Skip to content

Commit c4b93bb

Browse files
committed
Rename device-agnostic APDU methods
1 parent f4ce954 commit c4b93bb

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

src/apdu.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub trait APDUDevice {
1717
// Device Commands
1818
////////////////////////////////////////////////////////////////////////
1919

20-
pub fn u2f_register<T>(dev: &mut T, challenge: &[u8], application: &[u8]) -> io::Result<Vec<u8>>
20+
pub fn apdu_register<T>(dev: &mut T, challenge: &[u8], application: &[u8]) -> io::Result<Vec<u8>>
2121
where
2222
T: APDUDevice,
2323
{
@@ -34,10 +34,10 @@ where
3434

3535
let flags = U2F_REQUEST_USER_PRESENCE;
3636
let (resp, status) = dev.send_apdu(U2F_REGISTER, flags, &register_data)?;
37-
status_word_to_result(status, resp)
37+
apdu_status_to_result(status, resp)
3838
}
3939

40-
pub fn u2f_sign<T>(
40+
pub fn apdu_sign<T>(
4141
dev: &mut T,
4242
challenge: &[u8],
4343
application: &[u8],
@@ -68,10 +68,10 @@ where
6868

6969
let flags = U2F_REQUEST_USER_PRESENCE;
7070
let (resp, status) = dev.send_apdu(U2F_AUTHENTICATE, flags, &sign_data)?;
71-
status_word_to_result(status, resp)
71+
apdu_status_to_result(status, resp)
7272
}
7373

74-
pub fn u2f_is_keyhandle_valid<T>(
74+
pub fn apdu_is_keyhandle_valid<T>(
7575
dev: &mut T,
7676
challenge: &[u8],
7777
application: &[u8],
@@ -105,21 +105,21 @@ where
105105
Ok(status == SW_CONDITIONS_NOT_SATISFIED)
106106
}
107107

108-
pub fn is_v2_device<T>(dev: &mut T) -> io::Result<bool>
108+
pub fn apdu_is_v2_device<T>(dev: &mut T) -> io::Result<bool>
109109
where
110110
T: APDUDevice
111111
{
112112
let (data, status) = dev.send_apdu(U2F_VERSION, 0x00, &[])?;
113113
let actual = CString::new(data)?;
114114
let expected = CString::new("U2F_V2")?;
115-
status_word_to_result(status, actual == expected)
115+
apdu_status_to_result(status, actual == expected)
116116
}
117117

118118
////////////////////////////////////////////////////////////////////////
119119
// Error Handling
120120
////////////////////////////////////////////////////////////////////////
121121

122-
pub fn status_word_to_result<T>(status: [u8; 2], val: T) -> io::Result<T> {
122+
pub fn apdu_status_to_result<T>(status: [u8; 2], val: T) -> io::Result<T> {
123123
use self::io::ErrorKind::{InvalidData, InvalidInput};
124124

125125
match status {

src/statemachine.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::errors;
77
use crate::platform::device::Device;
88
use crate::platform::transaction::Transaction;
99
use crate::statecallback::StateCallback;
10-
use crate::apdu::{u2f_is_keyhandle_valid, u2f_register, u2f_sign, APDUDevice};
10+
use crate::apdu::{apdu_is_keyhandle_valid, apdu_register, apdu_sign, APDUDevice};
1111
use crate::u2ftypes::U2FInfoQueryable;
1212

1313
use std::sync::mpsc::Sender;
@@ -117,20 +117,20 @@ impl StateMachine {
117117
// consent, to be consistent with CTAP2 device behavior.
118118
let excluded = key_handles.iter().any(|key_handle| {
119119
is_valid_transport(key_handle.transports)
120-
&& u2f_is_keyhandle_valid(dev, &challenge, &application, &key_handle.credential)
120+
&& apdu_is_keyhandle_valid(dev, &challenge, &application, &key_handle.credential)
121121
.unwrap_or(false) /* no match on failure */
122122
});
123123

124124
while alive() {
125125
if excluded {
126126
let blank = vec![0u8; PARAMETER_SIZE];
127-
if u2f_register(dev, &blank, &blank).is_ok() {
127+
if apdu_register(dev, &blank, &blank).is_ok() {
128128
callback.call(Err(errors::AuthenticatorError::U2FToken(
129129
errors::U2FTokenError::InvalidState,
130130
)));
131131
break;
132132
}
133-
} else if let Ok(bytes) = u2f_register(dev, &challenge, &application) {
133+
} else if let Ok(bytes) = apdu_register(dev, &challenge, &application) {
134134
let dev_info = dev.get_device_info();
135135
send_status(
136136
&status_mutex,
@@ -201,7 +201,7 @@ impl StateMachine {
201201
// valid key handle for an appId, we'll use that appId below.
202202
let (app_id, valid_handles) =
203203
find_valid_key_handles(&app_ids, &key_handles, |app_id, key_handle| {
204-
u2f_is_keyhandle_valid(dev, &challenge, app_id, &key_handle.credential)
204+
apdu_is_keyhandle_valid(dev, &challenge, app_id, &key_handle.credential)
205205
.unwrap_or(false) /* no match on failure */
206206
});
207207

@@ -230,7 +230,7 @@ impl StateMachine {
230230
// then just make it blink with bogus data.
231231
if valid_handles.is_empty() {
232232
let blank = vec![0u8; PARAMETER_SIZE];
233-
if u2f_register(dev, &blank, &blank).is_ok() {
233+
if apdu_register(dev, &blank, &blank).is_ok() {
234234
callback.call(Err(errors::AuthenticatorError::U2FToken(
235235
errors::U2FTokenError::InvalidState,
236236
)));
@@ -239,7 +239,7 @@ impl StateMachine {
239239
} else {
240240
// Otherwise, try to sign.
241241
for key_handle in &valid_handles {
242-
if let Ok(bytes) = u2f_sign(dev, &challenge, app_id, &key_handle.credential)
242+
if let Ok(bytes) = apdu_sign(dev, &challenge, app_id, &key_handle.credential)
243243
{
244244
let dev_info = dev.get_device_info();
245245
send_status(

src/u2fprotocol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ where
2323
thread_rng().fill_bytes(&mut nonce);
2424

2525
// Initialize the device and check its version.
26-
init_device(self, &nonce).and(is_v2_device(self)).map(|_| ())
26+
init_device(self, &nonce).and(apdu_is_v2_device(self)).map(|_| ())
2727
}
2828

2929
fn send_apdu(&mut self, cmd: u8, p1: u8, send: &[u8]) -> io::Result<(Vec<u8>, [u8; 2])>

0 commit comments

Comments
 (0)