1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 04:18:10 +00:00

chore(core): Add offset parameter to cbor.decode().

This commit is contained in:
Andrew Kozlik 2021-03-22 21:14:25 +01:00 committed by Andrew Kozlik
parent 7811204ed5
commit 97ca1e3341
2 changed files with 5 additions and 4 deletions

View File

@ -302,8 +302,9 @@ def encode_chunked(value: Value, max_chunk_size: int) -> Iterator[bytes]:
yield chunk_buffer
def decode(cbor: bytes) -> Value:
def decode(cbor: bytes, offset: int = 0) -> Value:
r = utils.BufferReader(cbor)
r.seek(offset)
res = _cbor_decode(r)
if r.remaining_count():
raise ValueError

View File

@ -1479,7 +1479,7 @@ def cbor_make_credential_process(req: Cmd, dialog_mgr: DialogManager) -> State |
return cbor_error(req.cid, _ERR_OTHER)
try:
param = cbor.decode(req.data[1:])
param = cbor.decode(req.data, offset=1)
rp = param[_MAKECRED_CMD_RP]
rp_id = rp["id"]
rp_id_hash = hashlib.sha256(rp_id).digest()
@ -1657,7 +1657,7 @@ def cbor_get_assertion_process(req: Cmd, dialog_mgr: DialogManager) -> State | C
return cbor_error(req.cid, _ERR_OTHER)
try:
param = cbor.decode(req.data[1:])
param = cbor.decode(req.data, offset=1)
rp_id = param[_GETASSERT_CMD_RP_ID]
rp_id_hash = hashlib.sha256(rp_id).digest()
@ -1879,7 +1879,7 @@ def cbor_get_info(req: Cmd) -> Cmd:
def cbor_client_pin(req: Cmd) -> Cmd:
try:
param = cbor.decode(req.data[1:])
param = cbor.decode(req.data, offset=1)
pin_protocol = param[_CLIENTPIN_CMD_PIN_PROTOCOL]
subcommand = param[_CLIENTPIN_CMD_SUBCOMMAND]
except Exception: