Skip to content

Commit 3990851

Browse files
committed
don't loop in Parser.get()
1 parent 5c536bf commit 3990851

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

tlslite/utils/codec.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import sys
99
import struct
1010
from struct import pack
11+
from .compat import bytes_to_int
1112

1213

1314
class DecodeError(SyntaxError):
@@ -305,14 +306,8 @@ def get(self, length):
305306
306307
:rtype: int
307308
"""
308-
if self.index + length > len(self.bytes):
309-
raise DecodeError("Read past end of buffer")
310-
x = 0
311-
for _ in range(length):
312-
x <<= 8
313-
x |= self.bytes[self.index]
314-
self.index += 1
315-
return x
309+
ret = self.getFixBytes(length)
310+
return bytes_to_int(ret, 'big')
316311

317312
def getFixBytes(self, lengthBytes):
318313
"""

0 commit comments

Comments
 (0)