mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-08 06:20:56 +00:00
test: try fix pin callback
This commit is contained in:
parent
f671802da7
commit
9772236f27
@ -32,8 +32,13 @@ from pathlib import Path
|
|||||||
from mnemonic import Mnemonic
|
from mnemonic import Mnemonic
|
||||||
|
|
||||||
from . import btc, mapping, messages, models, protobuf
|
from . import btc, mapping, messages, models, protobuf
|
||||||
from .client import MAX_PASSPHRASE_LENGTH, PASSPHRASE_ON_DEVICE, TrezorClient
|
from .client import (
|
||||||
from .exceptions import Cancelled, TrezorFailure
|
MAX_PASSPHRASE_LENGTH,
|
||||||
|
MAX_PIN_LENGTH,
|
||||||
|
PASSPHRASE_ON_DEVICE,
|
||||||
|
TrezorClient,
|
||||||
|
)
|
||||||
|
from .exceptions import Cancelled, PinException, TrezorFailure
|
||||||
from .log import DUMP_BYTES
|
from .log import DUMP_BYTES
|
||||||
from .messages import Capability, DebugWaitType
|
from .messages import Capability, DebugWaitType
|
||||||
from .tools import expect, parse_path
|
from .tools import expect, parse_path
|
||||||
@ -1354,6 +1359,33 @@ class TrezorClientDebugLink(TrezorClient):
|
|||||||
|
|
||||||
return _callback_button
|
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
|
@property
|
||||||
def passphrase_callback(self):
|
def passphrase_callback(self):
|
||||||
def _callback_passphrase(
|
def _callback_passphrase(
|
||||||
|
Loading…
Reference in New Issue
Block a user