Migrate PublicKeyCredentialSource to read_cbor_map.
I didn't realize that the values were actually constants, as discriminants of an enum.
This commit is contained in:
@@ -530,27 +530,32 @@ impl TryFrom<cbor::Value> for PublicKeyCredentialSource {
|
|||||||
type Error = Ctap2StatusCode;
|
type Error = Ctap2StatusCode;
|
||||||
|
|
||||||
fn try_from(cbor_value: cbor::Value) -> Result<Self, Ctap2StatusCode> {
|
fn try_from(cbor_value: cbor::Value) -> Result<Self, Ctap2StatusCode> {
|
||||||
use PublicKeyCredentialSourceField::*;
|
use PublicKeyCredentialSourceField::{
|
||||||
let mut map = extract_map(cbor_value)?;
|
CredProtectPolicy, CredRandom, CredentialId, OtherUi, PrivateKey, RpId, UserHandle,
|
||||||
let credential_id = extract_byte_string(ok_or_missing(map.remove(&CredentialId.into()))?)?;
|
};
|
||||||
let private_key = extract_byte_string(ok_or_missing(map.remove(&PrivateKey.into()))?)?;
|
read_cbor_map! {
|
||||||
|
extract_map(cbor_value)?,
|
||||||
|
credential_id @ CredentialId,
|
||||||
|
private_key @ PrivateKey,
|
||||||
|
rp_id @ RpId,
|
||||||
|
user_handle @ UserHandle,
|
||||||
|
other_ui @ OtherUi,
|
||||||
|
cred_random @ CredRandom,
|
||||||
|
cred_protect_policy @ CredProtectPolicy,
|
||||||
|
};
|
||||||
|
|
||||||
|
let credential_id = extract_byte_string(ok_or_missing(credential_id)?)?;
|
||||||
|
let private_key = extract_byte_string(ok_or_missing(private_key)?)?;
|
||||||
if private_key.len() != 32 {
|
if private_key.len() != 32 {
|
||||||
return Err(Ctap2StatusCode::CTAP2_ERR_INVALID_CBOR);
|
return Err(Ctap2StatusCode::CTAP2_ERR_INVALID_CBOR);
|
||||||
}
|
}
|
||||||
let private_key = ecdsa::SecKey::from_bytes(array_ref!(private_key, 0, 32))
|
let private_key = ecdsa::SecKey::from_bytes(array_ref!(private_key, 0, 32))
|
||||||
.ok_or(Ctap2StatusCode::CTAP2_ERR_INVALID_CBOR)?;
|
.ok_or(Ctap2StatusCode::CTAP2_ERR_INVALID_CBOR)?;
|
||||||
let rp_id = extract_text_string(ok_or_missing(map.remove(&RpId.into()))?)?;
|
let rp_id = extract_text_string(ok_or_missing(rp_id)?)?;
|
||||||
let user_handle = extract_byte_string(ok_or_missing(map.remove(&UserHandle.into()))?)?;
|
let user_handle = extract_byte_string(ok_or_missing(user_handle)?)?;
|
||||||
let other_ui = map
|
let other_ui = other_ui.map(extract_text_string).transpose()?;
|
||||||
.remove(&OtherUi.into())
|
let cred_random = cred_random.map(extract_byte_string).transpose()?;
|
||||||
.map(extract_text_string)
|
let cred_protect_policy = cred_protect_policy
|
||||||
.transpose()?;
|
|
||||||
let cred_random = map
|
|
||||||
.remove(&CredRandom.into())
|
|
||||||
.map(extract_byte_string)
|
|
||||||
.transpose()?;
|
|
||||||
let cred_protect_policy = map
|
|
||||||
.remove(&CredProtectPolicy.into())
|
|
||||||
.map(CredentialProtectionPolicy::try_from)
|
.map(CredentialProtectionPolicy::try_from)
|
||||||
.transpose()?;
|
.transpose()?;
|
||||||
// We don't return whether there were unknown fields in the CBOR value. This means that
|
// We don't return whether there were unknown fields in the CBOR value. This means that
|
||||||
|
|||||||
Reference in New Issue
Block a user