| OLD | NEW |
| 1 # Author: Trevor Perrin |
| 2 # Patch from Google adding getChildBytes() |
| 3 # |
| 4 # See the LICENSE file for legal information regarding use of this file. |
| 5 |
| 1 """Class for parsing ASN.1""" | 6 """Class for parsing ASN.1""" |
| 2 from compat import * | 7 from .compat import * |
| 3 from codec import * | 8 from .codec import * |
| 4 | 9 |
| 5 #Takes a byte array which has a DER TLV field at its head | 10 #Takes a byte array which has a DER TLV field at its head |
| 6 class ASN1Parser: | 11 class ASN1Parser(object): |
| 7 def __init__(self, bytes): | 12 def __init__(self, bytes): |
| 8 p = Parser(bytes) | 13 p = Parser(bytes) |
| 9 p.get(1) #skip Type | 14 p.get(1) #skip Type |
| 10 | 15 |
| 11 #Get Length | 16 #Get Length |
| 12 self.length = self._getASN1Length(p) | 17 self.length = self._getASN1Length(p) |
| 13 | 18 |
| 14 #Get Value | 19 #Get Value |
| 15 self.value = p.getFixBytes(self.length) | 20 self.value = p.getFixBytes(self.length) |
| 16 | 21 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 28 return p.bytes[markIndex : p.index] | 33 return p.bytes[markIndex : p.index] |
| 29 | 34 |
| 30 #Decode the ASN.1 DER length field | 35 #Decode the ASN.1 DER length field |
| 31 def _getASN1Length(self, p): | 36 def _getASN1Length(self, p): |
| 32 firstLength = p.get(1) | 37 firstLength = p.get(1) |
| 33 if firstLength<=127: | 38 if firstLength<=127: |
| 34 return firstLength | 39 return firstLength |
| 35 else: | 40 else: |
| 36 lengthLength = firstLength & 0x7F | 41 lengthLength = firstLength & 0x7F |
| 37 return p.get(lengthLength) | 42 return p.get(lengthLength) |
| OLD | NEW |