File tree Expand file tree Collapse file tree 3 files changed +21
-4
lines changed
Expand file tree Collapse file tree 3 files changed +21
-4
lines changed Original file line number Diff line number Diff line change 2525
2626from io import BytesIO
2727from io import IOBase
28- from klvdata .common import bytes_to_int
28+ from klvdata .common import bytes_to_int , int_to_bytes
2929
3030
3131class KLVParser (object ):
@@ -42,7 +42,24 @@ def __iter__(self):
4242 return self
4343
4444 def __next__ (self ):
45- key = self .__read (self .key_length )
45+ # A length of None means the key is a variable length BER OID
46+ if self .key_length is None :
47+ oid = 0
48+ byte = bytes_to_int (self .__read (1 ))
49+ # We limit ourselves to four (4) bytes to prevent infinite loops.
50+ for _ in range (4 ):
51+ isFinal = byte < 128
52+ oid = (oid << 7 ) + (byte & 0x7F )
53+ if (isFinal ):
54+ break
55+ byte = bytes_to_int (self .__read (1 ))
56+ else :
57+ # We've haven't finished reading the key, so any subsequent reads will be invalid.
58+ raise StopIteration
59+
60+ key = int_to_bytes (oid )
61+ else :
62+ key = self .__read (self .key_length )
4663
4764 byte_length = bytes_to_int (self .__read (1 ))
4865
Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ class SecurityLocalMetadataSet(SetParser):
8383 Must be a subclass of Element or duck type Element.
8484 """
8585 key , name = b'\x30 ' , "Security Local Metadata Set"
86- key_length = 1
86+ key_length = None # A length of None means the key is a variable length BER OID
8787 parsers = {}
8888
8989 _unknown_element = UnknownElement
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ class UASLocalMetadataSet(SetParser):
4444 """
4545 key = hexstr_to_bytes ('06 0E 2B 34 - 02 0B 01 01 – 0E 01 03 01 - 01 00 00 00' )
4646 name = 'UAS Datalink Local Set'
47- key_length = 1
47+ key_length = None # A length of None means the key is a variable length BER OID
4848 parsers = {}
4949
5050 _unknown_element = UnknownElement
You can’t perform that action at this time.
0 commit comments