Skip to content

Commit 25fbaaf

Browse files
committed
Encode major version as a uint8 in detached timestamps
Backwards compatible because we only use major version 1. There's no way we'd ever need more than 256 major versions. So no reason to use a more complex encoding.
1 parent 678d208 commit 25fbaaf

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

opentimestamps/core/serialize.py

+6
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ def write_varuint(self, value):
155155
break
156156
value >>= 7
157157

158+
def write_uint8(self, value):
159+
self.fd.write(bytes([value]))
160+
158161
def write_bytes(self, value):
159162
self.fd.write(value)
160163

@@ -199,6 +202,9 @@ def read_varuint(self):
199202

200203
return value
201204

205+
def read_uint8(self):
206+
return self.fd_read(1)[0]
207+
202208
def read_bytes(self, expected_length=None):
203209
if expected_length is None:
204210
expected_length = self.read_varuint(None)

opentimestamps/core/timestamp.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def from_fd(cls, file_hash_op, fd):
316316
def serialize(self, ctx):
317317
ctx.write_bytes(self.HEADER_MAGIC)
318318

319-
ctx.write_varuint(self.MAJOR_VERSION)
319+
ctx.write_uint8(self.MAJOR_VERSION)
320320

321321
self.file_hash_op.serialize(ctx)
322322
assert self.file_hash_op.DIGEST_LENGTH == len(self.timestamp.msg)
@@ -328,7 +328,7 @@ def serialize(self, ctx):
328328
def deserialize(cls, ctx):
329329
ctx.assert_magic(cls.HEADER_MAGIC)
330330

331-
major = ctx.read_varuint() # FIXME: max-int limit
331+
major = ctx.read_uint8()
332332
if major != cls.MAJOR_VERSION:
333333
raise opentimestamps.core.serialize.UnsupportedMajorVersion("Version %d detached timestamp files are not supported" % major)
334334

0 commit comments

Comments
 (0)