OLD | NEW |
1 """Class for parsing ASN.1""" | 1 """Class for parsing ASN.1""" |
2 from compat import * | 2 from compat import * |
3 from codec import * | 3 from codec import * |
4 | 4 |
5 #Takes a byte array which has a DER TLV field at its head | 5 #Takes a byte array which has a DER TLV field at its head |
6 class ASN1Parser: | 6 class ASN1Parser: |
7 def __init__(self, bytes): | 7 def __init__(self, bytes): |
8 p = Parser(bytes) | 8 p = Parser(bytes) |
9 p.get(1) #skip Type | 9 p.get(1) #skip Type |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 return p.bytes[markIndex : p.index] | 28 return p.bytes[markIndex : p.index] |
29 | 29 |
30 #Decode the ASN.1 DER length field | 30 #Decode the ASN.1 DER length field |
31 def _getASN1Length(self, p): | 31 def _getASN1Length(self, p): |
32 firstLength = p.get(1) | 32 firstLength = p.get(1) |
33 if firstLength<=127: | 33 if firstLength<=127: |
34 return firstLength | 34 return firstLength |
35 else: | 35 else: |
36 lengthLength = firstLength & 0x7F | 36 lengthLength = firstLength & 0x7F |
37 return p.get(lengthLength) | 37 return p.get(lengthLength) |
OLD | NEW |