Skip to content

Commit 92c98ad

Browse files
committed
other micro optimisations
1 parent 6a918c4 commit 92c98ad

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

tlslite/utils/codec.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,12 @@ def getFixBytes(self, lengthBytes):
318318
319319
:rtype: bytearray
320320
"""
321-
if self.index + lengthBytes > len(self.bytes):
321+
end = self.index + lengthBytes
322+
if end > len(self.bytes):
322323
raise DecodeError("Read past end of buffer")
323-
bytes = self.bytes[self.index : self.index+lengthBytes]
324+
ret = self.bytes[self.index : end]
324325
self.index += lengthBytes
325-
return bytes
326+
return ret
326327

327328
def skip_bytes(self, length):
328329
"""Move the internal pointer ahead length bytes."""

tlslite/utils/rsakey.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,11 +534,10 @@ def _addPKCS1Padding(self, bytes, blockType):
534534
pad = bytearray(0)
535535
while len(pad) < padLength:
536536
padBytes = getRandomBytes(padLength * 2)
537-
pad = [b for b in padBytes if b != 0]
537+
pad = [b for b in padBytes if b]
538538
pad = pad[:padLength]
539539
else:
540540
raise AssertionError()
541541

542542
padding = bytearray([0,blockType] + pad + [0])
543-
paddedBytes = padding + bytes
544-
return paddedBytes
543+
return padding + bytes

0 commit comments

Comments
 (0)