Skip to content

Commit 2d53c14

Browse files
committed
don't copy values in asn1parse if not necessary
1 parent 3990851 commit 2d53c14

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

tlslite/utils/asn1parser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ def getChildCount(self):
8585
while True:
8686
if p.getRemainingLength() == 0:
8787
break
88-
p.get(1) # skip Type
88+
p.skip_bytes(1) # skip Type
8989
length = self._getASN1Length(p)
90-
p.getFixBytes(length) # skip value
90+
p.skip_bytes(length) # skip value
9191
count += 1
9292
return count
9393

@@ -104,9 +104,9 @@ def getChildBytes(self, which):
104104
p = Parser(self.value)
105105
for _ in range(which+1):
106106
markIndex = p.index
107-
p.get(1) #skip Type
107+
p.skip_bytes(1) # skip Type
108108
length = self._getASN1Length(p)
109-
p.getFixBytes(length)
109+
p.skip_bytes(length)
110110
return p.bytes[markIndex : p.index]
111111

112112
@staticmethod

tlslite/utils/codec.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,12 @@ def getFixBytes(self, lengthBytes):
324324
self.index += lengthBytes
325325
return bytes
326326

327+
def skip_bytes(self, length):
328+
"""Move the internal pointer ahead length bytes."""
329+
if self.index + length > len(self.bytes):
330+
raise DecodeError("Read past end of buffer")
331+
self.index += length
332+
327333
def getVarBytes(self, lengthLength):
328334
"""
329335
Read a variable length string with a fixed length.

0 commit comments

Comments
 (0)