def test_search_range(self): oid_start = ObjectIdentifier(4, 2, 0, 0, (1, 1, 1, 0)) oid_end = ObjectIdentifier(0, 0, 0, 0, ()) sr1 = SearchRange(oid_start, oid_end) sr2 = SearchRange.from_bytes(oid_start.to_bytes('!') + oid_end.to_bytes('!'), '!') self.assertEqual(sr1, sr2) self.assertEqual(sr1.size, 24) print(sr1) oid_start = ObjectIdentifier(4, 2, 0, 0, (1, 1, 1, 0)) oid_end = ObjectIdentifier(4, 2, 0, 0, (2, 2, 2, 0)) sr1 = SearchRange(oid_start, oid_end) sr2 = SearchRange.from_bytes(oid_start.to_bytes('!') + oid_end.to_bytes('!'), '!') self.assertEqual(sr1, sr2) self.assertEqual(sr1.size, 40) print(sr1) self.assertEqual(SearchRange.from_bytes(sr1.to_bytes('!'), '!'), sr1)
def test_oid(self): oid1 = ObjectIdentifier(4, 2, 0, 0, (1, 1, 1, 0)) self.assertEqual(str(oid1), '.1.3.6.1.2.1.1.1.0') self.assertEqual(oid1.size, 20) print(oid1) oid2 = ObjectIdentifier.from_bytes(oid1.to_bytes('!'), '!') # round-trip self.assertEqual(str(oid2), '.1.3.6.1.2.1.1.1.0') self.assertEqual(oid2.size, 20) oid_literal = ObjectIdentifier(4, 0, 0, 0, (1, 2, 3, 4)) self.assertEqual(str(oid_literal), '.1.2.3.4') print(oid_literal) oid_small = ObjectIdentifier(0, 0, 0, 0, ()) self.assertEqual(oid_small.size, 4) dell_oid = ObjectIdentifier(n_subid=7, prefix_=4, include=0, reserved=0, subids=(1, 6027, 3, 10, 1, 2, 9)) check = ObjectIdentifier.from_bytes(dell_oid.to_bytes('!'), '!') self.assertEqual(check, dell_oid)