| 1 |
use super::{Command, CommandError, RequestCtap2, StatusCode}; |
| 2 |
use crate::ctap2::commands::get_assertion::GetAssertionResponse; |
| 3 |
use crate::transport::errors::HIDError; |
| 4 |
use crate::transport::{FidoDevice, VirtualFidoDevice}; |
| 5 |
use serde_cbor::{de::from_slice, Value}; |
| 6 |
|
| 7 |
#[derive(Debug)] |
| 8 |
pub(crate) struct GetNextAssertion; |
| 9 |
|
| 10 |
impl RequestCtap2 for GetNextAssertion { |
| 11 |
type Output = GetAssertionResponse; |
| 12 |
|
| 13 |
fn command(&self) -> Command { |
| 14 |
Command::GetNextAssertion |
| 15 |
} |
| 16 |
|
| 17 |
fn wire_format(&self) -> Result<Vec<u8>, HIDError> { |
| 18 |
Ok(Vec::new()) |
| 19 |
} |
| 20 |
|
| 21 |
fn handle_response_ctap2<Dev: FidoDevice>( |
| 22 |
&self, |
| 23 |
_dev: &mut Dev, |
| 24 |
input: &[u8], |
| 25 |
) -> Result<Self::Output, HIDError> { |
| 26 |
if input.is_empty() { |
| 27 |
return Err(CommandError::InputTooSmall.into()); |
| 28 |
} |
| 29 |
|
| 30 |
let status: StatusCode = input[0].into(); |
| 31 |
debug!("response status code: {:?}", status); |
| 32 |
if input.len() > 1 { |
| 33 |
if status.is_ok() { |
| 34 |
let assertion = from_slice(&input[1..]).map_err(CommandError::Deserializing)?; |
| 35 |
// TODO(baloo): check assertion response does not have numberOfCredentials |
| 36 |
Ok(assertion) |
| 37 |
} else { |
| 38 |
let data: Value = from_slice(&input[1..]).map_err(CommandError::Deserializing)?; |
| 39 |
Err(CommandError::StatusCode(status, Some(data)).into()) |
| 40 |
} |
| 41 |
} else if status.is_ok() { |
| 42 |
Err(CommandError::InputTooSmall.into()) |
| 43 |
} else { |
| 44 |
Err(CommandError::StatusCode(status, None).into()) |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
fn send_to_virtual_device<Dev: VirtualFidoDevice>( |
| 49 |
&self, |
| 50 |
_dev: &mut Dev, |
| 51 |
) -> Result<Self::Output, HIDError> { |
| 52 |
unimplemented!() |
| 53 |
} |
| 54 |
} |