Index: third_party/tlslite/tlslite/utils/codec.py |
diff --git a/third_party/tlslite/tlslite/utils/codec.py b/third_party/tlslite/tlslite/utils/codec.py |
index 13022a0b93261992801629c4b828ee19feb5d3c1..f1e21c923dfa28ca3be8ecbb0f039f19dd2b766e 100644 |
--- a/third_party/tlslite/tlslite/utils/codec.py |
+++ b/third_party/tlslite/tlslite/utils/codec.py |
@@ -1,39 +1,32 @@ |
+# Author: Trevor Perrin |
+# See the LICENSE file for legal information regarding use of this file. |
+ |
"""Classes for reading/writing binary data (such as TLS records).""" |
-from compat import * |
+from .compat import * |
-class Writer: |
- def __init__(self, length=0): |
- #If length is zero, then this is just a "trial run" to determine length |
- self.index = 0 |
- self.bytes = createByteArrayZeros(length) |
+class Writer(object): |
+ def __init__(self): |
+ self.bytes = bytearray(0) |
def add(self, x, length): |
- if self.bytes: |
- newIndex = self.index+length-1 |
- while newIndex >= self.index: |
- self.bytes[newIndex] = x & 0xFF |
- x >>= 8 |
- newIndex -= 1 |
- self.index += length |
+ self.bytes += bytearray(length) |
+ newIndex = len(self.bytes) - 1 |
+ for count in range(length): |
+ self.bytes[newIndex] = x & 0xFF |
+ x >>= 8 |
+ newIndex -= 1 |
def addFixSeq(self, seq, length): |
- if self.bytes: |
- for e in seq: |
- self.add(e, length) |
- else: |
- self.index += len(seq)*length |
+ for e in seq: |
+ self.add(e, length) |
def addVarSeq(self, seq, length, lengthLength): |
- if self.bytes: |
- self.add(len(seq)*length, lengthLength) |
- for e in seq: |
- self.add(e, length) |
- else: |
- self.index += lengthLength + (len(seq)*length) |
- |
+ self.add(len(seq)*length, lengthLength) |
+ for e in seq: |
+ self.add(e, length) |
-class Parser: |
+class Parser(object): |
def __init__(self, bytes): |
self.bytes = bytes |
self.index = 0 |
@@ -67,7 +60,7 @@ class Parser: |
lengthList = self.get(lengthLength) |
if lengthList % length != 0: |
raise SyntaxError() |
- lengthList = int(lengthList/length) |
+ lengthList = lengthList // length |
l = [0] * lengthList |
for x in range(lengthList): |
l[x] = self.get(length) |
@@ -91,4 +84,4 @@ class Parser: |
elif (self.index - self.indexCheck) == self.lengthCheck: |
return True |
else: |
- raise SyntaxError() |
+ raise SyntaxError() |