mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-14 03:30:02 +00:00
chore(core): add exceptions to getters for QR code string, code code string and handshake hash, remove unnecessary booleans from PairingDisplayData
[no changelog]
This commit is contained in:
parent
fa8ff7351a
commit
5727c7e319
@ -167,7 +167,6 @@ async def _handle_code_entry_is_included(ctx: PairingContext) -> None:
|
||||
ctx.display_data.code_code_entry = (
|
||||
int.from_bytes(code_code_entry_hash, "big") % 1000000
|
||||
)
|
||||
ctx.display_data.display_code_entry = True
|
||||
|
||||
|
||||
@check_state_and_log(ChannelState.TP1, ChannelState.TP2)
|
||||
@ -176,7 +175,6 @@ def _handle_qr_code_is_included(ctx: PairingContext) -> None:
|
||||
sha_ctx.update(ctx.secret)
|
||||
sha_ctx.update(bytes("PairingMethod_QrCode", "utf-8"))
|
||||
ctx.display_data.code_qr_code = sha_ctx.digest()[:16]
|
||||
ctx.display_data.display_qr_code = True
|
||||
|
||||
|
||||
@check_state_and_log(ChannelState.TP1, ChannelState.TP2)
|
||||
@ -185,7 +183,6 @@ def _handle_nfc_unidirectional_is_included(ctx: PairingContext) -> None:
|
||||
sha_ctx.update(ctx.secret)
|
||||
sha_ctx.update(bytes("PairingMethod_NfcUnidirectional", "utf-8"))
|
||||
ctx.display_data.code_nfc_unidirectional = sha_ctx.digest()[:16]
|
||||
ctx.display_data.display_nfc_unidirectional = True
|
||||
|
||||
|
||||
@check_state_and_log(ChannelState.TP3)
|
||||
|
@ -77,7 +77,9 @@ class Channel:
|
||||
return state
|
||||
|
||||
def get_handshake_hash(self) -> bytes:
|
||||
return self.channel_cache.get(CHANNEL_HANDSHAKE_HASH) or b""
|
||||
h = self.channel_cache.get(CHANNEL_HANDSHAKE_HASH)
|
||||
assert h is not None
|
||||
return h
|
||||
|
||||
def set_channel_state(self, state: ChannelState) -> None:
|
||||
self.channel_cache.state = bytearray(state.to_bytes(1, "big"))
|
||||
|
@ -23,10 +23,8 @@ if __debug__:
|
||||
|
||||
|
||||
class PairingDisplayData:
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.display_code_entry: bool = False
|
||||
self.display_qr_code: bool = False
|
||||
self.display_nfc_unidirectional: bool = False
|
||||
self.code_code_entry: int | None = None
|
||||
self.code_qr_code: bytes | None = None
|
||||
self.code_nfc_unidirectional: bytes | None = None
|
||||
@ -45,19 +43,19 @@ class PairingDisplayData:
|
||||
)
|
||||
|
||||
def _get_code_code_entry_str(self) -> str:
|
||||
if self.display_code_entry and self.code_code_entry is not None:
|
||||
if self.code_code_entry is not None:
|
||||
code_str = str(self.code_code_entry)
|
||||
print("code_code_entry:", code_str)
|
||||
|
||||
return code_str[:3] + " " + code_str[3:]
|
||||
return "NOT ALLOWED"
|
||||
raise Exception("Code entry string is not available")
|
||||
|
||||
def _get_code_qr_code_str(self) -> str:
|
||||
if self.display_qr_code and self.code_qr_code is not None:
|
||||
if self.code_qr_code is not None:
|
||||
code_str = (hexlify(self.code_qr_code)).decode("utf-8")
|
||||
print("code_qr_code_hexlified:", code_str)
|
||||
return code_str
|
||||
return "QR CODE IS NOT SUPPOSED TO BE DISPLAYED!!!!"
|
||||
raise Exception("QR code string is not available")
|
||||
|
||||
|
||||
class PairingContext(Context):
|
||||
|
Loading…
Reference in New Issue
Block a user