Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions libwebauthn/src/proto/ctap1/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@ use crate::webauthn::CtapError;

#[derive(Debug, Clone, Copy)]
pub enum Ctap1Transport {
BT,
BLE,
NFC,
USB,
Bt,
Ble,
Nfc,
Usb,
}

impl TryFrom<&Ctap2Transport> for Ctap1Transport {
type Error = CtapError;
fn try_from(ctap2: &Ctap2Transport) -> Result<Ctap1Transport, Self::Error> {
match ctap2 {
Ctap2Transport::BLE => Ok(Ctap1Transport::BLE),
Ctap2Transport::USB => Ok(Ctap1Transport::USB),
Ctap2Transport::NFC => Ok(Ctap1Transport::NFC),
Ctap2Transport::INTERNAL => Err(CtapError::UnsupportedOption),
Ctap2Transport::Ble => Ok(Ctap1Transport::Ble),
Ctap2Transport::Usb => Ok(Ctap1Transport::Usb),
Ctap2Transport::Nfc => Ok(Ctap1Transport::Nfc),
Ctap2Transport::Internal => Err(CtapError::UnsupportedOption),
Ctap2Transport::Hybrid => Err(CtapError::UnsupportedOption),
}
}
}
Expand Down
27 changes: 14 additions & 13 deletions libwebauthn/src/proto/ctap2/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,20 @@ pub enum Ctap2PublicKeyCredentialType {
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Ctap2Transport {
BLE,
NFC,
USB,
INTERNAL,
Ble,
Nfc,
Usb,
Internal,
Hybrid,
}

impl From<&Ctap1Transport> for Ctap2Transport {
fn from(ctap1: &Ctap1Transport) -> Ctap2Transport {
match ctap1 {
Ctap1Transport::BT => Ctap2Transport::BLE,
Ctap1Transport::BLE => Ctap2Transport::BLE,
Ctap1Transport::USB => Ctap2Transport::USB,
Ctap1Transport::NFC => Ctap2Transport::NFC,
Ctap1Transport::Bt => Ctap2Transport::Ble,
Ctap1Transport::Ble => Ctap2Transport::Ble,
Ctap1Transport::Usb => Ctap2Transport::Usb,
Ctap1Transport::Nfc => Ctap2Transport::Nfc,
}
}
}
Expand Down Expand Up @@ -211,13 +212,13 @@ pub enum Ctap2UserVerificationOperation {
mod tests {
use crate::proto::ctap2::Ctap2PublicKeyCredentialDescriptor;

use super::{Ctap2CredentialType, Ctap2COSEAlgorithmIdentifier, Ctap2PublicKeyCredentialType};
use super::{Ctap2COSEAlgorithmIdentifier, Ctap2CredentialType, Ctap2PublicKeyCredentialType};
use hex;
use serde_bytes::ByteBuf;
use serde_cbor;
use hex;

#[test]
/// Verify CBOR serialization conforms to CTAP canonical standard, including ordering (see #95)
/// Verify CBOR serialization conforms to CTAP canonical standard, including ordering (see #95)
pub fn credential_type_field_serialization() {
let credential_type = Ctap2CredentialType {
algorithm: Ctap2COSEAlgorithmIdentifier::ES256,
Expand All @@ -230,7 +231,7 @@ mod tests {
}

#[test]
/// Verify CBOR serialization conforms to CTAP canonical standard, including ordering (see #95)
/// Verify CBOR serialization conforms to CTAP canonical standard, including ordering (see #95)
pub fn credential_descriptor_serialization() {
let credential_descriptor = Ctap2PublicKeyCredentialDescriptor {
id: ByteBuf::from(vec![0x42]),
Expand All @@ -242,4 +243,4 @@ mod tests {
let expected = hex::decode("a2626964414264747970656a7075626c69632d6b6579").unwrap();
assert_eq!(serialized, expected);
}
}
}
Loading