diff --git a/src/ctap/data_formats.rs b/src/ctap/data_formats.rs index 133b957..d226fca 100644 --- a/src/ctap/data_formats.rs +++ b/src/ctap/data_formats.rs @@ -155,7 +155,7 @@ impl From for cbor::Value { fn from(cred_param: PublicKeyCredentialParameter) -> Self { cbor_map_options! { "type" => cred_param.cred_type, - "alg" => cred_param.alg as i64, + "alg" => cred_param.alg, } } } @@ -429,6 +429,12 @@ pub enum SignatureAlgorithm { Unknown = 0, } +impl From for cbor::Value { + fn from(alg: SignatureAlgorithm) -> Self { + (alg as i64).into() + } +} + impl TryFrom<&cbor::Value> for SignatureAlgorithm { type Error = Ctap2StatusCode; @@ -448,6 +454,12 @@ pub enum CredentialProtectionPolicy { UserVerificationRequired = 0x03, } +impl From for cbor::Value { + fn from(policy: CredentialProtectionPolicy) -> Self { + (policy as i64).into() + } +} + impl TryFrom for CredentialProtectionPolicy { type Error = Ctap2StatusCode; @@ -526,7 +538,7 @@ impl From for cbor::Value { UserHandle => Some(credential.user_handle), OtherUi => credential.other_ui, CredRandom => credential.cred_random, - CredProtectPolicy => credential.cred_protect_policy.map(|p| p as i64), + CredProtectPolicy => credential.cred_protect_policy, } } } @@ -1137,7 +1149,7 @@ mod test { let signature_algorithm = SignatureAlgorithm::try_from(&cbor_signature_algorithm); let expected_signature_algorithm = SignatureAlgorithm::ES256; assert_eq!(signature_algorithm, Ok(expected_signature_algorithm)); - let created_cbor: cbor::Value = cbor_int!(signature_algorithm.unwrap() as i64); + let created_cbor = cbor::Value::from(signature_algorithm.unwrap()); assert_eq!(created_cbor, cbor_signature_algorithm); let cbor_unknown_algorithm = cbor_int!(-1); @@ -1164,11 +1176,11 @@ mod test { #[test] fn test_from_into_cred_protection_policy() { - let cbor_policy = cbor_int!(CredentialProtectionPolicy::UserVerificationOptional as i64); + let cbor_policy = cbor::Value::from(CredentialProtectionPolicy::UserVerificationOptional); let policy = CredentialProtectionPolicy::try_from(&cbor_policy); let expected_policy = CredentialProtectionPolicy::UserVerificationOptional; assert_eq!(policy, Ok(expected_policy)); - let created_cbor: cbor::Value = cbor_int!(policy.unwrap() as i64); + let created_cbor = cbor::Value::from(policy.unwrap()); assert_eq!(created_cbor, cbor_policy); let cbor_policy_error = cbor_int!(-1); @@ -1290,7 +1302,7 @@ mod test { #[test] fn test_cred_protect_extension() { let cbor_extensions = cbor_map! { - "credProtect" => CredentialProtectionPolicy::UserVerificationRequired as i64, + "credProtect" => CredentialProtectionPolicy::UserVerificationRequired, }; let extensions = Extensions::try_from(&cbor_extensions).unwrap(); assert_eq!( diff --git a/src/ctap/mod.rs b/src/ctap/mod.rs index a8081bc..5514fea 100644 --- a/src/ctap/mod.rs +++ b/src/ctap/mod.rs @@ -522,7 +522,7 @@ where .user_display_name .map(|s| truncate_to_char_boundary(&s, 64).to_string()), cred_random, - cred_protect_policy: cred_protect_policy.clone(), + cred_protect_policy, }; self.persistent_store.store_credential(credential_source)?; random_id @@ -547,7 +547,7 @@ where let hmac_secret_output = if use_hmac_extension { Some(true) } else { None }; let extensions = cbor_map_options! { "hmac-secret" => hmac_secret_output, - "credProtect" => cred_protect_policy.map(|policy| policy as i64), + "credProtect" => cred_protect_policy, }; if !cbor::write(extensions, &mut auth_data) { return Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_RESPONSE_CANNOT_WRITE_CBOR); @@ -1220,7 +1220,7 @@ mod test { policy: CredentialProtectionPolicy, ) -> AuthenticatorMakeCredentialParameters { let mut extension_map = BTreeMap::new(); - extension_map.insert("credProtect".to_string(), cbor_int!(policy as i64)); + extension_map.insert("credProtect".to_string(), cbor::Value::from(policy)); let extensions = Some(Extensions::new(extension_map)); let mut make_credential_params = create_minimal_make_credential_parameters(); make_credential_params.extensions = extensions;