fn ykpiv_auth_getchallenge() -> Result<[u8; 8], ErrorKind>

This commit is contained in:
Jack Grigg
2019-11-20 12:16:23 +00:00
parent b750b9cbbb
commit 71a334a9b8
+9 -24
View File
@@ -2191,23 +2191,12 @@ pub unsafe fn ykpiv_attest(
} }
/// Get an auth challenge /// Get an auth challenge
pub unsafe fn ykpiv_auth_getchallenge( pub unsafe fn ykpiv_auth_getchallenge(state: &mut YubiKey) -> Result<[u8; 8], ErrorKind> {
state: &mut YubiKey,
challenge: *mut u8,
challenge_len: usize,
) -> Result<(), ErrorKind> {
let mut data = [0u8; 261]; let mut data = [0u8; 261];
let mut recv_len = data.len() as u32; let mut recv_len = data.len() as u32;
let mut sw: i32 = 0; let mut sw: i32 = 0;
let mut res = Ok(()); // TODO(str4d): What should the default value be if the application is not selected?
let mut res = Ok([0; 8]);
if challenge.is_null() {
return Err(ErrorKind::GenericError);
}
if challenge_len != 8 {
return Err(ErrorKind::SizeError);
}
_ykpiv_begin_transaction(state)?; _ykpiv_begin_transaction(state)?;
@@ -2221,18 +2210,14 @@ pub unsafe fn ykpiv_auth_getchallenge(
apdu.data[1] = 0x02; apdu.data[1] = 0x02;
apdu.data[2] = 0x81; //0x80; apdu.data[2] = 0x81; //0x80;
res = _send_data(state, &mut apdu, data.as_mut_ptr(), &mut recv_len, &mut sw); if let Err(e) = _send_data(state, &mut apdu, data.as_mut_ptr(), &mut recv_len, &mut sw) {
res = Err(e)
if res.is_err() { } else if sw != SW_SUCCESS {
if sw != SW_SUCCESS {
res = Err(ErrorKind::AuthenticationError); res = Err(ErrorKind::AuthenticationError);
} else { } else {
memcpy( let mut challenge = [0; 8];
challenge as (*mut c_void), challenge.copy_from_slice(&data[4..12]);
data.as_mut_ptr().offset(4isize) as (*const c_void), res = Ok(challenge);
8usize,
);
}
} }
} }