pub fn from_der(
        input: impl AsRef<[u8]>,
        hash: Option<HashAlgorithm>,
        mgf1_hash: Option<HashAlgorithm>,
        salt_len: Option<u8>,
    ) -> Result<Self, JoseError> {
        (|| -> anyhow::Result<Self> {
            let input = input.as_ref();
            let pkcs8_der_vec;
            let (pkcs8_der, hash, mgf1_hash, salt_len) = match Self::detect_pkcs8(input, false) {
                Some((hash2, mgf1_hash2, salt_len2)) => {
                    let hash = match hash {
                        Some(val) if val == hash2 => hash2,
                        Some(_) => bail!("The hash algorithm is mismatched: {}", hash2),
                        None => hash2,
                    };

                    let mgf1_hash = match mgf1_hash {
                        Some(val) if val == mgf1_hash2 => mgf1_hash2,
                        Some(_) => bail!("The MGF1 hash algorithm is mismatched: {}", mgf1_hash2),
                        None => hash2,
                    };

                    let salt_len = match salt_len {
                        Some(val) if val == salt_len2 => salt_len2,
                        Some(_) => bail!("The salt length is mismatched: {}", salt_len2),
                        None => salt_len2,
                    };

                    (input, hash, mgf1_hash, salt_len)
                }
                None => {
                    let hash = match hash {
                        Some(val) => val,
                        None => bail!("The hash algorithm is required."),
                    };

                    let mgf1_hash = match mgf1_hash {
                        Some(val) => val,
                        None => bail!("The MGF1 hash algorithm is required."),
                    };

                    let salt_len = match salt_len {
                        Some(val) => val,
                        None => bail!("The salt length is required."),
                    };

                    let rsa_der_vec;
                    let rsa_der = match RsaKeyPair::detect_pkcs8(input, false) {
                        Some(_) => {
                            let key_pair = RsaKeyPair::from_der(input)?;
                            rsa_der_vec = key_pair.to_raw_private_key();
                            &rsa_der_vec
                        }
                        None => input,
                    };

                    pkcs8_der_vec = Self::to_pkcs8(rsa_der, false, hash, mgf1_hash, salt_len);
                    (pkcs8_der_vec.as_slice(), hash, mgf1_hash, salt_len)
                }
            };

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

            Ok(RsaPssKeyPair {
                private_key,
                key_len,
                hash,
                mgf1_hash,
                salt_len,
                algorithm: None,
                key_id: None,
            })
        })()
        .map_err(|err| match err.downcast::<JoseError>() {
            Ok(err) => err,
            Err(err) => JoseError::InvalidKeyFormat(err),
        })
    }
