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_vec;
            let pkcs8_der = match alg.as_str() {
                "PRIVATE KEY" => match Self::detect_pkcs8(&data, false) {
                    Some(_) => data.as_slice(),
                    None => bail!("Invalid PEM contents."),
                },
                "RSA PRIVATE KEY" => {
                    pkcs8_der_vec = Self::to_pkcs8(&data, false);
                    pkcs8_der_vec.as_slice()
                }
                alg => bail!("Inappropriate algorithm: {}", alg),
            };

            let private_key = PKey::private_key_from_der(&pkcs8_der)?;
            let rsa = private_key.rsa()?;
            let key_len = rsa.size();

            Ok(Self {
                private_key,
                key_len,
                algorithm: None,
                key_id: None,
            })
        })()
        .map_err(|err| JoseError::InvalidKeyFormat(err))
    }
/// Create a RSA 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#1 RSAPrivateKey
/// that surrounded by "-----BEGIN/END RSA PRIVATE KEY----".
///
/// # Arguments
/// * `input` - A private key of common or traditinal PEM format.
Create a RSA 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 RSA 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_vec;
            let pkcs8_der = match alg.as_str() {
                "PRIVATE KEY" => match Self::detect_pkcs8(&data, false) {
                    Some(_) => data.as_slice(),
                    None => bail!("Invalid PEM contents."),
                },
                "RSA PRIVATE KEY" => {
                    pkcs8_der_vec = Self::to_pkcs8(&data, false);
                    pkcs8_der_vec.as_slice()
                }
                alg => bail!("Inappropriate algorithm: {}", alg),
            };
            let private_key = PKey::private_key_from_der(&pkcs8_der)?;
            let rsa = private_key.rsa()?;
            let key_len = rsa.size();
            Ok(Self {
                private_key,
                key_len,
                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_vec ; let pkcs8_der = match alg . as_str ( ) { " " => match Self :: detect_pkcs8 ( & data , false ) { Some ( _ ) => data . as_slice ( ) , None => bail ! ( " " ) , } , " " => { pkcs8_der_vec = Self :: to_pkcs8 ( & data , false ) ; pkcs8_der_vec . as_slice ( ) } alg => bail ! ( " " alg ) , } ; let private_key = PKey :: private_key_from_der ( & pkcs8_der ) ? ; let rsa = private_key . rsa ( ) ? ; let key_len = rsa . size ( ) ; Ok ( Self { private_key , key_len , algorithm : None , key_id : None , } ) } ) ( ) . map_err ( | err | JoseError :: InvalidKeyFormat ( err ) ) }
Create a RSA key pair from a private key of common or traditinal PEM format.
Create a RSA key pair from a private key of common or traditinal PEM format .
input
impl AsRef<[u8]>
input
impl AsRef<[u8]>