Skip to content

Commit 22fa888

Browse files
committed
Run cargo fmt
1 parent 9af9e99 commit 22fa888

File tree

5 files changed

+61
-63
lines changed

5 files changed

+61
-63
lines changed

ledger_device_sdk/src/ble.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

ledger_device_sdk/src/io.rs

Lines changed: 41 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
32
use ledger_secure_sdk_sys::buttons::{get_button_event, ButtonEvent, ButtonsState};
43
use ledger_secure_sdk_sys::seph as sys_seph;
@@ -17,7 +16,6 @@ unsafe extern "C" {
1716
pub unsafe static mut G_ux_params: bolos_ux_params_t;
1817
}
1918

20-
2119
#[derive(Copy, Clone)]
2220
#[repr(u16)]
2321
pub enum StatusWords {
@@ -103,7 +101,7 @@ pub enum Event<T> {
103101
#[cfg(any(target_os = "stax", target_os = "flex"))]
104102
TouchEvent,
105103
/// Ticker
106-
Ticker
104+
Ticker,
107105
}
108106

109107
/// Manages the communication of the device: receives events such as button presses, incoming
@@ -190,8 +188,7 @@ impl Comm {
190188
if self.tx != 0 {
191189
sys_seph::io_tx(self.apdu_type, &self.apdu_buffer, self.tx);
192190
self.tx = 0;
193-
}
194-
else {
191+
} else {
195192
sys_seph::io_tx(self.apdu_type, &self.io_buffer, self.tx_length);
196193
}
197194
self.tx_length = 0;
@@ -261,7 +258,7 @@ impl Comm {
261258
if status > 0 {
262259
return self.detect_apdu::<T>(status);
263260
}
264-
return false
261+
return false;
265262
}
266263

267264
pub fn check_event<T>(&mut self) -> Option<Event<T>>
@@ -287,10 +284,7 @@ impl Comm {
287284
}
288285

289286
// Manage BOLOS specific APDUs B0xx0000
290-
if self.io_buffer[1] == 0xB0
291-
&& self.io_buffer[3] == 0x00
292-
&& self.io_buffer[4] == 0x00
293-
{
287+
if self.io_buffer[1] == 0xB0 && self.io_buffer[3] == 0x00 && self.io_buffer[4] == 0x00 {
294288
handle_bolos_apdu(self, self.io_buffer[2]);
295289
return None;
296290
}
@@ -327,13 +321,12 @@ impl Comm {
327321
let tag = seph_buffer[0];
328322
let _len: usize = u16::from_be_bytes([seph_buffer[1], seph_buffer[2]]) as usize;
329323

330-
if (length as usize) < _len+3 {
324+
if (length as usize) < _len + 3 {
331325
self.reply(StatusWords::BadLen);
332-
return None
326+
return None;
333327
}
334328

335329
match seph::Events::from(tag) {
336-
337330
// BUTTON PUSH EVENT
338331
#[cfg(not(any(target_os = "stax", target_os = "flex")))]
339332
seph::Events::ButtonPushEvent => {
@@ -352,7 +345,7 @@ impl Comm {
352345
seph::Events::ScreenTouchEvent => unsafe {
353346
ux_process_finger_event(seph_buffer.as_mut_ptr());
354347
return Some(Event::TouchEvent);
355-
}
348+
},
356349

357350
// TICKER EVENT
358351
seph::Events::TickerEvent => {
@@ -367,29 +360,26 @@ impl Comm {
367360
seph::Events::ItcEvent => {
368361
#[cfg(any(target_os = "nanox", target_os = "stax", target_os = "flex"))]
369362
match ItcUxEvent::from(seph_buffer[3]) {
370-
371-
seph::ItcUxEvent::AskBlePairing => {
372-
unsafe {
373-
G_ux_params.ux_id = BOLOS_UX_ASYNCHMODAL_PAIRING_REQUEST;
374-
G_ux_params.len = 20;
375-
G_ux_params.u.pairing_request.type_ = seph_buffer[4];
376-
G_ux_params.u.pairing_request.pairing_info_len = (_len-2) as u32;
377-
for i in 0..G_ux_params.u.pairing_request.pairing_info_len as usize {
378-
G_ux_params.u.pairing_request.pairing_info[i as usize] = seph_buffer[5+i] as i8;
379-
}
380-
G_ux_params.u.pairing_request.pairing_info[G_ux_params.u.pairing_request.pairing_info_len as usize] = 0;
381-
os_ux(&raw mut G_ux_params as *mut bolos_ux_params_t);
363+
seph::ItcUxEvent::AskBlePairing => unsafe {
364+
G_ux_params.ux_id = BOLOS_UX_ASYNCHMODAL_PAIRING_REQUEST;
365+
G_ux_params.len = 20;
366+
G_ux_params.u.pairing_request.type_ = seph_buffer[4];
367+
G_ux_params.u.pairing_request.pairing_info_len = (_len - 2) as u32;
368+
for i in 0..G_ux_params.u.pairing_request.pairing_info_len as usize {
369+
G_ux_params.u.pairing_request.pairing_info[i as usize] =
370+
seph_buffer[5 + i] as i8;
382371
}
383-
}
384-
385-
seph::ItcUxEvent::BlePairingStatus => {
386-
unsafe {
387-
G_ux_params.ux_id = BOLOS_UX_ASYNCHMODAL_PAIRING_STATUS;
388-
G_ux_params.len = 0;
389-
G_ux_params.u.pairing_status.pairing_ok = seph_buffer[4];
390-
os_ux(&raw mut G_ux_params as *mut bolos_ux_params_t);
391-
}
392-
}
372+
G_ux_params.u.pairing_request.pairing_info
373+
[G_ux_params.u.pairing_request.pairing_info_len as usize] = 0;
374+
os_ux(&raw mut G_ux_params as *mut bolos_ux_params_t);
375+
},
376+
377+
seph::ItcUxEvent::BlePairingStatus => unsafe {
378+
G_ux_params.ux_id = BOLOS_UX_ASYNCHMODAL_PAIRING_STATUS;
379+
G_ux_params.len = 0;
380+
G_ux_params.u.pairing_status.pairing_ok = seph_buffer[4];
381+
os_ux(&raw mut G_ux_params as *mut bolos_ux_params_t);
382+
},
393383

394384
seph::ItcUxEvent::Redisplay => {
395385
#[cfg(any(target_os = "stax", target_os = "flex", feature = "nano_nbgl"))]
@@ -400,11 +390,9 @@ impl Comm {
400390
}
401391
}
402392

403-
_ => {
404-
return None
405-
}
393+
_ => return None,
406394
}
407-
return None
395+
return None;
408396
}
409397

410398
// DEFAULT EVENT
@@ -422,7 +410,7 @@ impl Comm {
422410
None
423411
}
424412

425-
pub fn decode_event<T>(&mut self, length:i32) -> Option<Event<T>>
413+
pub fn decode_event<T>(&mut self, length: i32) -> Option<Event<T>>
426414
where
427415
T: TryFrom<ApduHeader>,
428416
Reply: From<<T as TryFrom<ApduHeader>>::Error>,
@@ -434,45 +422,45 @@ impl Comm {
434422
// SE or SEPH event
435423
let mut seph_buffer = [0u8; 272];
436424
seph_buffer[0..272].copy_from_slice(&self.io_buffer[1..273]);
437-
if let Some(event) = self.process_event(seph_buffer, length-1) {
425+
if let Some(event) = self.process_event(seph_buffer, length - 1) {
438426
return Some(event);
439427
}
440428
}
441429

442-
seph::PacketTypes::PacketTypeRawApdu |
443-
seph::PacketTypes::PacketTypeUsbHidApdu |
444-
seph::PacketTypes::PacketTypeUsbWebusbApdu |
445-
seph::PacketTypes::PacketTypeBleApdu=> {
430+
seph::PacketTypes::PacketTypeRawApdu
431+
| seph::PacketTypes::PacketTypeUsbHidApdu
432+
| seph::PacketTypes::PacketTypeUsbWebusbApdu
433+
| seph::PacketTypes::PacketTypeBleApdu => {
446434
unsafe {
447435
if os_perso_is_pin_set() == BOLOS_TRUE.try_into().unwrap()
448-
&& os_global_pin_is_validated() != BOLOS_TRUE.try_into().unwrap() {
436+
&& os_global_pin_is_validated() != BOLOS_TRUE.try_into().unwrap()
437+
{
449438
self.reply(StatusWords::DeviceLocked);
450439
return None;
451440
}
452441
}
453442
self.apdu_buffer[0..272].copy_from_slice(&self.io_buffer[1..273]);
454443
self.apdu_type = packet_type;
455444
self.rx_length = length as usize;
456-
self.rx = self.rx_length-1;
445+
self.rx = self.rx_length - 1;
457446
self.event_pending = true;
458447
return self.check_event();
459448
}
460449

461-
_ => {
462-
}
450+
_ => {}
463451
}
464452
None
465453
}
466454

467-
fn detect_apdu<T>(&mut self, length:i32) -> bool
455+
fn detect_apdu<T>(&mut self, length: i32) -> bool
468456
where
469457
T: TryFrom<ApduHeader>,
470458
Reply: From<<T as TryFrom<ApduHeader>>::Error>,
471459
{
472460
match self.decode_event::<T>(length) {
473461
Some(Event::Command(_)) => {
474462
self.rx_length = length as usize;
475-
self.rx = self.rx_length-1;
463+
self.rx = self.rx_length - 1;
476464
self.event_pending = true;
477465
return true;
478466
}
@@ -585,8 +573,7 @@ impl Comm {
585573
(0, 6) => Ok(&[]), // Non-conforming zero-data APDU
586574
(0, 7) => Err(StatusWords::BadLen),
587575
(0, _) => {
588-
let len =
589-
u16::from_le_bytes([self.io_buffer[6], self.io_buffer[7]]) as usize;
576+
let len = u16::from_le_bytes([self.io_buffer[6], self.io_buffer[7]]) as usize;
590577
get_data_from_buffer(len, 8)
591578
}
592579
(len, _) => get_data_from_buffer(len, 6),

ledger_device_sdk/src/seph.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ impl From<u8> for ItcUxEvent {
7373
}
7474
}
7575

76-
7776
/// FFI bindings to USBD functions inlined here for clarity
7877
/// and also because some of the generated ones are incorrectly
7978
/// assuming mutable pointers when they are not

ledger_secure_sdk_sys/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const SDK_C_FILES: [&str; 13] = [
2121
"io/src/os_io.c",
2222
"io/src/os_io_default_apdu.c",
2323
"io/src/os_io_seph_cmd.c",
24-
"io/src/os_io_seph_ux.c"
24+
"io/src/os_io_seph_ux.c",
2525
];
2626

2727
const CFLAGS_NANOSPLUS: [&str; 22] = [

ledger_secure_sdk_sys/src/seph.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1-
use crate::{
2-
os_io_rx_evt,
3-
os_io_tx_cmd,
4-
};
1+
use crate::{os_io_rx_evt, os_io_tx_cmd};
52

63
/// Receive the next APDU into 'buffer'
74
pub fn io_rx(buffer: &mut [u8], check_se_event: bool) -> i32 {
8-
unsafe { os_io_rx_evt(buffer.as_ptr() as _, buffer.len() as u16, core::ptr::null_mut(), check_se_event) }
5+
unsafe {
6+
os_io_rx_evt(
7+
buffer.as_ptr() as _,
8+
buffer.len() as u16,
9+
core::ptr::null_mut(),
10+
check_se_event,
11+
)
12+
}
913
}
1014

11-
pub fn io_tx(apdu_type: u8, buffer: &[u8], length:usize) -> i32 {
12-
unsafe { os_io_tx_cmd(apdu_type, buffer.as_ptr() as _, length as u16, core::ptr::null_mut()) }
15+
pub fn io_tx(apdu_type: u8, buffer: &[u8], length: usize) -> i32 {
16+
unsafe {
17+
os_io_tx_cmd(
18+
apdu_type,
19+
buffer.as_ptr() as _,
20+
length as u16,
21+
core::ptr::null_mut(),
22+
)
23+
}
1324
}

0 commit comments

Comments
 (0)