Skip to content

Commit

Permalink
Minor fixes following code review
Browse files Browse the repository at this point in the history
  • Loading branch information
kingofpayne committed Dec 11, 2023
1 parent c0957e7 commit 8f48d21
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
28 changes: 12 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,7 @@ use handlers::{
get_version::handler_get_version,
sign_tx::{handler_sign_tx, TxContext},
};
use ledger_device_sdk::{
io::{ApduHeader, Comm, Event, Reply, StatusWords},
ui::{
gadgets::clear_screen,
layout::{Layout, Location, StringPlace},
screen_util::screen_update,
},
};
use ledger_secure_sdk_sys::buttons::ButtonEvent;
use ledger_device_sdk::io::{ApduHeader, Comm, Event, Reply, StatusWords};

ledger_device_sdk::set_panic!(ledger_device_sdk::exiting_panic);

Expand Down Expand Up @@ -75,7 +67,7 @@ pub enum AppSW {
TxSignFail = 0xB008,
KeyDeriveFail = 0xB009,
VersionParsingFail = 0xB00A,
BadLen = StatusWords::BadLen as u16,
WrongApduLength = StatusWords::BadLen as u16,
}

impl From<AppSW> for Reply {
Expand Down Expand Up @@ -126,16 +118,20 @@ impl TryFrom<ApduHeader> for Instruction {
// Developer mode / pending review popup
// must be cleared with user interaction
fn display_pending_review(comm: &mut Comm) {
use ledger_device_sdk::buttons::ButtonEvent::{
BothButtonsRelease, LeftButtonRelease, RightButtonRelease,
};
use ledger_device_sdk::ui::gadgets::clear_screen;
use ledger_device_sdk::ui::layout::{Layout, Location, StringPlace};
use ledger_device_sdk::ui::screen_util::screen_update;

clear_screen();
"Pending Review".place(Location::Middle, Layout::Centered, false);
screen_update();

loop {
if let Event::Button(
ButtonEvent::LeftButtonRelease
| ButtonEvent::RightButtonRelease
| ButtonEvent::BothButtonsRelease,
) = comm.next_event::<ApduHeader>()
if let Event::Button(LeftButtonRelease | RightButtonRelease | BothButtonsRelease) =
comm.next_event::<ApduHeader>()
{
break;
}
Expand All @@ -156,7 +152,7 @@ extern "C" fn sample_main() {
if let Event::Command(ins) = ui_menu_main(&mut comm) {
match handle_apdu(&mut comm, ins, &mut tx_ctx) {
Ok(()) => comm.reply_ok(),
Err(sw) => comm.reply(Reply::from(sw)),
Err(sw) => comm.reply(sw),
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions tests/application_client/boilerplate_command_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ class InsType(IntEnum):
class Errors(IntEnum):
SW_DENY = 0x6985
SW_WRONG_P1P2 = 0x6A86
SW_WRONG_DATA_LENGTH = 0x6A87
SW_INS_NOT_SUPPORTED = 0x6D00
SW_CLA_NOT_SUPPORTED = 0x6E00
SW_BAD_LENGTH = 0x6E03
SW_WRONG_APDU_LENGTH = 0x6E03
SW_WRONG_RESPONSE_LENGTH = 0xB000
SW_DISPLAY_BIP32_PATH_FAIL = 0xB001
SW_DISPLAY_ADDRESS_FAIL = 0xB002
Expand Down
4 changes: 2 additions & 2 deletions tests/test_error_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ def test_wrong_data_length(backend):
# APDUs must be at least 4 bytes: CLA, INS, P1, P2.
with pytest.raises(ExceptionRAPDU) as e:
backend.exchange_raw(bytes.fromhex("E00300"))
assert e.value.status == Errors.SW_BAD_LENGTH
assert e.value.status == Errors.SW_WRONG_APDU_LENGTH
# APDUs advertises a too long length
with pytest.raises(ExceptionRAPDU) as e:
backend.exchange_raw(bytes.fromhex("E003000005"))
assert e.value.status == Errors.SW_BAD_LENGTH
assert e.value.status == Errors.SW_WRONG_APDU_LENGTH


# Ensure there is no state confusion when trying wrong APDU sequences
Expand Down

0 comments on commit 8f48d21

Please sign in to comment.