Skip to content

Commit

Permalink
fix: hard-coded CLA byte
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI committed Jun 19, 2024
1 parent 4460475 commit 0e3be5d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/ledger/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ impl AsRef<[u8]> for APDUData {
/// additional format details
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct APDUCommand {
/// The application identifier.
pub cla: u8,
/// The instruction code.
pub ins: u8,
/// Instruction parameter 1
Expand All @@ -78,6 +80,7 @@ pub struct APDUCommand {
impl std::fmt::Display for APDUCommand {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("APDUCommand")
.field("cla", &self.cla)
.field("ins", &self.ins)
.field("p1", &self.p1)
.field("p2", &self.p2)
Expand All @@ -101,7 +104,7 @@ impl APDUCommand {

/// Write the APDU packet to the specified Write interface
pub fn write_to<W: std::io::Write>(&self, w: &mut W) -> Result<usize, std::io::Error> {
w.write_all(&[0xE0, self.ins, self.p1, self.p2])?;
w.write_all(&[self.cla, self.ins, self.p1, self.p2])?;
if !self.data.is_empty() {
w.write_all(&[self.data.len() as u8])?;
w.write_all(self.data.as_ref())?;
Expand Down Expand Up @@ -311,6 +314,7 @@ mod test {
let data: &[u8] = &[0, 0, 0, 1, 0, 0, 0, 1];

let command = APDUCommand {
cla: 0xe0,
ins: 0x01,
p1: 0x00,
p2: 0x00,
Expand All @@ -323,6 +327,7 @@ mod test {
assert_eq!(serialized_command, expected);

let command = APDUCommand {
cla: 0xe0,
ins: 0x01,
p1: 0x00,
p2: 0x00,
Expand Down
1 change: 1 addition & 0 deletions crates/ledger/src/transports/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ impl LedgerTransport {

// Ethereum `get_app_version`
let command = APDUCommand {
cla: 0xe0,
ins: 0x06,
p1: 0x00,
p2: 0x00,
Expand Down
1 change: 1 addition & 0 deletions crates/ledger/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ async fn exchange() {
let buf: &[u8] = &[];
// Ethereum `get_app_version`
let command = APDUCommand {
cla: 0xe0,
ins: 0x06,
p1: 0x00,
p2: 0x00,
Expand Down

0 comments on commit 0e3be5d

Please sign in to comment.