1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-20 13:38:11 +00:00

WIP - returning None instead of empty bytes

This commit is contained in:
grdddj 2022-03-16 13:34:37 +01:00
parent c9f247b75e
commit cc02e8892c
2 changed files with 31 additions and 26 deletions

View File

@ -12,7 +12,6 @@ use core::convert::{TryFrom, TryInto};
// MISSING FUNCTIONALITY: // MISSING FUNCTIONALITY:
// - returning strings into python // - returning strings into python
// - return either bytes or None
const FLAG_PUBLIC: u8 = 0x80; const FLAG_PUBLIC: u8 = 0x80;
@ -143,7 +142,10 @@ extern "C" fn storagedevice_get_label() -> Obj {
let block = || { let block = || {
let key = _get_appkey(_LABEL, true); let key = _get_appkey(_LABEL, true);
let result = &storagedevice_storage_get(key) as &[u8]; let result = &storagedevice_storage_get(key) as &[u8];
// TODO: return None in case it is empty if result.is_empty() {
// TODO: it did not work with None::<&[u8]>, but it should not matter
return Ok(None::<u16>.into());
}
// TODO: how to convert into a string? // TODO: how to convert into a string?
// let label = StrBuffer::try_from(*result)?; // let label = StrBuffer::try_from(*result)?;
result.try_into() result.try_into()
@ -269,6 +271,9 @@ extern "C" fn storagedevice_get_homescreen() -> Obj {
let block = || { let block = || {
let key = _get_appkey(_HOMESCREEN, false); let key = _get_appkey(_HOMESCREEN, false);
let result = &storagedevice_storage_get_homescreen(key) as &[u8]; let result = &storagedevice_storage_get_homescreen(key) as &[u8];
if result.is_empty() {
return Ok(None::<u16>.into());
}
result.try_into() result.try_into()
}; };
unsafe { util::try_or_raise(block) } unsafe { util::try_or_raise(block) }

View File

@ -1,67 +1,67 @@
from typing import * from typing import *
# rust/src/storagedevice/storagedevice.rs # rust/src/storagedevice/storage_device.rs
def is_version_stored() -> bool: def is_version_stored() -> bool:
"""Whether version is in storage.""" """Whether version is in storage."""
# rust/src/storagedevice/storagedevice.rs # rust/src/storagedevice/storage_device.rs
def is_initialized() -> bool: def is_initialized() -> bool:
"""Whether device is initialized.""" """Whether device is initialized."""
# rust/src/storagedevice/storagedevice.rs # rust/src/storagedevice/storage_device.rs
def get_version() -> bytes: def get_version() -> bytes:
"""Get version.""" """Get version."""
# rust/src/storagedevice/storagedevice.rs # rust/src/storagedevice/storage_device.rs
def set_version(version: bytes) -> bool: def set_version(version: bytes) -> bool:
"""Set version.""" """Set version."""
# rust/src/storagedevice/storagedevice.rs # rust/src/storagedevice/storage_device.rs
def get_rotation() -> int: def get_rotation() -> int:
"""Get rotation.""" """Get rotation."""
# rust/src/storagedevice/storagedevice.rs # rust/src/storagedevice/storage_device.rs
def set_rotation(rotation: int) -> bool: def set_rotation(rotation: int) -> bool:
"""Set rotation.""" """Set rotation."""
# rust/src/storagedevice/storagedevice.rs # rust/src/storagedevice/storage_device.rs
def get_label() -> str | None: def get_label() -> str | None:
"""Get label.""" """Get label."""
# rust/src/storagedevice/storagedevice.rs # rust/src/storagedevice/storage_device.rs
def set_label(label: str) -> bool: def set_label(label: str) -> bool:
"""Set label.""" """Set label."""
# rust/src/storagedevice/storagedevice.rs # rust/src/storagedevice/storage_device.rs
def get_mnemonic_secret() -> bytes: def get_mnemonic_secret() -> bytes:
"""Get mnemonic secret.""" """Get mnemonic secret."""
# rust/src/storagedevice/storagedevice.rs # rust/src/storagedevice/storage_device.rs
def is_passphrase_enabled() -> bool: def is_passphrase_enabled() -> bool:
"""Whether passphrase is enabled.""" """Whether passphrase is enabled."""
# rust/src/storagedevice/storagedevice.rs # rust/src/storagedevice/storage_device.rs
def set_passphrase_enabled(enable: bool) -> bool: def set_passphrase_enabled(enable: bool) -> bool:
"""Set whether passphrase is enabled.""" """Set whether passphrase is enabled."""
# rust/src/storagedevice/storagedevice.rs # rust/src/storagedevice/storage_device.rs
def get_passphrase_always_on_device() -> bool: def get_passphrase_always_on_device() -> bool:
"""Whether passphrase is on device.""" """Whether passphrase is on device."""
# rust/src/storagedevice/storagedevice.rs # rust/src/storagedevice/storage_device.rs
def set_passphrase_always_on_device(enable: bool) -> bool: def set_passphrase_always_on_device(enable: bool) -> bool:
"""Set whether passphrase is on device. """Set whether passphrase is on device.
This is backwards compatible with _PASSPHRASE_SOURCE: This is backwards compatible with _PASSPHRASE_SOURCE:
@ -71,47 +71,47 @@ def set_passphrase_always_on_device(enable: bool) -> bool:
""" """
# rust/src/storagedevice/storagedevice.rs # rust/src/storagedevice/storage_device.rs
def unfinished_backup() -> bool: def unfinished_backup() -> bool:
"""Whether backup is still in progress.""" """Whether backup is still in progress."""
# rust/src/storagedevice/storagedevice.rs # rust/src/storagedevice/storage_device.rs
def set_unfinished_backup(state: bool) -> bool: def set_unfinished_backup(state: bool) -> bool:
"""Set backup state.""" """Set backup state."""
# rust/src/storagedevice/storagedevice.rs # rust/src/storagedevice/storage_device.rs
def needs_backup() -> bool: def needs_backup() -> bool:
"""Whether backup is needed.""" """Whether backup is needed."""
# rust/src/storagedevice/storagedevice.rs # rust/src/storagedevice/storage_device.rs
def set_backed_up() -> bool: def set_backed_up() -> bool:
"""Signal that backup is finished.""" """Signal that backup is finished."""
# rust/src/storagedevice/storagedevice.rs # rust/src/storagedevice/storage_device.rs
def no_backup() -> bool: def no_backup() -> bool:
"""Whether there is no backup.""" """Whether there is no backup."""
# rust/src/storagedevice/storagedevice.rs # rust/src/storagedevice/storage_device.rs
def get_homescreen() -> bytes | None: def get_homescreen() -> bytes | None:
"""Get homescreen.""" """Get homescreen."""
# rust/src/storagedevice/storagedevice.rs # rust/src/storagedevice/storage_device.rs
def set_homescreen(homescreen: bytes) -> bool: def set_homescreen(homescreen: bytes) -> bool:
"""Set homescreen.""" """Set homescreen."""
# rust/src/storagedevice/storagedevice.rs # rust/src/storagedevice/storage_device.rs
def get_slip39_identifier() -> int | None: def get_slip39_identifier() -> int | None:
"""The device's actual SLIP-39 identifier used in passphrase derivation.""" """The device's actual SLIP-39 identifier used in passphrase derivation."""
# rust/src/storagedevice/storagedevice.rs # rust/src/storagedevice/storage_device.rs
def set_slip39_identifier(identifier: int) -> bool: def set_slip39_identifier(identifier: int) -> bool:
""" """
The device's actual SLIP-39 identifier used in passphrase derivation. The device's actual SLIP-39 identifier used in passphrase derivation.
@ -120,12 +120,12 @@ def set_slip39_identifier(identifier: int) -> bool:
""" """
# rust/src/storagedevice/storagedevice.rs # rust/src/storagedevice/storage_device.rs
def get_slip39_iteration_exponent() -> int | None: def get_slip39_iteration_exponent() -> int | None:
"""The device's actual SLIP-39 iteration exponent used in passphrase derivation.""" """The device's actual SLIP-39 iteration exponent used in passphrase derivation."""
# rust/src/storagedevice/storagedevice.rs # rust/src/storagedevice/storage_device.rs
def set_slip39_iteration_exponent(exponent: int) -> bool: def set_slip39_iteration_exponent(exponent: int) -> bool:
""" """
The device's actual SLIP-39 iteration exponent used in passphrase derivation. The device's actual SLIP-39 iteration exponent used in passphrase derivation.