pub fn from_pem(input: impl AsRef<[u8]>, curve: Option<EcCurve>) -> Result<Self, JoseError> {
        (|| -> anyhow::Result<Self> {
            let (alg, data) = util::parse_pem(input.as_ref())?;

            let pkcs8_der_vec;
            let (pkcs8_der, curve) = match alg.as_str() {
                "PRIVATE KEY" => {
                    let curve = match Self::detect_pkcs8(&data, false) {
                        Some(val) => match curve {
                            Some(val2) if val2 == val => val2,
                            Some(val2) => bail!("The curve is mismatched: {}", val2),
                            None => val,
                        },
                        None => bail!("PEM contents is expected PKCS#8 wrapped key."),
                    };
                    (data.as_slice(), curve)
                }
                "EC PRIVATE KEY" => {
                    let curve = match Self::detect_ec_curve(data.as_slice()) {
                        Some(val) => match curve {
                            Some(val2) if val2 == val => val,
                            Some(val2) => bail!("The curve is mismatched: {}", val2),
                            None => val,
                        },
                        None => match curve {
                            Some(val) => val,
                            None => bail!("A curve name cannot be determined."),
                        },
                    };
                    pkcs8_der_vec = Self::to_pkcs8(&data, false, curve);
                    (pkcs8_der_vec.as_slice(), curve)
                }
                alg => bail!("Inappropriate algorithm: {}", alg),
            };

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

            Ok(EcKeyPair {
                private_key,
                curve,
                algorithm: None,
                key_id: None,
            })
        })()
        .map_err(|err| match err.downcast::<JoseError>() {
            Ok(err) => err,
            Err(err) => JoseError::InvalidKeyFormat(err),
        })
    }
/// Create a Ec 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 ECPrivateKey
/// that surrounded by "-----BEGIN/END EC PRIVATE KEY----".
///
/// # Arguments
///
/// * `input` - A private key of common or traditinal PEM format.
/// * `curve` - EC curve
Create a Ec 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 Ec 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]>, curve: Option<EcCurve>) -> Result<Self, JoseError> {
        (|| -> anyhow::Result<Self> {
            let (alg, data) = util::parse_pem(input.as_ref())?;
            let pkcs8_der_vec;
            let (pkcs8_der, curve) = match alg.as_str() {
                "PRIVATE KEY" => {
                    let curve = match Self::detect_pkcs8(&data, false) {
                        Some(val) => match curve {
                            Some(val2) if val2 == val => val2,
                            Some(val2) => bail!("The curve is mismatched: {}", val2),
                            None => val,
                        },
                        None => bail!("PEM contents is expected PKCS#8 wrapped key."),
                    };
                    (data.as_slice(), curve)
                }
                "EC PRIVATE KEY" => {
                    let curve = match Self::detect_ec_curve(data.as_slice()) {
                        Some(val) => match curve {
                            Some(val2) if val2 == val => val,
                            Some(val2) => bail!("The curve is mismatched: {}", val2),
                            None => val,
                        },
                        None => match curve {
                            Some(val) => val,
                            None => bail!("A curve name cannot be determined."),
                        },
                    };
                    pkcs8_der_vec = Self::to_pkcs8(&data, false, curve);
                    (pkcs8_der_vec.as_slice(), curve)
                }
                alg => bail!("Inappropriate algorithm: {}", alg),
            };
            let private_key = PKey::private_key_from_der(pkcs8_der)?;
            Ok(EcKeyPair {
                private_key,
                curve,
                algorithm: None,
                key_id: None,
            })
        })()
        .map_err(|err| match err.downcast::<JoseError>() {
            Ok(err) => err,
            Err(err) => JoseError::InvalidKeyFormat(err),
        })
    }
pub fn from_pem ( input : impl AsRef < [ u8 ] > , curve : Option < EcCurve > ) -> Result < Self , JoseError > { ( | | -> anyhow :: Result < Self > { let ( alg , data ) = util :: parse_pem ( input . as_ref ( ) ) ? ; let pkcs8_der_vec ; let ( pkcs8_der , curve ) = match alg . as_str ( ) { " " => { let curve = match Self :: detect_pkcs8 ( & data , false ) { Some ( val ) => match curve { Some ( val2 ) if val2 == val => val2 , Some ( val2 ) => bail ! ( " " val2 ) , None => val , } , None => bail ! ( " " ) , } ; ( data . as_slice ( ) , curve ) } " " => { let curve = match Self :: detect_ec_curve ( data . as_slice ( ) ) { Some ( val ) => match curve { Some ( val2 ) if val2 == val => val , Some ( val2 ) => bail ! ( " " val2 ) , None => val , } , None => match curve { Some ( val ) => val , None => bail ! ( " " ) , } , } ; pkcs8_der_vec = Self :: to_pkcs8 ( & data , false , curve ) ; ( pkcs8_der_vec . as_slice ( ) , curve ) } alg => bail ! ( " " alg ) , } ; let private_key = PKey :: private_key_from_der ( pkcs8_der ) ? ; Ok ( EcKeyPair { private_key , curve , algorithm : None , key_id : None , } ) } ) ( ) . map_err ( | err | match err . downcast :: < JoseError > ( ) { Ok ( err ) => err , Err ( err ) => JoseError :: InvalidKeyFormat ( err ) , } ) }
Create a Ec key pair from a private key of common or traditinal PEM format.
Create a Ec key pair from a private key of common or traditinal PEM format .
input
impl AsRef<[u8]>
curve
Option<EcCurve>
input
impl AsRef<[u8]>
curve
Option<EcCurve>