mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-05 21:10:57 +00:00
test: try fix pin callback
This commit is contained in:
parent
2b51be1eab
commit
76daf9da60
@ -32,8 +32,13 @@ from pathlib import Path
|
||||
from mnemonic import Mnemonic
|
||||
|
||||
from . import btc, mapping, messages, models, protobuf
|
||||
from .client import MAX_PASSPHRASE_LENGTH, PASSPHRASE_ON_DEVICE, TrezorClient
|
||||
from .exceptions import Cancelled, TrezorFailure
|
||||
from .client import (
|
||||
MAX_PASSPHRASE_LENGTH,
|
||||
MAX_PIN_LENGTH,
|
||||
PASSPHRASE_ON_DEVICE,
|
||||
TrezorClient,
|
||||
)
|
||||
from .exceptions import Cancelled, PinException, TrezorFailure
|
||||
from .log import DUMP_BYTES
|
||||
from .messages import Capability, DebugWaitType
|
||||
from .tools import expect, parse_path
|
||||
@ -1354,6 +1359,33 @@ class TrezorClientDebugLink(TrezorClient):
|
||||
|
||||
return _callback_button
|
||||
|
||||
@property
|
||||
def pin_callback(self):
|
||||
|
||||
def _callback_pin(session: Session, msg: messages.PinMatrixRequest) -> t.Any:
|
||||
try:
|
||||
pin = self.ui.get_pin(msg.type)
|
||||
except Cancelled:
|
||||
session.call_raw(messages.Cancel())
|
||||
raise
|
||||
|
||||
if any(d not in "123456789" for d in pin) or not (
|
||||
1 <= len(pin) <= MAX_PIN_LENGTH
|
||||
):
|
||||
session.call_raw(messages.Cancel())
|
||||
raise ValueError("Invalid PIN provided")
|
||||
resp = session.call_raw(messages.PinMatrixAck(pin=pin))
|
||||
if isinstance(resp, messages.Failure) and resp.code in (
|
||||
messages.FailureType.PinInvalid,
|
||||
messages.FailureType.PinCancelled,
|
||||
messages.FailureType.PinExpected,
|
||||
):
|
||||
raise PinException(resp.code, resp.message)
|
||||
else:
|
||||
return resp
|
||||
|
||||
return _callback_pin
|
||||
|
||||
@property
|
||||
def passphrase_callback(self):
|
||||
def _callback_passphrase(
|
||||
|
Loading…
Reference in New Issue
Block a user