mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 15:38:11 +00:00
trezorlib/protobuf.py: return BytesType from wire as bytes, not bytearray.
This makes more sense, because bytes are immutable and callers have no business mutating structures from the wire anyway. Incidentally this should fix issue #236, where rlp library would treat bytes and bytearrays differently and produce invalid structures in our usecase. Also very minor nitpicks and code cleanup for neater typing.
This commit is contained in:
parent
f87d931ce7
commit
afb3e04c24
@ -244,12 +244,13 @@ def load_message(reader, msg_type):
|
||||
elif ftype is BoolType:
|
||||
fvalue = bool(ivalue)
|
||||
elif ftype is BytesType:
|
||||
fvalue = bytearray(ivalue)
|
||||
reader.readinto(fvalue)
|
||||
buf = bytearray(ivalue)
|
||||
reader.readinto(buf)
|
||||
fvalue = bytes(buf)
|
||||
elif ftype is UnicodeType:
|
||||
fvalue = bytearray(ivalue)
|
||||
reader.readinto(fvalue)
|
||||
fvalue = fvalue.decode()
|
||||
buf = bytearray(ivalue)
|
||||
reader.readinto(buf)
|
||||
fvalue = buf.decode()
|
||||
elif issubclass(ftype, MessageType):
|
||||
fvalue = load_message(LimitedReader(reader, ivalue), ftype)
|
||||
else:
|
||||
@ -270,10 +271,7 @@ def dump_message(writer, msg):
|
||||
fields = mtype.FIELDS
|
||||
|
||||
for ftag in fields:
|
||||
field = fields[ftag]
|
||||
fname = field[0]
|
||||
ftype = field[1]
|
||||
fflags = field[2]
|
||||
fname, ftype, fflags = fields[ftag]
|
||||
|
||||
fvalue = getattr(msg, fname, None)
|
||||
if fvalue is None:
|
||||
|
Loading…
Reference in New Issue
Block a user