From 7b844f0379d3adadb868edc9468b7cf8fb5ce2d4 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Tue, 30 Jan 2018 15:04:24 +0100 Subject: [PATCH] add Sint64 to protobuf --- tools/pb2py | 4 ++++ trezorlib/protobuf.py | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/tools/pb2py b/tools/pb2py index ef61d7e945..50d7cebc7c 100755 --- a/tools/pb2py +++ b/tools/pb2py @@ -39,6 +39,10 @@ def process_type(t, cls, msg_id, indexfile, is_upy): # TYPE_SINT32 = 17 type = 'p.Sint32Type' + elif v.type in (18,): + # TYPE_SINT64 = 18 + type = 'p.Sint64Type' + elif v.type == 9: # TYPE_STRING = 9 type = 'p.UnicodeType' diff --git a/trezorlib/protobuf.py b/trezorlib/protobuf.py index 096fb664d7..08699808af 100644 --- a/trezorlib/protobuf.py +++ b/trezorlib/protobuf.py @@ -76,6 +76,10 @@ class Sint32Type: WIRE_TYPE = 0 +class Sint64Type: + WIRE_TYPE = 0 + + class BoolType: WIRE_TYPE = 0 @@ -235,6 +239,8 @@ def load_message(reader, msg_type): fvalue = ivalue elif ftype is Sint32Type: fvalue = (ivalue >> 1) ^ ((ivalue << 31) & 0xffffffff) + elif ftype is Sint64Type: + fvalue = (ivalue >> 1) ^ ((ivalue << 63) & 0xffffffffffffffff) elif ftype is BoolType: fvalue = bool(ivalue) elif ftype is BytesType: @@ -288,6 +294,9 @@ def dump_message(writer, msg): elif ftype is Sint32Type: dump_uvarint(writer, ((svalue << 1) & 0xffffffff) ^ (svalue >> 31)) + elif ftype is Sint64Type: + dump_uvarint(writer, ((svalue << 1) & 0xffffffffffffffff) ^ (svalue >> 63)) + elif ftype is BoolType: dump_uvarint(writer, int(svalue))