Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Unified Diff: third_party/tlslite/tlslite/utils/codec.py

Issue 210323002: Update tlslite to 0.4.6. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Executable bit and --similarity=80 Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/tlslite/tlslite/utils/cipherfactory.py ('k') | third_party/tlslite/tlslite/utils/compat.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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()
« no previous file with comments | « third_party/tlslite/tlslite/utils/cipherfactory.py ('k') | third_party/tlslite/tlslite/utils/compat.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698