pub fn from_pem(input: impl AsRef<[u8]>) -> Result<Self, JoseError> {
        (|| -> anyhow::Result<Self> {
            let (alg, data) = util::parse_pem(input.as_ref())?;
            let (pkcs8_der, curve) = match alg.as_str() {
                "PRIVATE KEY" => match EcxKeyPair::detect_pkcs8(&data, false) {
                    Some(val) => (data.as_slice(), val),
                    None => {
                        bail!("The Montgomery curve private key must be wrapped by PKCS#8 format.")
                    }
                },
                "X25519 PRIVATE KEY" => match EcxKeyPair::detect_pkcs8(&data, false) {
                    Some(val) if val == EcxCurve::X25519 => (data.as_slice(), val),
                    Some(val) => bail!("The EdDSA curve is mismatched: {}", val.name()),
                    None => {
                        bail!("The Montgomery curve private key must be wrapped by PKCS#8 format.")
                    }
                },
                "X448 PRIVATE KEY" => match EcxKeyPair::detect_pkcs8(&data, false) {
                    Some(val) if val == EcxCurve::X448 => (data.as_slice(), val),
                    Some(val) => bail!("The EdDSA curve is mismatched: {}", val.name()),
                    None => {
                        bail!("The Montgomery curve private key must be wrapped by PKCS#8 format.")
                    }
                },
                alg => bail!("Inappropriate algorithm: {}", alg),
            };

            let private_key = PKey::private_key_from_der(pkcs8_der)?;

            Ok(EcxKeyPair {
                private_key,
                curve,
                algorithm: None,
                key_id: None,
            })
        })()
        .map_err(|err| JoseError::InvalidKeyFormat(err))
    }
/// Create a Montgomery curve key pair from a private key of common or traditinal PEM format.
///
/// Common PEM format is a DER and base64 encoded PKCS#8 PrivateKeyInfo
/// that surrounded by "-----BEGIN/END PRIVATE KEY----".
///
/// Traditional PEM format is a DER and base64 encoded PKCS#8 PrivateKeyInfo
/// that surrounded by "-----BEGIN/END ED25519/ED448 PRIVATE KEY----".
///
/// # Arguments
/// * `input` - A private key of common or traditinal PEM format.
Create a Montgomery curve key pair from a private key of common or traditinal PEM format.
Common PEM format is a DER and base64 encoded PKCS#8 PrivateKeyInfo
that surrounded by "BEGIN/END PRIVATE KEY----".


Create a Montgomery curve key pair from a private key of common or traditinal PEM format . Common PEM format is a DER and base64 encoded PKCS#8 PrivateKeyInfo that surrounded by " BEGIN / END PRIVATE KEY ---- " .
pub fn from_pem(input: impl AsRef<[u8]>) -> Result<Self, JoseError> {
        (|| -> anyhow::Result<Self> {
            let (alg, data) = util::parse_pem(input.as_ref())?;
            let (pkcs8_der, curve) = match alg.as_str() {
                "PRIVATE KEY" => match EcxKeyPair::detect_pkcs8(&data, false) {
                    Some(val) => (data.as_slice(), val),
                    None => {
                        bail!("The Montgomery curve private key must be wrapped by PKCS#8 format.")
                    }
                },
                "X25519 PRIVATE KEY" => match EcxKeyPair::detect_pkcs8(&data, false) {
                    Some(val) if val == EcxCurve::X25519 => (data.as_slice(), val),
                    Some(val) => bail!("The EdDSA curve is mismatched: {}", val.name()),
                    None => {
                        bail!("The Montgomery curve private key must be wrapped by PKCS#8 format.")
                    }
                },
                "X448 PRIVATE KEY" => match EcxKeyPair::detect_pkcs8(&data, false) {
                    Some(val) if val == EcxCurve::X448 => (data.as_slice(), val),
                    Some(val) => bail!("The EdDSA curve is mismatched: {}", val.name()),
                    None => {
                        bail!("The Montgomery curve private key must be wrapped by PKCS#8 format.")
                    }
                },
                alg => bail!("Inappropriate algorithm: {}", alg),
            };
            let private_key = PKey::private_key_from_der(pkcs8_der)?;
            Ok(EcxKeyPair {
                private_key,
                curve,
                algorithm: None,
                key_id: None,
            })
        })()
        .map_err(|err| JoseError::InvalidKeyFormat(err))
    }
pub fn from_pem ( input : impl AsRef < [ u8 ] > ) -> Result < Self , JoseError > { ( | | -> anyhow :: Result < Self > { let ( alg , data ) = util :: parse_pem ( input . as_ref ( ) ) ? ; let ( pkcs8_der , curve ) = match alg . as_str ( ) { " " => match EcxKeyPair :: detect_pkcs8 ( & data , false ) { Some ( val ) => ( data . as_slice ( ) , val ) , None => { bail ! ( " " ) } } , " " => match EcxKeyPair :: detect_pkcs8 ( & data , false ) { Some ( val ) if val == EcxCurve :: X25519 => ( data . as_slice ( ) , val ) , Some ( val ) => bail ! ( " " val name ( ) ) , None => { bail ! ( " " ) } } , " " => match EcxKeyPair :: detect_pkcs8 ( & data , false ) { Some ( val ) if val == EcxCurve :: X448 => ( data . as_slice ( ) , val ) , Some ( val ) => bail ! ( " " val name ( ) ) , None => { bail ! ( " " ) } } , alg => bail ! ( " " alg ) , } ; let private_key = PKey :: private_key_from_der ( pkcs8_der ) ? ; Ok ( EcxKeyPair { private_key , curve , algorithm : None , key_id : None , } ) } ) ( ) . map_err ( | err | JoseError :: InvalidKeyFormat ( err ) ) }
Create a Montgomery curve key pair from a private key of common or traditinal PEM format.
Create a Montgomery curve key pair from a private key of common or traditinal PEM format .
input
impl AsRef<[u8]>
input
impl AsRef<[u8]>