Skip to content

Commit 5c9160a

Browse files
Adjust CTAP transport casing
1 parent 97ba35b commit 5c9160a

3 files changed

Lines changed: 43 additions & 21 deletions

File tree

libwebauthn/src/proto/ctap1/model.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ use crate::webauthn::CtapError;
1212

1313
#[derive(Debug, Clone, Copy)]
1414
pub enum Ctap1Transport {
15-
BT,
16-
BLE,
17-
NFC,
18-
USB,
15+
Bt,
16+
Ble,
17+
Nfc,
18+
Usb,
1919
}
2020

2121
impl TryFrom<&Ctap2Transport> for Ctap1Transport {
2222
type Error = CtapError;
2323
fn try_from(ctap2: &Ctap2Transport) -> Result<Ctap1Transport, Self::Error> {
2424
match ctap2 {
25-
Ctap2Transport::BLE => Ok(Ctap1Transport::BLE),
26-
Ctap2Transport::USB => Ok(Ctap1Transport::USB),
27-
Ctap2Transport::NFC => Ok(Ctap1Transport::NFC),
28-
Ctap2Transport::INTERNAL => Err(CtapError::UnsupportedOption),
25+
Ctap2Transport::Ble => Ok(Ctap1Transport::Ble),
26+
Ctap2Transport::Usb => Ok(Ctap1Transport::Usb),
27+
Ctap2Transport::Nfc => Ok(Ctap1Transport::Nfc),
28+
Ctap2Transport::Internal => Err(CtapError::UnsupportedOption),
2929
}
3030
}
3131
}

libwebauthn/src/proto/ctap2/model.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,19 @@ pub enum Ctap2PublicKeyCredentialType {
121121
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
122122
#[serde(rename_all = "lowercase")]
123123
pub enum Ctap2Transport {
124-
BLE,
125-
NFC,
126-
USB,
127-
INTERNAL,
124+
Ble,
125+
Nfc,
126+
Usb,
127+
Internal,
128128
}
129129

130130
impl From<&Ctap1Transport> for Ctap2Transport {
131131
fn from(ctap1: &Ctap1Transport) -> Ctap2Transport {
132132
match ctap1 {
133-
Ctap1Transport::BT => Ctap2Transport::BLE,
134-
Ctap1Transport::BLE => Ctap2Transport::BLE,
135-
Ctap1Transport::USB => Ctap2Transport::USB,
136-
Ctap1Transport::NFC => Ctap2Transport::NFC,
133+
Ctap1Transport::Bt => Ctap2Transport::Ble,
134+
Ctap1Transport::Ble => Ctap2Transport::Ble,
135+
Ctap1Transport::Usb => Ctap2Transport::Usb,
136+
Ctap1Transport::Nfc => Ctap2Transport::Nfc,
137137
}
138138
}
139139
}
@@ -211,13 +211,13 @@ pub enum Ctap2UserVerificationOperation {
211211
mod tests {
212212
use crate::proto::ctap2::Ctap2PublicKeyCredentialDescriptor;
213213

214-
use super::{Ctap2CredentialType, Ctap2COSEAlgorithmIdentifier, Ctap2PublicKeyCredentialType};
214+
use super::{Ctap2COSEAlgorithmIdentifier, Ctap2CredentialType, Ctap2PublicKeyCredentialType};
215+
use hex;
215216
use serde_bytes::ByteBuf;
216217
use serde_cbor;
217-
use hex;
218218

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

232232
#[test]
233-
/// Verify CBOR serialization conforms to CTAP canonical standard, including ordering (see #95)
233+
/// Verify CBOR serialization conforms to CTAP canonical standard, including ordering (see #95)
234234
pub fn credential_descriptor_serialization() {
235235
let credential_descriptor = Ctap2PublicKeyCredentialDescriptor {
236236
id: ByteBuf::from(vec![0x42]),
@@ -242,4 +242,4 @@ mod tests {
242242
let expected = hex::decode("a2626964414264747970656a7075626c69632d6b6579").unwrap();
243243
assert_eq!(serialized, expected);
244244
}
245-
}
245+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use minicbor::{Decode, Encode};
2+
3+
/// Credential protection policy as defined in the CTAP2 spec.
4+
///
5+
/// This replaces the ctap_types::ctap2::credential_management::CredentialProtectionPolicy
6+
/// to avoid external dependency.
7+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Encode, Decode)]
8+
#[cbor(index_only)]
9+
pub enum CredentialProtectionPolicy {
10+
#[n(1)]
11+
UserVerificationOptional = 0x01,
12+
#[n(2)]
13+
UserVerificationOptionalWithCredentialIdList = 0x02,
14+
#[n(3)]
15+
UserVerificationRequired = 0x03,
16+
}
17+
18+
impl Default for CredentialProtectionPolicy {
19+
fn default() -> Self {
20+
Self::UserVerificationOptional
21+
}
22+
}

0 commit comments

Comments
 (0)