mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-10 23:40:58 +00:00
core/passphrase: merge 'get from user' functions
This commit is contained in:
parent
7d7ffe3b67
commit
fd0dc8ed66
@ -29,20 +29,17 @@ async def get(ctx: wire.Context) -> str:
|
||||
|
||||
|
||||
async def _request_from_user(ctx: wire.Context) -> str:
|
||||
passphrase = await _get_from_user(ctx)
|
||||
if storage.device.get_passphrase_always_on_device():
|
||||
passphrase = await _request_on_device(ctx)
|
||||
else:
|
||||
passphrase = await _request_on_host(ctx)
|
||||
if len(passphrase) > _MAX_PASSPHRASE_LEN:
|
||||
raise wire.DataError("Maximum passphrase length is %d" % _MAX_PASSPHRASE_LEN)
|
||||
|
||||
return passphrase
|
||||
|
||||
|
||||
async def _get_from_user(ctx: wire.Context) -> str:
|
||||
if storage.device.get_passphrase_always_on_device():
|
||||
return await _request_from_user_on_device(ctx)
|
||||
return await _request_from_host(ctx)
|
||||
|
||||
|
||||
async def _request_from_host(ctx: wire.Context) -> str:
|
||||
async def _request_on_host(ctx: wire.Context) -> str:
|
||||
_entry_dialog()
|
||||
|
||||
request = PassphraseRequest()
|
||||
@ -50,7 +47,7 @@ async def _request_from_host(ctx: wire.Context) -> str:
|
||||
if ack.on_device:
|
||||
if ack.passphrase is not None:
|
||||
raise wire.DataError("Passphrase provided when it should not be")
|
||||
return await _request_from_user_on_device(ctx)
|
||||
return await _request_on_device(ctx)
|
||||
|
||||
if ack.passphrase is None:
|
||||
raise wire.DataError(
|
||||
@ -59,7 +56,7 @@ async def _request_from_host(ctx: wire.Context) -> str:
|
||||
return ack.passphrase
|
||||
|
||||
|
||||
async def _request_from_user_on_device(ctx: wire.Context) -> str:
|
||||
async def _request_on_device(ctx: wire.Context) -> str:
|
||||
await ctx.call(ButtonRequest(code=ButtonRequestType.PassphraseEntry), ButtonAck)
|
||||
|
||||
keyboard = PassphraseKeyboard("Enter passphrase", _MAX_PASSPHRASE_LEN)
|
||||
|
Loading…
Reference in New Issue
Block a user