-
Notifications
You must be signed in to change notification settings - Fork 9
list applications installed on device #7
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a31ed91
list application installed on devices using unsecure instructions (re…
yogh333 2b76eeb
moved list app feature as default method on Device
yogh333 9316d48
fix CI test issue
yogh333 160db21
fix CI test issue when no_std building of proto package
yogh333 d9034e5
cargo fmt + clippy
yogh333 f6bdbea
Updates after Copilot review
yogh333 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| use encdec::{Decode, Encode}; | ||
|
|
||
| extern crate alloc; | ||
| use alloc::string::String; | ||
| use alloc::vec::Vec; | ||
|
|
||
| use crate::{ApduError, ApduStatic}; | ||
|
|
||
| /// App List Start APDU command | ||
| #[derive(Copy, Clone, PartialEq, Debug, Default, Encode, Decode)] | ||
| #[encdec(error = "ApduError")] | ||
| pub struct AppListStartReq {} | ||
|
|
||
| /// App List Next APDU command | ||
| #[derive(Copy, Clone, PartialEq, Debug, Default, Encode, Decode)] | ||
| #[encdec(error = "ApduError")] | ||
| pub struct AppListNextReq {} | ||
|
|
||
| impl ApduStatic for AppListStartReq { | ||
| /// App list start request APDU is class `0xe0` | ||
| const CLA: u8 = 0xe0; | ||
|
|
||
| /// App list start request APDU is instruction `0x01` | ||
| const INS: u8 = 0xde; | ||
| } | ||
|
|
||
| impl ApduStatic for AppListNextReq { | ||
| /// App list next request APDU is class `0xe0` | ||
| const CLA: u8 = 0xe0; | ||
|
|
||
| /// App list next request APDU is instruction `0x01` | ||
| const INS: u8 = 0xdf; | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, Default, PartialEq)] | ||
| pub struct AppData { | ||
| pub flags: u32, | ||
| pub hash_code_data: [u8; 32], | ||
| pub hash: [u8; 32], | ||
| pub name: String, | ||
| } | ||
|
|
||
| /// Decodes an `AppData` structure from a binary slice, starting at the given offset. | ||
| /// | ||
| /// # Binary format | ||
| /// The expected format of the data is as follows (all fields are in order): | ||
| /// | ||
| /// - [0] : 1 byte - Reserved or tag byte (skipped by `*offset += 1`) | ||
| /// - [1..5] : 4 bytes - Flags (big-endian u32) | ||
| /// - [5..37] : 32 bytes - Hash code data | ||
| /// - [37..69] : 32 bytes - Hash | ||
| /// - [69] : 1 byte - Length of the name field (N) | ||
| /// - [70..70+N]: N bytes - Name (UTF-8 encoded) | ||
| /// | ||
| /// The function updates the provided `offset` as it parses each field. | ||
| /// | ||
| /// # Arguments | ||
| /// * `data` - The binary slice containing the encoded `AppData`. | ||
| /// * `offset` - A mutable reference to the current offset in the slice. This will be updated as fields are parsed. | ||
| /// | ||
| /// # Returns | ||
| /// * `Ok(AppData)` if decoding is successful. | ||
| /// * `Err(ApduError)` if decoding fails. | ||
| pub fn decode_app_data(data: &[u8], offset: &mut usize) -> Result<AppData, ApduError> { | ||
| *offset += 1; | ||
| let mut app_info: AppData = Default::default(); | ||
| let bytes = | ||
| <[u8; 4]>::try_from(&data[*offset..*offset + 4]).map_err(|_| ApduError::InvalidLength)?; | ||
| app_info.flags = u32::from_be_bytes(bytes); | ||
| *offset += 4; | ||
| if data.len() < *offset + 32 { | ||
| return Err(ApduError::InvalidLength); | ||
| } | ||
| app_info | ||
| .hash_code_data | ||
| .copy_from_slice(&data[*offset..*offset + 32]); | ||
| *offset += 32; | ||
|
yogh333 marked this conversation as resolved.
|
||
| if data.len() < *offset + 32 { | ||
| return Err(ApduError::InvalidLength); | ||
| } | ||
| app_info.hash.copy_from_slice(&data[*offset..*offset + 32]); | ||
| *offset += 32; | ||
| if data.len() <= *offset { | ||
| return Err(ApduError::InvalidLength); | ||
| } | ||
| let name_len: usize = data[*offset] as usize; | ||
| *offset += 1; | ||
| if data.len() < *offset + name_len { | ||
| return Err(ApduError::InvalidLength); | ||
| } | ||
| app_info.name = String::from_utf8(Vec::from(&data[*offset..*offset + name_len])).unwrap(); | ||
|
yogh333 marked this conversation as resolved.
|
||
| *offset += name_len; | ||
|
|
||
| Ok(app_info) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.