/// Parse a CBOR-encoded key in the COSE (RFC 8152) format
///
/// # Arguments
/// * `pk_cose` the CBOR-encoded COSE key
/// # Errors
/// * `MalformedPublicKey` if the data could not be CBOR-decoded
/// * `AlgorithmNotSupported` if the key was decoded but is some unsupported
///   algorithm
///
/// # Returns
/// The decoded key as an SPKI
Parse a CBOR-encoded key in the COSE (RFC 8152) format
Parse a CBOR - encoded key in the COSE ( RFC 8152 ) format
pub fn parse_cose_public_key(pk_cose: &[u8]) -> CryptoResult<(AlgorithmId, Vec<u8>)> {
    match CosePublicKey::from_cbor(pk_cose) {
        Ok(key) => Ok((key.algorithm_id(), key.encoded_key())),
        Err(CosePublicKeyParseError::MalformedPublicKey(algorithm)) => {
            Err(CryptoError::MalformedPublicKey {
                algorithm,
                key_bytes: Some(pk_cose.to_vec()),
                internal_error: "Failed to parse COSE public key".to_string(),
            })
        }
        Err(CosePublicKeyParseError::AlgorithmNotSupported) => {
            Err(CryptoError::AlgorithmNotSupported {
                algorithm: AlgorithmId::Placeholder,
                reason: "Algorithm not supported in COSE parser".to_string(),
            })
        }
    }
}
pub fn parse_cose_public_key ( pk_cose : & [ u8 ] ) -> CryptoResult < ( AlgorithmId , Vec < u8 > ) > { match CosePublicKey :: from_cbor ( pk_cose ) { Ok ( key ) => Ok ( ( key . algorithm_id ( ) , key . encoded_key ( ) ) ) , Err ( CosePublicKeyParseError :: MalformedPublicKey ( algorithm ) ) => { Err ( CryptoError :: MalformedPublicKey { algorithm , key_bytes : Some ( pk_cose . to_vec ( ) ) , internal_error : " " . to_string ( ) , } ) } Err ( CosePublicKeyParseError :: AlgorithmNotSupported ) => { Err ( CryptoError :: AlgorithmNotSupported { algorithm : AlgorithmId :: Placeholder , reason : " " . to_string ( ) , } ) } } }
Parse a CBOR-encoded key in the COSE (RFC 8152) format
Parse a CBOR - encoded key in the COSE ( RFC 8152 ) format
The decoded key as an SPKI
The decoded key as an SPKI
pk_cose
&[u8]
errors
`MalformedPublicKey` if the data could not be CBOR-decoded
`AlgorithmNotSupported` if the key was decoded but is some unsupported
algorithm
` MalformedPublicKey ` if the data could not be CBOR - decoded ` AlgorithmNotSupported ` if the key was decoded but is some unsupported algorithm