/// Create a RSA-PSS key pair from a private key that is a DER encoded PKCS#8 PrivateKeyInfo or PKCS#1 RSAPrivateKey.
///
/// # Arguments
/// * `input` - A private key that is a DER encoded PKCS#8 PrivateKeyInfo or PKCS#1 RSAPrivateKey.
/// * `hash` A hash algorithm for signing
/// * `mgf1_hash` A hash algorithm for MGF1
/// * `salt_len` A salt length
Create a RSA-PSS key pair from a private key that is a DER encoded PKCS#8 PrivateKeyInfo or PKCS#1 RSAPrivateKey.
Create a RSA - PSS key pair from a private key that is a DER encoded PKCS#8 PrivateKeyInfo or PKCS#1 RSAPrivateKey .
pub fn from_der(
        input: impl AsRef<[u8]>,
        hash: Option<HashAlgorithm>,
        mgf1_hash: Option<HashAlgorithm>,
        salt_len: Option<u8>,
    ) -> Result<Self, JoseError> {
        (|| -> anyhow::Result<Self> {
            let input = input.as_ref();
            let pkcs8_der_vec;
            let (pkcs8_der, hash, mgf1_hash, salt_len) = match Self::detect_pkcs8(input, false) {
                Some((hash2, mgf1_hash2, salt_len2)) => {
                    let hash = match hash {
                        Some(val) if val == hash2 => hash2,
                        Some(_) => bail!("The hash algorithm is mismatched: {}", hash2),
                        None => hash2,
                    };
                    let mgf1_hash = match mgf1_hash {
                        Some(val) if val == mgf1_hash2 => mgf1_hash2,
                        Some(_) => bail!("The MGF1 hash algorithm is mismatched: {}", mgf1_hash2),
                        None => hash2,
                    };
                    let salt_len = match salt_len {
                        Some(val) if val == salt_len2 => salt_len2,
                        Some(_) => bail!("The salt length is mismatched: {}", salt_len2),
                        None => salt_len2,
                    };
                    (input, hash, mgf1_hash, salt_len)
                }
                None => {
                    let hash = match hash {
                        Some(val) => val,
                        None => bail!("The hash algorithm is required."),
                    };
                    let mgf1_hash = match mgf1_hash {
                        Some(val) => val,
                        None => bail!("The MGF1 hash algorithm is required."),
                    };
                    let salt_len = match salt_len {
                        Some(val) => val,
                        None => bail!("The salt length is required."),
                    };
                    let rsa_der_vec;
                    let rsa_der = match RsaKeyPair::detect_pkcs8(input, false) {
                        Some(_) => {
                            let key_pair = RsaKeyPair::from_der(input)?;
                            rsa_der_vec = key_pair.to_raw_private_key();
                            &rsa_der_vec
                        }
                        None => input,
                    };
                    pkcs8_der_vec = Self::to_pkcs8(rsa_der, false, hash, mgf1_hash, salt_len);
                    (pkcs8_der_vec.as_slice(), hash, mgf1_hash, salt_len)
                }
            };
            let private_key = PKey::private_key_from_der(pkcs8_der)?;
            let rsa = private_key.rsa()?;
            let key_len = rsa.size();
            Ok(RsaPssKeyPair {
                private_key,
                key_len,
                hash,
                mgf1_hash,
                salt_len,
                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 ] > , hash : Option < HashAlgorithm > , mgf1_hash : Option < HashAlgorithm > , salt_len : Option < u8 > , ) -> Result < Self , JoseError > { ( | | -> anyhow :: Result < Self > { let input = input . as_ref ( ) ; let pkcs8_der_vec ; let ( pkcs8_der , hash , mgf1_hash , salt_len ) = match Self :: detect_pkcs8 ( input , false ) { Some ( ( hash2 , mgf1_hash2 , salt_len2 ) ) => { let hash = match hash { Some ( val ) if val == hash2 => hash2 , Some ( _ ) => bail ! ( " " hash2 ) , None => hash2 , } ; let mgf1_hash = match mgf1_hash { Some ( val ) if val == mgf1_hash2 => mgf1_hash2 , Some ( _ ) => bail ! ( " " mgf1_hash2 ) , None => hash2 , } ; let salt_len = match salt_len { Some ( val ) if val == salt_len2 => salt_len2 , Some ( _ ) => bail ! ( " " salt_len2 ) , None => salt_len2 , } ; ( input , hash , mgf1_hash , salt_len ) } None => { let hash = match hash { Some ( val ) => val , None => bail ! ( " " ) , } ; let mgf1_hash = match mgf1_hash { Some ( val ) => val , None => bail ! ( " " ) , } ; let salt_len = match salt_len { Some ( val ) => val , None => bail ! ( " " ) , } ; let rsa_der_vec ; let rsa_der = match RsaKeyPair :: detect_pkcs8 ( input , false ) { Some ( _ ) => { let key_pair = RsaKeyPair :: from_der ( input ) ? ; rsa_der_vec = key_pair . to_raw_private_key ( ) ; & rsa_der_vec } None => input , } ; pkcs8_der_vec = Self :: to_pkcs8 ( rsa_der , false , hash , mgf1_hash , salt_len ) ; ( pkcs8_der_vec . as_slice ( ) , hash , mgf1_hash , salt_len ) } } ; let private_key = PKey :: private_key_from_der ( pkcs8_der ) ? ; let rsa = private_key . rsa ( ) ? ; let key_len = rsa . size ( ) ; Ok ( RsaPssKeyPair { private_key , key_len , hash , mgf1_hash , salt_len , algorithm : None , key_id : None , } ) } ) ( ) . map_err ( | err | match err . downcast :: < JoseError > ( ) { Ok ( err ) => err , Err ( err ) => JoseError :: InvalidKeyFormat ( err ) , } ) }
Create a RSA-PSS key pair from a private key that is a DER encoded PKCS#8 PrivateKeyInfo or PKCS#1 RSAPrivateKey.
Create a RSA - PSS key pair from a private key that is a DER encoded PKCS#8 PrivateKeyInfo or PKCS#1 RSAPrivateKey .
input
impl AsRef<[u8]>
hash
Option<HashAlgorithm>
mgf1_hash
Option<HashAlgorithm>
salt_len
Option<u8>
input
impl AsRef<[u8]>
hash
Option<HashAlgorithm>
mgf1_hash
Option<HashAlgorithm>
salt_len
Option<u8>