pub fn thumbprint(
        &self,
        algorithm: &'static crate::digest::Algorithm,
    ) -> Result<String, serde_json::error::Error> {
        use serde::ser::SerializeMap;

        use crate::serde_custom::{base64_url_uint, byte_sequence};

        let mut serializer = serde_json::Serializer::new(Vec::new());
        let mut map = serializer.serialize_map(None)?;
        // https://tools.ietf.org/html/rfc7638#section-3.2
        // Write required public key parameters in lexicographic order
        match self {
            AlgorithmParameters::EllipticCurve(params) => {
                map.serialize_entry("crv", &params.curve)?;
                map.serialize_entry("kty", &params.key_type)?;
                map.serialize_entry("x", &byte_sequence::wrap(&params.x))?;
                map.serialize_entry("y", &byte_sequence::wrap(&params.y))?;
            }
            AlgorithmParameters::RSA(params) => {
                map.serialize_entry("e", &base64_url_uint::wrap(&params.e))?;
                map.serialize_entry("kty", &params.key_type)?;
                map.serialize_entry("n", &base64_url_uint::wrap(&params.n))?;
            }
            AlgorithmParameters::OctetKey(params) => {
                map.serialize_entry("k", &byte_sequence::wrap(&params.value))?;
                map.serialize_entry("kty", &params.key_type)?;
            }
            AlgorithmParameters::OctetKeyPair(params) => {
                map.serialize_entry("crv", &params.curve)?;
                map.serialize_entry("kty", &params.key_type)?;
                map.serialize_entry("x", &byte_sequence::wrap(&params.x))?;
            }
        }
        map.end()?;
        let json_u8 = serializer.into_inner();
        Ok(BASE64URL_NOPAD.encode(ring::digest::digest(algorithm.0, &json_u8).as_ref()))
    }
/// JWK thumbprints are digests for identifying key material.
/// Their computation is specified in
/// [RFC 7638](https://tools.ietf.org/html/rfc7638).
///
/// This can be used to identify a public key; when the underlying digest algorithm
/// is collision-resistant (currently, the SHA-2 family is provided), it is infeasible
/// to build two keys sharing a thumbprint.
///
/// As mentioned in the RFC's security considerations, it remains possible to build
/// related keys with distinct parameters and thumbprints.
///
/// ```
/// // Example from https://tools.ietf.org/html/rfc7638#section-3.1
/// let jwk: biscuit::jwk::JWK<biscuit::Empty> = serde_json::from_str(
/// r#"{
///   "kty": "RSA",
///   "n": "0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw",
///   "e": "AQAB",
///   "alg": "RS256",
///   "kid": "2011-04-29"
///   }"#,
/// ).unwrap();
/// assert_eq!(
///   jwk.algorithm.thumbprint(&biscuit::digest::SHA256).unwrap(),
///   "NzbLsXh8uDCcd-6MNwXF4W_7noWXFZAfHkxZsRGC9Xs"
/// );
/// ```
JWK thumbprints are digests for identifying key material.
Their computation is specified in
[RFC 7638].

This can be used to identify a public key; when the underlying digest algorithm
is collision-resistant (currently, the SHA-2 family is provided), it is infeasible
to build two keys sharing a thumbprint.

As mentioned in the RFC's security considerations, it remains possible to build
related keys with distinct parameters and thumbprints.


JWK thumbprints are digests for identifying key material . Their computation is specified in [ RFC 7638 ] . This can be used to identify a public key ; when the underlying digest algorithm is collision - resistant ( currently the SHA - 2 family is provided ) it is infeasible to build two keys sharing a thumbprint . As mentioned in the RFC ' s security considerations it remains possible to build related keys with distinct parameters and thumbprints .
pub fn thumbprint(
        &self,
        algorithm: &'static crate::digest::Algorithm,
    ) -> Result<String, serde_json::error::Error> {
        use serde::ser::SerializeMap;
        use crate::serde_custom::{base64_url_uint, byte_sequence};
        let mut serializer = serde_json::Serializer::new(Vec::new());
        let mut map = serializer.serialize_map(None)?;
        // https://tools.ietf.org/html/rfc7638#section-3.2
        // Write required public key parameters in lexicographic order
        match self {
            AlgorithmParameters::EllipticCurve(params) => {
                map.serialize_entry("crv", &params.curve)?;
                map.serialize_entry("kty", &params.key_type)?;
                map.serialize_entry("x", &byte_sequence::wrap(&params.x))?;
                map.serialize_entry("y", &byte_sequence::wrap(&params.y))?;
            }
            AlgorithmParameters::RSA(params) => {
                map.serialize_entry("e", &base64_url_uint::wrap(&params.e))?;
                map.serialize_entry("kty", &params.key_type)?;
                map.serialize_entry("n", &base64_url_uint::wrap(&params.n))?;
            }
            AlgorithmParameters::OctetKey(params) => {
                map.serialize_entry("k", &byte_sequence::wrap(&params.value))?;
                map.serialize_entry("kty", &params.key_type)?;
            }
            AlgorithmParameters::OctetKeyPair(params) => {
                map.serialize_entry("crv", &params.curve)?;
                map.serialize_entry("kty", &params.key_type)?;
                map.serialize_entry("x", &byte_sequence::wrap(&params.x))?;
            }
        }
        map.end()?;
        let json_u8 = serializer.into_inner();
        Ok(BASE64URL_NOPAD.encode(ring::digest::digest(algorithm.0, &json_u8).as_ref()))
    }
pub fn thumbprint ( & self , algorithm : & ' static crate :: digest :: Algorithm , ) -> Result < String , serde_json :: error :: Error > { use serde :: ser :: SerializeMap ; use crate :: serde_custom :: { base64_url_uint , byte_sequence } ; let mut serializer = serde_json :: Serializer :: new ( Vec :: new ( ) ) ; let mut map = serializer . serialize_map ( None ) ? ; // https://tools.ietf.org/html/rfc7638#section-3.2 // Write required public key parameters in lexicographic order match self { AlgorithmParameters :: EllipticCurve ( params ) => { map . serialize_entry ( " " , & params . curve ) ? ; map . serialize_entry ( " " , & params . key_type ) ? ; map . serialize_entry ( " " , & byte_sequence :: wrap ( & params . x ) ) ? ; map . serialize_entry ( " " , & byte_sequence :: wrap ( & params . y ) ) ? ; } AlgorithmParameters :: RSA ( params ) => { map . serialize_entry ( " " , & base64_url_uint :: wrap ( & params . e ) ) ? ; map . serialize_entry ( " " , & params . key_type ) ? ; map . serialize_entry ( " " , & base64_url_uint :: wrap ( & params . n ) ) ? ; } AlgorithmParameters :: OctetKey ( params ) => { map . serialize_entry ( " " , & byte_sequence :: wrap ( & params . value ) ) ? ; map . serialize_entry ( " " , & params . key_type ) ? ; } AlgorithmParameters :: OctetKeyPair ( params ) => { map . serialize_entry ( " " , & params . curve ) ? ; map . serialize_entry ( " " , & params . key_type ) ? ; map . serialize_entry ( " " , & byte_sequence :: wrap ( & params . x ) ) ? ; } } map . end ( ) ? ; let json_u8 = serializer . into_inner ( ) ; Ok ( BASE64URL_NOPAD . encode ( ring :: digest :: digest ( algorithm . 0 , & json_u8 ) . as_ref ( ) ) ) }
JWK thumbprints are digests for identifying key material.
JWK thumbprints are digests for identifying key material .
&self
algorithm
&'static crate::digest::Algorithm
&self
algorithm
&'static crate::digest::Algorithm