pub fn from_der(input: impl AsRef<[u8]>, curve: Option<EcCurve>) -> Result<Self, JoseError> {
        (|| -> anyhow::Result<Self> {
            let input = input.as_ref();
            let pkcs8_der_vec;
            let (pkcs8_der, curve) = match Self::detect_pkcs8(input, false) {
                Some(val) => match curve {
                    Some(val2) if val2 == val => (input, val),
                    Some(val2) => bail!("The curve is mismatched: {}", val2),
                    None => (input, val),
                },
                None => match curve {
                    Some(val) => {
                        pkcs8_der_vec = Self::to_pkcs8(input.as_ref(), false, val);
                        (pkcs8_der_vec.as_slice(), val)
                    }
                    None => bail!("A curve is required for raw format."),
                },
            };

            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 that is a DER encoded PKCS#8 PrivateKeyInfo or ECPrivateKey.
///
/// # Arguments
///
/// * `input` - A private key that is a DER encoded PKCS#8 PrivateKeyInfo or ECPrivateKey.
/// * `curve` - EC curve
Create a EC key pair from a private key that is a DER encoded PKCS#8 PrivateKeyInfo or ECPrivateKey.
Create a EC key pair from a private key that is a DER encoded PKCS#8 PrivateKeyInfo or ECPrivateKey .
pub fn from_der(input: impl AsRef<[u8]>, curve: Option<EcCurve>) -> Result<Self, JoseError> {
        (|| -> anyhow::Result<Self> {
            let input = input.as_ref();
            let pkcs8_der_vec;
            let (pkcs8_der, curve) = match Self::detect_pkcs8(input, false) {
                Some(val) => match curve {
                    Some(val2) if val2 == val => (input, val),
                    Some(val2) => bail!("The curve is mismatched: {}", val2),
                    None => (input, val),
                },
                None => match curve {
                    Some(val) => {
                        pkcs8_der_vec = Self::to_pkcs8(input.as_ref(), false, val);
                        (pkcs8_der_vec.as_slice(), val)
                    }
                    None => bail!("A curve is required for raw format."),
                },
            };
            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_der ( input : impl AsRef < [ u8 ] > , curve : Option < EcCurve > ) -> Result < Self , JoseError > { ( | | -> anyhow :: Result < Self > { let input = input . as_ref ( ) ; let pkcs8_der_vec ; let ( pkcs8_der , curve ) = match Self :: detect_pkcs8 ( input , false ) { Some ( val ) => match curve { Some ( val2 ) if val2 == val => ( input , val ) , Some ( val2 ) => bail ! ( " " val2 ) , None => ( input , val ) , } , None => match curve { Some ( val ) => { pkcs8_der_vec = Self :: to_pkcs8 ( input . as_ref ( ) , false , val ) ; ( pkcs8_der_vec . as_slice ( ) , val ) } None => bail ! ( " " ) , } , } ; 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 that is a DER encoded PKCS#8 PrivateKeyInfo or ECPrivateKey.
Create a EC key pair from a private key that is a DER encoded PKCS#8 PrivateKeyInfo or ECPrivateKey .
input
impl AsRef<[u8]>
curve
Option<EcCurve>
input
impl AsRef<[u8]>
curve
Option<EcCurve>