Rename extend_cbor_map_options

This commit is contained in:
Julien Cretin
2020-05-11 16:07:59 +02:00
parent e6fdcacd32
commit 491721b421
2 changed files with 15 additions and 14 deletions

View File

@@ -41,32 +41,31 @@ macro_rules! cbor_map_options {
};
( $( $key:expr => $value:expr ),* ) => {
cbor_extend_map_options! (
::alloc::collections::BTreeMap::<_, $crate::values::Value>::new(),
$( $key => $value, )*
)
{
let mut _map = ::alloc::collections::BTreeMap::<_, $crate::values::Value>::new();
extend_cbor_map_options! ( &mut _map, $( $key => $value, )* );
$crate::values::Value::Map(_map)
}
};
}
#[macro_export]
macro_rules! cbor_extend_map_options {
macro_rules! extend_cbor_map_options {
// Add trailing comma if missing.
( $initial:expr, $( $key:expr => $value:expr ),+ ) => {
cbor_extend_map_options! ( $initial, $($key => $value,)+ )
( &mut $initial:expr, $( $key:expr => $value:expr ),+ ) => {
extend_cbor_map_options! ( &mut $initial, $($key => $value,)+ )
};
( $initial:expr, $( $key:expr => $value:expr, )* ) => {
( &mut $initial:expr, $( $key:expr => $value:expr, )* ) => {
{
// The import is unused if the list is empty.
#[allow(unused_imports)]
use $crate::values::{IntoCborKey, IntoCborValueOption};
let mut _map = $initial;
$(
if let Some(val) = $value.into_cbor_value_option() {
_map.insert($key.into_cbor_key(), val);
$initial.insert($key.into_cbor_key(), val);
}
)*
$crate::values::Value::Map(_map)
}
};
}

View File

@@ -480,15 +480,17 @@ impl From<PublicKeyCredentialSource> for cbor::Value {
use PublicKeyCredentialSourceField::*;
let mut private_key = [0; 32];
credential.private_key.to_bytes(&mut private_key);
cbor_extend_map_options! {
credential.unknown_fields,
let mut result = credential.unknown_fields;
extend_cbor_map_options! {
&mut result,
CredentialId => Some(credential.credential_id),
PrivateKey => Some(private_key.to_vec()),
RpId => Some(credential.rp_id),
UserHandle => Some(credential.user_handle),
OtherUi => credential.other_ui,
CredRandom => credential.cred_random
}
};
cbor::Value::Map(result)
}
}