Skip to content

Commit

Permalink
other micro optimisations
Browse files Browse the repository at this point in the history
  • Loading branch information
tomato42 committed Sep 23, 2020
1 parent 37d9e1a commit 71f7e24
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
7 changes: 4 additions & 3 deletions tlslite/utils/codec.py
Expand Up @@ -318,11 +318,12 @@ def getFixBytes(self, lengthBytes):
:rtype: bytearray
"""
if self.index + lengthBytes > len(self.bytes):
end = self.index + lengthBytes
if end > len(self.bytes):
raise DecodeError("Read past end of buffer")
bytes = self.bytes[self.index : self.index+lengthBytes]
ret = self.bytes[self.index : end]
self.index += lengthBytes
return bytes
return ret

def skip_bytes(self, length):
"""Move the internal pointer ahead length bytes."""
Expand Down
5 changes: 2 additions & 3 deletions tlslite/utils/rsakey.py
Expand Up @@ -534,11 +534,10 @@ def _addPKCS1Padding(self, bytes, blockType):
pad = bytearray(0)
while len(pad) < padLength:
padBytes = getRandomBytes(padLength * 2)
pad = [b for b in padBytes if b != 0]
pad = [b for b in padBytes if b]
pad = pad[:padLength]
else:
raise AssertionError()

padding = bytearray([0,blockType] + pad + [0])
paddedBytes = padding + bytes
return paddedBytes
return padding + bytes

0 comments on commit 71f7e24

Please sign in to comment.