Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: third_party/tlslite/tlslite/utils/ASN1Parser.py

Issue 211173006: Perform tlslite 0.3.8 -> 0.4.6 renames ahead of time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Drop the -B Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 """Class for parsing ASN.1"""
2 from compat import *
3 from codec import *
4
5 #Takes a byte array which has a DER TLV field at its head
6 class ASN1Parser:
7 def __init__(self, bytes):
8 p = Parser(bytes)
9 p.get(1) #skip Type
10
11 #Get Length
12 self.length = self._getASN1Length(p)
13
14 #Get Value
15 self.value = p.getFixBytes(self.length)
16
17 #Assuming this is a sequence...
18 def getChild(self, which):
19 return ASN1Parser(self.getChildBytes(which))
20
21 def getChildBytes(self, which):
22 p = Parser(self.value)
23 for x in range(which+1):
24 markIndex = p.index
25 p.get(1) #skip Type
26 length = self._getASN1Length(p)
27 p.getFixBytes(length)
28 return p.bytes[markIndex : p.index]
29
30 #Decode the ASN.1 DER length field
31 def _getASN1Length(self, p):
32 firstLength = p.get(1)
33 if firstLength<=127:
34 return firstLength
35 else:
36 lengthLength = firstLength & 0x7F
37 return p.get(lengthLength)
OLDNEW
« no previous file with comments | « third_party/tlslite/tlslite/utils/AES.py ('k') | third_party/tlslite/tlslite/utils/Cryptlib_AES.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698