def test_to_string(self): for known_string, known_encoding in self.examples: obj = ObjectIdentifier(known_encoding) string = str(obj) print(known_string, binascii.hexlify(known_encoding), string) self.assertEqual(known_string, string) with self.assertRaises(AssertionError): ObjectIdentifier.from_string('3.0') with self.assertRaises(AssertionError): ObjectIdentifier.from_string('1.41')
def from_oid(cls, oid=None): if oid is None: oid = snmp.mib.system if isinstance(oid, str): oid = ObjectIdentifier.from_string(oid) if isinstance(oid, ObjectIdentifier): oid = oid.get_object() else: assert isinstance(oid, Object) assert isinstance(oid.value, ObjectIdentifier) variable_bindings = Sequence.from_list([Sequence.from_list([oid, Null().get_object()])]) return cls(variable_bindings=variable_bindings)
def test_from_string(self): for known_string, known_encoding in self.examples: print(known_string, binascii.hexlify(known_encoding)) obj = ObjectIdentifier.from_string(known_string) encoding = bytes(obj) self.assertEqual(known_encoding, encoding)
from ber.object import ObjectIdentifier # 1 - ISO assigned OIDs # 1.3 - ISO Identified Organization # 1.3.6 - US Department of Defense # 1.3.6.1 - OID assignments from 1.3.6.1 - Internet # 1.3.6.1.2 - IETF Management # 1.3.6.1.2.1 - SNMP MIB-2 system = ObjectIdentifier.from_string('1.3.6.1.2.1')