Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SFT-2271: Upgrade to foundation-rs #342

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 75 additions & 50 deletions extmod/foundation-rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions extmod/foundation-rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ default-features = false
version = "1"
default-features = false

[dependencies.ur]
git = "https://github.com/Foundation-Devices/ur-rs"
branch = "dev"
[dependencies.foundation-ur]
git = "https://github.com/Foundation-Devices/foundation-rs"
branch = "main"
default-features = false

[dependencies.ur-foundation]
git = "https://github.com/Foundation-Devices/rust-ur-foundation"
branch = "dev-v0.1.0"
[dependencies.foundation-urtypes]
git = "https://github.com/Foundation-Devices/foundation-rs"
branch = "main"
default-features = false

[target.'cfg(target_arch = "arm")'.dependencies.cortex-m]
Expand Down
7 changes: 1 addition & 6 deletions extmod/foundation-rust/include/foundation.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@
*/
#define UR_NETWORK_TESTNET 1

/**
* Maximum number of components that a `crypto-keypath` can have.
*/
#define UR_MAX_PATH_COMPONENTS 4

typedef enum {
BTC,
} UR_CoinType;
Expand Down Expand Up @@ -441,7 +436,7 @@ bool ur_decode_single_part(const uint8_t *ur,
* # Parameters
*
* - `value` is the uniform resource to encode.
* - `max_fragment_len` is the maximum fragment length in bytes.
* - `max_chars` is the maximum fragment length in bytes.
*
* # Safety
*
Expand Down
26 changes: 11 additions & 15 deletions extmod/foundation-rust/src/ur/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

use core::{fmt, slice, str};

use ur::UR;
use ur_foundation::{ur, ur::decoder::Error};

use crate::ur::{
max_fragment_len, max_message_len, registry::UR_Value, UR_Error,
use foundation_ur::{
bytewords, bytewords::Style, decoder::Error, max_fragment_len,
HeaplessDecoder, UR,
};

use crate::ur::{max_message_len, registry::UR_Value, UR_Error, UR_MAX_TYPE};

/// Maximum size of an encoded Uniform Resource.
///
/// This value assumes a QR code of version of 16 with ECC L using
Expand All @@ -25,7 +25,7 @@ pub const UR_DECODER_MAX_SEQUENCE_COUNT: usize = 128;

/// Maximum fragment length.
pub const UR_DECODER_MAX_FRAGMENT_LEN: usize =
max_fragment_len(UR_DECODER_MAX_STRING);
max_fragment_len(UR_MAX_TYPE, usize::MAX, UR_DECODER_MAX_STRING);

/// Maximum message length that can be decoded.
pub const UR_DECODER_MAX_MESSAGE_LEN: usize = 24 * 1024;
Expand All @@ -49,7 +49,7 @@ pub const UR_DECODER_MAX_UR_TYPE: usize = "crypto-coin-info".len();
#[used]
#[cfg_attr(dtcm, link_section = ".dtcm")]
pub static mut UR_DECODER: UR_Decoder = UR_Decoder {
inner: ur::HeaplessDecoder::new_heapless(),
inner: HeaplessDecoder::new(),
};

/// cbindgen:ignore
Expand All @@ -62,7 +62,7 @@ static mut UR_DECODER_SINGLE_PART_MESSAGE: heapless::Vec<

/// Uniform Resource decoder.
pub struct UR_Decoder {
inner: ur::HeaplessDecoder<
inner: HeaplessDecoder<
UR_DECODER_MAX_MESSAGE_LEN,
UR_DECODER_MAX_MIXED_PARTS,
UR_DECODER_MAX_FRAGMENT_LEN,
Expand Down Expand Up @@ -213,11 +213,7 @@ pub unsafe extern "C" fn ur_validate(ur: *const u8, ur_len: usize) -> bool {
.as_bytewords()
.expect("Parsed URs shouldn't be in a deserialized variant");

return ur::bytewords::validate(
bytewords,
ur::bytewords::Style::Minimal,
)
.is_ok();
return bytewords::validate(bytewords, Style::Minimal).is_ok();
}

false
Expand Down Expand Up @@ -256,11 +252,11 @@ pub unsafe extern "C" fn ur_decode_single_part(
.resize(UR_DECODER_MAX_SINGLE_PART_MESSAGE_LEN, 0)
.expect("Message buffer should have the same size as in the constant");

let result = ur::bytewords::decode_to_slice(
let result = bytewords::decode_to_slice(
ur.as_bytewords()
.expect("Uniform Resource should contain bytewords"),
message,
ur::bytewords::Style::Minimal,
Style::Minimal,
)
.map_err(|e| unsafe { UR_Error::other(&e) });

Expand Down
Loading