Skip to content

Commit

Permalink
Some enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
neithanmo committed Nov 19, 2024
1 parent 64a56e5 commit 0fd750d
Show file tree
Hide file tree
Showing 7 changed files with 437 additions and 20 deletions.
152 changes: 137 additions & 15 deletions app/rust/Cargo.lock

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

4 changes: 4 additions & 0 deletions app/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ hex = { version = "0.4" }
minicbor = { version = "0.24.2", features = ["std"] }
ic-certification = { version = "2.5.0", features = ["serde"] }
serde_cbor = "0.11.2"
serde_json = "1.0.85"
zuit = { path = "../../deps/ledger-rust/zuit" }
insta = { version = "1", features = ["glob"] }
serde = { version = "1.0.215", features = ["derive"] }


[target.'cfg(fuzzing)'.dependencies]
Expand All @@ -43,3 +46,4 @@ panic = "abort"

[features]
clippy = []
derive-debug = []
6 changes: 3 additions & 3 deletions app/rust/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ mod ffi_verify_cert {
unsafe {
// 1. send consent_request
if rs_parse_consent_request(consent_data.as_ptr(), consent_data.len() as u16)
!= ParserError::Ok as _
!= ParserError::Ok as u32
{
std::println!("Error parsing consent request");
return ParserError::InvalidConsentMsg as u32;
}

// 2. send call request
if rs_parse_canister_call_request(call_data.as_ptr(), call_data.len() as u16)
!= ParserError::Ok as _
!= ParserError::Ok as u32
{
std::println!("Error parsing call request");
return ParserError::InvalidCallRequest as u32;
Expand All @@ -62,7 +62,7 @@ mod ffi_verify_cert {
cert_data.as_ptr(),
cert_data.len() as u16,
root_key.as_ptr(),
) != ParserError::Ok as _
) != ParserError::Ok as u32
{
std::println!("Error verifying certificate");
return ParserError::InvalidCertificate as u32;
Expand Down
4 changes: 3 additions & 1 deletion app/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern crate no_std_compat as std;

pub mod candid_types;
mod constants;
mod error;
pub mod error;
mod ffi;
mod parser;
mod principal;
Expand All @@ -18,6 +18,8 @@ pub use principal::Principal;
use zemu_sys as _;
pub mod argument_list;
pub mod candid_header;
#[cfg(test)]
pub mod test_ui;

pub use parser::*;

Expand Down
2 changes: 1 addition & 1 deletion app/rust/src/parser/candid_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ mod tests {
let input = &[1, 0x2A, 0x00]; // 1 followed by 42 in little endian
let (rem, value) = parse_opt_i16(input).unwrap();
assert_eq!(value, Some(42));
assert_eq!(rem, &[]);
assert!(rem.is_empty());

// Test invalid tag
let input = &[2, 0x00, 0x00];
Expand Down
3 changes: 3 additions & 0 deletions app/rust/src/parser/testvectors/ui_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"response": "4449444c0c6b02bc8a0101c5fed201096c02efcee7800402e29fdcc806046c02aeaeb1cc0503d880c6d007716e766b02d9e5b0980405fcdfd79a0f716c01c4d6b4ea0b066d076c01ffbb87a807086d716b04d1c4987c0aa3f2efe6020b9a8597e6030be3c581900f0b6c02fc91f4f80571c498b1b50d7d6c01fc91f4f805710100000002656e0007031e2320417574686f72697a6520616e6f74686572206164647265737320746f2077697468647261772066726f6d20796f7572206163636f756e74202a2a5468651f666f6c6c6f77696e67206164647265737320697320616c6c6f77656420746f031d77697468647261772066726f6d20796f7572206163636f756e743a2a2a2272646d78362d6a616161612d61616161612d61616164712d636169202a2a596f75720d7375626163636f756e743a2a2a032330303030303030303030303030303030303030303030303030303030303030303030301d3030303030303030303030303030303030303030303030303030303030232a2a526571756573746564207769746864726177616c20616c6c6f77616e63653a2a2a032031302049435020e29aa02054686520616c6c6f77616e63652077696c6c2062652273657420746f2031302049435020696e646570656e64656e746c79206f6620616e791e70726576696f757320616c6c6f77616e63652e20556e74696c207468697303217472616e73616374696f6e20686173206265656e206578656375746564207468651e7370656e6465722063616e207374696c6c206578657263697365207468652370726576696f757320616c6c6f77616e63652028696620616e792920746f2069742773032166756c6c20616d6f756e742e202a2a45787069726174696f6e20646174653a2a2a204e6f2065787069726174696f6e2e202a2a417070726f76616c206665653a2a2a23302e3030303120494350202a2a5472616e73616374696f6e206665657320746f206265031a7061696420627920796f7572207375626163636f756e743a2a2a2330303030303030303030303030303030303030303030303030303030303030303030301d3030303030303030303030303030303030303030303030303030303030"
}
Loading

0 comments on commit 0fd750d

Please sign in to comment.