Simplify syntax of the read_cbor_map! macro, to align it with cbor_map.

This commit is contained in:
Guillaume Endignoux
2020-06-09 15:26:55 +02:00
parent 2c4bf7d422
commit 2124511913
3 changed files with 70 additions and 69 deletions

View File

@@ -126,15 +126,15 @@ impl TryFrom<cbor::Value> for AuthenticatorMakeCredentialParameters {
fn try_from(cbor_value: cbor::Value) -> Result<Self, Ctap2StatusCode> {
read_cbor_map! {
extract_map(cbor_value)?,
client_data_hash @ cbor_unsigned!(1),
rp @ cbor_unsigned!(2),
user @ cbor_unsigned!(3),
cred_param_vec @ cbor_unsigned!(4),
exclude_list @ cbor_unsigned!(5),
extensions @ cbor_unsigned!(6),
options @ cbor_unsigned!(7),
pin_uv_auth_param @ cbor_unsigned!(8),
pin_uv_auth_protocol @ cbor_unsigned!(9),
client_data_hash @ 1,
rp @ 2,
user @ 3,
cred_param_vec @ 4,
exclude_list @ 5,
extensions @ 6,
options @ 7,
pin_uv_auth_param @ 8,
pin_uv_auth_protocol @ 9,
};
let client_data_hash = extract_byte_string(ok_or_missing(client_data_hash)?)?;
@@ -208,13 +208,13 @@ impl TryFrom<cbor::Value> for AuthenticatorGetAssertionParameters {
fn try_from(cbor_value: cbor::Value) -> Result<Self, Ctap2StatusCode> {
read_cbor_map! {
extract_map(cbor_value)?,
rp_id @ cbor_unsigned!(1),
client_data_hash @ cbor_unsigned!(2),
allow_list @ cbor_unsigned!(3),
extensions @ cbor_unsigned!(4),
options @ cbor_unsigned!(5),
pin_uv_auth_param @ cbor_unsigned!(6),
pin_uv_auth_protocol @ cbor_unsigned!(7),
rp_id @ 1,
client_data_hash @ 2,
allow_list @ 3,
extensions @ 4,
options @ 5,
pin_uv_auth_param @ 6,
pin_uv_auth_protocol @ 7,
};
let rp_id = extract_text_string(ok_or_missing(rp_id)?)?;
@@ -277,12 +277,12 @@ impl TryFrom<cbor::Value> for AuthenticatorClientPinParameters {
fn try_from(cbor_value: cbor::Value) -> Result<Self, Ctap2StatusCode> {
read_cbor_map! {
extract_map(cbor_value)?,
pin_protocol @ cbor_unsigned!(1),
sub_command @ cbor_unsigned!(2),
key_agreement @ cbor_unsigned!(3),
pin_auth @ cbor_unsigned!(4),
new_pin_enc @ cbor_unsigned!(5),
pin_hash_enc @ cbor_unsigned!(6),
pin_protocol @ 1,
sub_command @ 2,
key_agreement @ 3,
pin_auth @ 4,
new_pin_enc @ 5,
pin_hash_enc @ 6,
};
let pin_protocol = extract_unsigned(ok_or_missing(pin_protocol)?)?;

View File

@@ -33,9 +33,9 @@ impl TryFrom<cbor::Value> for PublicKeyCredentialRpEntity {
fn try_from(cbor_value: cbor::Value) -> Result<Self, Ctap2StatusCode> {
read_cbor_map! {
extract_map(cbor_value)?,
rp_id @ cbor_text!("id"),
rp_icon @ cbor_text!("icon"),
rp_name @ cbor_text!("name"),
rp_id @ "id",
rp_icon @ "icon",
rp_name @ "name",
};
let rp_id = extract_text_string(ok_or_missing(rp_id)?)?;
@@ -65,10 +65,10 @@ impl TryFrom<cbor::Value> for PublicKeyCredentialUserEntity {
fn try_from(cbor_value: cbor::Value) -> Result<Self, Ctap2StatusCode> {
read_cbor_map! {
extract_map(cbor_value)?,
user_id @ cbor_text!("id"),
user_icon @ cbor_text!("icon"),
user_name @ cbor_text!("name"),
user_display_name @ cbor_text!("displayName"),
user_id @ "id",
user_icon @ "icon",
user_name @ "name",
user_display_name @ "displayName",
};
let user_id = extract_byte_string(ok_or_missing(user_id)?)?;
@@ -143,8 +143,8 @@ impl TryFrom<cbor::Value> for PublicKeyCredentialParameter {
fn try_from(cbor_value: cbor::Value) -> Result<Self, Ctap2StatusCode> {
read_cbor_map! {
extract_map(cbor_value)?,
alg @ cbor_text!("alg"),
cred_type @ cbor_text!("type"),
alg @ "alg",
cred_type @ "type",
};
let cred_type = PublicKeyCredentialType::try_from(ok_or_missing(cred_type)?)?;
@@ -212,9 +212,9 @@ impl TryFrom<cbor::Value> for PublicKeyCredentialDescriptor {
fn try_from(cbor_value: cbor::Value) -> Result<Self, Ctap2StatusCode> {
read_cbor_map! {
extract_map(cbor_value)?,
key_id @ cbor_text!("id"),
key_type @ cbor_text!("type"),
transports @ cbor_text!("transports"),
key_id @ "id",
key_type @ "type",
transports @ "transports",
};
let key_type = PublicKeyCredentialType::try_from(ok_or_missing(key_type)?)?;
@@ -261,8 +261,8 @@ impl TryFrom<cbor::Value> for MakeCredentialExtensions {
fn try_from(cbor_value: cbor::Value) -> Result<Self, Ctap2StatusCode> {
read_cbor_map! {
extract_map(cbor_value)?,
cred_protect @ cbor_text!("credProtect"),
hmac_secret @ cbor_text!("hmac-secret"),
cred_protect @ "credProtect",
hmac_secret @ "hmac-secret",
};
let hmac_secret = hmac_secret.map_or(Ok(false), extract_bool)?;
@@ -287,7 +287,7 @@ impl TryFrom<cbor::Value> for GetAssertionExtensions {
fn try_from(cbor_value: cbor::Value) -> Result<Self, Ctap2StatusCode> {
read_cbor_map! {
extract_map(cbor_value)?,
hmac_secret @ cbor_text!("hmac-secret"),
hmac_secret @ "hmac-secret",
};
let hmac_secret = hmac_secret
@@ -310,9 +310,9 @@ impl TryFrom<cbor::Value> for GetAssertionHmacSecretInput {
fn try_from(cbor_value: cbor::Value) -> Result<Self, Ctap2StatusCode> {
read_cbor_map! {
extract_map(cbor_value)?,
cose_key @ cbor_unsigned!(1),
salt_enc @ cbor_unsigned!(2),
salt_auth @ cbor_unsigned!(3),
cose_key @ 1,
salt_enc @ 2,
salt_auth @ 3,
};
let cose_key = extract_map(ok_or_missing(cose_key)?)?;
@@ -339,9 +339,9 @@ impl TryFrom<cbor::Value> for MakeCredentialOptions {
fn try_from(cbor_value: cbor::Value) -> Result<Self, Ctap2StatusCode> {
read_cbor_map! {
extract_map(cbor_value)?,
rk @ cbor_text!("rk"),
up @ cbor_text!("up"),
uv @ cbor_text!("uv"),
rk @ "rk",
up @ "up",
uv @ "uv",
};
let rk = match rk {
@@ -373,9 +373,9 @@ impl TryFrom<cbor::Value> for GetAssertionOptions {
fn try_from(cbor_value: cbor::Value) -> Result<Self, Ctap2StatusCode> {
read_cbor_map! {
extract_map(cbor_value)?,
rk @ cbor_text!("rk"),
up @ cbor_text!("up"),
uv @ cbor_text!("uv"),
rk @ "rk",
up @ "up",
uv @ "uv",
};
if let Some(options_entry) = rk {
@@ -630,11 +630,11 @@ impl TryFrom<CoseKey> for ecdh::PubKey {
fn try_from(cose_key: CoseKey) -> Result<Self, Ctap2StatusCode> {
read_cbor_map! {
cose_key.0,
key_type @ cbor_int!(1),
algorithm @ cbor_int!(3),
curve @ cbor_int!(-1),
x_bytes @ cbor_int!(-2),
y_bytes @ cbor_int!(-3),
key_type @ 1,
algorithm @ 3,
curve @ -1,
x_bytes @ -2,
y_bytes @ -3,
};
let key_type = extract_integer(ok_or_missing(key_type)?)?;