1 """Class for parsing ASN.1"""
5 #Takes a byte array which has a DER TLV field at its head
7 def __init__(self, bytes):
12 self.length = self._getASN1Length(p)
15 self.value = p.getFixBytes(self.length)
17 #Assuming this is a sequence...
18 def getChild(self, which):
19 return ASN1Parser(self.getChildBytes(which))
21 def getChildBytes(self, which):
22 p = Parser(self.value)
23 for x in range(which+1):
26 length = self._getASN1Length(p)
28 return p.bytes[markIndex : p.index]
30 #Decode the ASN.1 DER length field
31 def _getASN1Length(self, p):
32 firstLength = p.get(1)
36 lengthLength = firstLength & 0x7F
37 return p.get(lengthLength)