ctap2-proto: Add raw module with RawSubcommand to authenticator::credential::management

RawSubcommand is de/serialized as a u8 corresponding to its subCommand
number.

Also implements Display for authenticator::credential::management::Error
so that it can be used as the serde error type for RawSubcommand.
main
Nick Zana 1 year ago
parent eb06e4c88d
commit ed57873783

@ -3,6 +3,9 @@ use fido_common::credential::public_key;
pub type PinUvAuthParam = [u8; 16]; pub type PinUvAuthParam = [u8; 16];
#[cfg(feature = "serde")]
mod raw;
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
pub enum Request<'a> { pub enum Request<'a> {
GetCredentialsMetadata { GetCredentialsMetadata {
@ -106,3 +109,17 @@ pub enum Error {
NoCredentials, NoCredentials,
KeyStoreFull, KeyStoreFull,
} }
impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let message = match self {
Error::PinUvAuthTokenRequired => "PIN/UV auth token required",
Error::MissingParameter => "Missing parameter",
Error::InvalidParameter => "Invalid parameter",
Error::PinAuthInvalid => "PIN auth invalid",
Error::NoCredentials => "No credentials",
Error::KeyStoreFull => "Key store full",
};
write!(f, "{}", message)
}
}

@ -0,0 +1,37 @@
use super::Error;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(into = "u8", try_from = "u8")]
enum RawSubcommand {
GetCredsMetadata = 0x01,
EnumerateRpsBegin = 0x02,
EnumerateRpsGetNextRp = 0x03,
EnumerateCredentialsBegin = 0x04,
EnumerateCredentialsGetNextCredential = 0x05,
DeleteCredential = 0x06,
UpdateUserInformation = 0x07,
}
impl From<RawSubcommand> for u8 {
fn from(val: RawSubcommand) -> Self {
val as u8
}
}
impl TryFrom<u8> for RawSubcommand {
type Error = Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Ok(match value {
0x01 => RawSubcommand::GetCredsMetadata,
0x02 => RawSubcommand::EnumerateRpsBegin,
0x03 => RawSubcommand::EnumerateRpsGetNextRp,
0x04 => RawSubcommand::EnumerateCredentialsBegin,
0x05 => RawSubcommand::EnumerateCredentialsGetNextCredential,
0x06 => RawSubcommand::DeleteCredential,
0x07 => RawSubcommand::UpdateUserInformation,
_ => return Err(Error::InvalidParameter),
})
}
}
Loading…
Cancel
Save