ctap2-proto: Add authenticator::client_pin::raw::PublicKey type for deserialization
The cosey::PublicKey type does not properly implement deserialize for the general PublicKey type. the client_pin::raw::PublicKey type is used as an intermediate to allow deserialization of COSE public keys in the client_pin protocol.main
parent
984e43cd18
commit
df78c9e303
@ -0,0 +1,6 @@
|
|||||||
|
//! Used to make serialization and deseriazation of the request and response
|
||||||
|
//! possible in CBOR format while maintaining ergonomic enum variants for public
|
||||||
|
//! API.
|
||||||
|
|
||||||
|
mod public_key;
|
||||||
|
|
@ -0,0 +1,32 @@
|
|||||||
|
use cosey::{EcdhEsHkdf256PublicKey, Ed25519PublicKey, P256PublicKey};
|
||||||
|
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
pub(crate) enum PublicKey {
|
||||||
|
P256Key(P256PublicKey),
|
||||||
|
EcdhEsHkdf256Key(EcdhEsHkdf256PublicKey),
|
||||||
|
Ed25519Key(Ed25519PublicKey),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Into<cosey::PublicKey> for PublicKey {
|
||||||
|
fn into(self) -> cosey::PublicKey {
|
||||||
|
match self {
|
||||||
|
PublicKey::P256Key(key) => cosey::PublicKey::P256Key(key),
|
||||||
|
PublicKey::EcdhEsHkdf256Key(key) => cosey::PublicKey::EcdhEsHkdf256Key(key),
|
||||||
|
PublicKey::Ed25519Key(key) => cosey::PublicKey::Ed25519Key(key),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn deserialize<'de, D>(deserializer: D) -> Result<Option<cosey::PublicKey>, D::Error>
|
||||||
|
where
|
||||||
|
D: serde::Deserializer<'de>,
|
||||||
|
{
|
||||||
|
PublicKey::deserialize(deserializer)
|
||||||
|
.map(Into::into)
|
||||||
|
.map(Some)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue