From cc02e8892ceee94d032fea9ff56f54038968cad0 Mon Sep 17 00:00:00 2001 From: grdddj Date: Wed, 16 Mar 2022 13:34:37 +0100 Subject: [PATCH] WIP - returning None instead of empty bytes --- .../rust/src/storagedevice/storage_device.rs | 9 +++- core/mocks/generated/trezorstoragedevice.pyi | 48 +++++++++---------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/core/embed/rust/src/storagedevice/storage_device.rs b/core/embed/rust/src/storagedevice/storage_device.rs index 12cd943a63..0850b77f5e 100644 --- a/core/embed/rust/src/storagedevice/storage_device.rs +++ b/core/embed/rust/src/storagedevice/storage_device.rs @@ -12,7 +12,6 @@ use core::convert::{TryFrom, TryInto}; // MISSING FUNCTIONALITY: // - returning strings into python -// - return either bytes or None const FLAG_PUBLIC: u8 = 0x80; @@ -143,7 +142,10 @@ extern "C" fn storagedevice_get_label() -> Obj { let block = || { let key = _get_appkey(_LABEL, true); 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::.into()); + } // TODO: how to convert into a string? // let label = StrBuffer::try_from(*result)?; result.try_into() @@ -269,6 +271,9 @@ extern "C" fn storagedevice_get_homescreen() -> Obj { let block = || { let key = _get_appkey(_HOMESCREEN, false); let result = &storagedevice_storage_get_homescreen(key) as &[u8]; + if result.is_empty() { + return Ok(None::.into()); + } result.try_into() }; unsafe { util::try_or_raise(block) } diff --git a/core/mocks/generated/trezorstoragedevice.pyi b/core/mocks/generated/trezorstoragedevice.pyi index 1fedb2ea6a..51b243df78 100644 --- a/core/mocks/generated/trezorstoragedevice.pyi +++ b/core/mocks/generated/trezorstoragedevice.pyi @@ -1,67 +1,67 @@ from typing import * -# rust/src/storagedevice/storagedevice.rs +# rust/src/storagedevice/storage_device.rs def is_version_stored() -> bool: """Whether version is in storage.""" -# rust/src/storagedevice/storagedevice.rs +# rust/src/storagedevice/storage_device.rs def is_initialized() -> bool: """Whether device is initialized.""" -# rust/src/storagedevice/storagedevice.rs +# rust/src/storagedevice/storage_device.rs def get_version() -> bytes: """Get version.""" -# rust/src/storagedevice/storagedevice.rs +# rust/src/storagedevice/storage_device.rs def set_version(version: bytes) -> bool: """Set version.""" -# rust/src/storagedevice/storagedevice.rs +# rust/src/storagedevice/storage_device.rs def get_rotation() -> int: """Get rotation.""" -# rust/src/storagedevice/storagedevice.rs +# rust/src/storagedevice/storage_device.rs def set_rotation(rotation: int) -> bool: """Set rotation.""" -# rust/src/storagedevice/storagedevice.rs +# rust/src/storagedevice/storage_device.rs def get_label() -> str | None: """Get label.""" -# rust/src/storagedevice/storagedevice.rs +# rust/src/storagedevice/storage_device.rs def set_label(label: str) -> bool: """Set label.""" -# rust/src/storagedevice/storagedevice.rs +# rust/src/storagedevice/storage_device.rs def get_mnemonic_secret() -> bytes: """Get mnemonic secret.""" -# rust/src/storagedevice/storagedevice.rs +# rust/src/storagedevice/storage_device.rs def is_passphrase_enabled() -> bool: """Whether passphrase is enabled.""" -# rust/src/storagedevice/storagedevice.rs +# rust/src/storagedevice/storage_device.rs def set_passphrase_enabled(enable: bool) -> bool: """Set whether passphrase is enabled.""" -# rust/src/storagedevice/storagedevice.rs +# rust/src/storagedevice/storage_device.rs def get_passphrase_always_on_device() -> bool: """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: """Set whether passphrase is on device. 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: """Whether backup is still in progress.""" -# rust/src/storagedevice/storagedevice.rs +# rust/src/storagedevice/storage_device.rs def set_unfinished_backup(state: bool) -> bool: """Set backup state.""" -# rust/src/storagedevice/storagedevice.rs +# rust/src/storagedevice/storage_device.rs def needs_backup() -> bool: """Whether backup is needed.""" -# rust/src/storagedevice/storagedevice.rs +# rust/src/storagedevice/storage_device.rs def set_backed_up() -> bool: """Signal that backup is finished.""" -# rust/src/storagedevice/storagedevice.rs +# rust/src/storagedevice/storage_device.rs def no_backup() -> bool: """Whether there is no backup.""" -# rust/src/storagedevice/storagedevice.rs +# rust/src/storagedevice/storage_device.rs def get_homescreen() -> bytes | None: """Get homescreen.""" -# rust/src/storagedevice/storagedevice.rs +# rust/src/storagedevice/storage_device.rs def set_homescreen(homescreen: bytes) -> bool: """Set homescreen.""" -# rust/src/storagedevice/storagedevice.rs +# rust/src/storagedevice/storage_device.rs def get_slip39_identifier() -> int | None: """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: """ 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: """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: """ The device's actual SLIP-39 iteration exponent used in passphrase derivation.