pub fn try_from_basic<T>(&self, signature: &BasicSigOf<T>) -> CryptoResult<CspSignature> {
        match self.target_algorithm {
            AlgorithmId::Ed25519 => {
                const SIG_LEN: usize = ed25519_types::SignatureBytes::SIZE;
                let sig_bytes = &signature.get_ref().0;

                if sig_bytes.len() != SIG_LEN {
                    return Err(CryptoError::MalformedSignature {
                        algorithm: AlgorithmId::Ed25519,
                        sig_bytes: sig_bytes.to_vec(),
                        internal_error: format!(
                            "Invalid length: Expected Ed25519 signature with {} bytes but got {} bytes",
                            SIG_LEN,
                            sig_bytes.len()
                        ),
                    });
                }
                let mut bytes: [u8; SIG_LEN] = [0; SIG_LEN];
                bytes.copy_from_slice(&sig_bytes[0..SIG_LEN]);
                Ok(CspSignature::Ed25519(ed25519_types::SignatureBytes(bytes)))
            }
            AlgorithmId::EcdsaP256 => {
                const SIG_LEN: usize = ecdsa_types::SignatureBytes::SIZE;
                let sig_bytes = &signature.get_ref().0;

                if sig_bytes.len() != SIG_LEN {
                    return Err(CryptoError::MalformedSignature {
                        algorithm: AlgorithmId::EcdsaP256,
                        sig_bytes: sig_bytes.to_vec(),
                        internal_error: format!(
                            "Invalid length: Expected ECDSA-P256 signature with {} bytes but got {} bytes",
                            SIG_LEN,
                            sig_bytes.len()
                        ),
                    });
                }
                let mut bytes: [u8; SIG_LEN] = [0; SIG_LEN];
                bytes.copy_from_slice(&sig_bytes[0..SIG_LEN]);
                Ok(CspSignature::EcdsaP256(ecdsa_types::SignatureBytes(bytes)))
            }
            AlgorithmId::EcdsaSecp256k1 => {
                const SIG_LEN: usize = ecdsa_types::SignatureBytes::SIZE;
                let sig_bytes = &signature.get_ref().0;

                if sig_bytes.len() != SIG_LEN {
                    return Err(CryptoError::MalformedSignature {
                        algorithm: AlgorithmId::EcdsaSecp256k1,
                        sig_bytes: sig_bytes.to_vec(),
                        internal_error: format!(
                            "Invalid length: Expected ECDSA-SECP256k1 signature with {} bytes but got {} bytes",
                            SIG_LEN,
                            sig_bytes.len()
                        ),
                    });
                }
                let mut bytes: [u8; SIG_LEN] = [0; SIG_LEN];
                bytes.copy_from_slice(&sig_bytes[0..SIG_LEN]);
                Ok(CspSignature::EcdsaSecp256k1(
                    secp256k1_types::SignatureBytes(bytes),
                ))
            }
            AlgorithmId::RsaSha256 => {
                let sig_bytes = &signature.get_ref().0;
                Ok(CspSignature::RsaSha256(sig_bytes.clone()))
            }
            algorithm => Err(CryptoError::AlgorithmNotSupported {
                algorithm,
                reason: "Expecting Ed25519 or ECDSA-P256 signature".to_string(),
            }),
        }
    }
/// Convert from a BasicSigOf to a CspSignature
Convert from a BasicSigOf to a CspSignature
Convert from a BasicSigOf to a CspSignature
pub fn try_from_basic<T>(&self, signature: &BasicSigOf<T>) -> CryptoResult<CspSignature> {
        match self.target_algorithm {
            AlgorithmId::Ed25519 => {
                const SIG_LEN: usize = ed25519_types::SignatureBytes::SIZE;
                let sig_bytes = &signature.get_ref().0;
                if sig_bytes.len() != SIG_LEN {
                    return Err(CryptoError::MalformedSignature {
                        algorithm: AlgorithmId::Ed25519,
                        sig_bytes: sig_bytes.to_vec(),
                        internal_error: format!(
                            "Invalid length: Expected Ed25519 signature with {} bytes but got {} bytes",
                            SIG_LEN,
                            sig_bytes.len()
                        ),
                    });
                }
                let mut bytes: [u8; SIG_LEN] = [0; SIG_LEN];
                bytes.copy_from_slice(&sig_bytes[0..SIG_LEN]);
                Ok(CspSignature::Ed25519(ed25519_types::SignatureBytes(bytes)))
            }
            AlgorithmId::EcdsaP256 => {
                const SIG_LEN: usize = ecdsa_types::SignatureBytes::SIZE;
                let sig_bytes = &signature.get_ref().0;
                if sig_bytes.len() != SIG_LEN {
                    return Err(CryptoError::MalformedSignature {
                        algorithm: AlgorithmId::EcdsaP256,
                        sig_bytes: sig_bytes.to_vec(),
                        internal_error: format!(
                            "Invalid length: Expected ECDSA-P256 signature with {} bytes but got {} bytes",
                            SIG_LEN,
                            sig_bytes.len()
                        ),
                    });
                }
                let mut bytes: [u8; SIG_LEN] = [0; SIG_LEN];
                bytes.copy_from_slice(&sig_bytes[0..SIG_LEN]);
                Ok(CspSignature::EcdsaP256(ecdsa_types::SignatureBytes(bytes)))
            }
            AlgorithmId::EcdsaSecp256k1 => {
                const SIG_LEN: usize = ecdsa_types::SignatureBytes::SIZE;
                let sig_bytes = &signature.get_ref().0;
                if sig_bytes.len() != SIG_LEN {
                    return Err(CryptoError::MalformedSignature {
                        algorithm: AlgorithmId::EcdsaSecp256k1,
                        sig_bytes: sig_bytes.to_vec(),
                        internal_error: format!(
                            "Invalid length: Expected ECDSA-SECP256k1 signature with {} bytes but got {} bytes",
                            SIG_LEN,
                            sig_bytes.len()
                        ),
                    });
                }
                let mut bytes: [u8; SIG_LEN] = [0; SIG_LEN];
                bytes.copy_from_slice(&sig_bytes[0..SIG_LEN]);
                Ok(CspSignature::EcdsaSecp256k1(
                    secp256k1_types::SignatureBytes(bytes),
                ))
            }
            AlgorithmId::RsaSha256 => {
                let sig_bytes = &signature.get_ref().0;
                Ok(CspSignature::RsaSha256(sig_bytes.clone()))
            }
            algorithm => Err(CryptoError::AlgorithmNotSupported {
                algorithm,
                reason: "Expecting Ed25519 or ECDSA-P256 signature".to_string(),
            }),
        }
    }
pub fn try_from_basic < T > ( & self , signature : & BasicSigOf < T > ) -> CryptoResult < CspSignature > { match self . target_algorithm { AlgorithmId :: Ed25519 => { const SIG_LEN : usize = ed25519_types :: SignatureBytes :: SIZE ; let sig_bytes = & signature . get_ref ( ) . 0 ; if sig_bytes . len ( ) != SIG_LEN { return Err ( CryptoError :: MalformedSignature { algorithm : AlgorithmId :: Ed25519 , sig_bytes : sig_bytes . to_vec ( ) , internal_error : format ! ( " " SIG_LEN sig_bytes len ( ) ) , } ) ; } let mut bytes : [ u8 ; SIG_LEN ] = [ 0 ; SIG_LEN ] ; bytes . copy_from_slice ( & sig_bytes [ 0 .. SIG_LEN ] ) ; Ok ( CspSignature :: Ed25519 ( ed25519_types :: SignatureBytes ( bytes ) ) ) } AlgorithmId :: EcdsaP256 => { const SIG_LEN : usize = ecdsa_types :: SignatureBytes :: SIZE ; let sig_bytes = & signature . get_ref ( ) . 0 ; if sig_bytes . len ( ) != SIG_LEN { return Err ( CryptoError :: MalformedSignature { algorithm : AlgorithmId :: EcdsaP256 , sig_bytes : sig_bytes . to_vec ( ) , internal_error : format ! ( " " SIG_LEN sig_bytes len ( ) ) , } ) ; } let mut bytes : [ u8 ; SIG_LEN ] = [ 0 ; SIG_LEN ] ; bytes . copy_from_slice ( & sig_bytes [ 0 .. SIG_LEN ] ) ; Ok ( CspSignature :: EcdsaP256 ( ecdsa_types :: SignatureBytes ( bytes ) ) ) } AlgorithmId :: EcdsaSecp256k1 => { const SIG_LEN : usize = ecdsa_types :: SignatureBytes :: SIZE ; let sig_bytes = & signature . get_ref ( ) . 0 ; if sig_bytes . len ( ) != SIG_LEN { return Err ( CryptoError :: MalformedSignature { algorithm : AlgorithmId :: EcdsaSecp256k1 , sig_bytes : sig_bytes . to_vec ( ) , internal_error : format ! ( " " SIG_LEN sig_bytes len ( ) ) , } ) ; } let mut bytes : [ u8 ; SIG_LEN ] = [ 0 ; SIG_LEN ] ; bytes . copy_from_slice ( & sig_bytes [ 0 .. SIG_LEN ] ) ; Ok ( CspSignature :: EcdsaSecp256k1 ( secp256k1_types :: SignatureBytes ( bytes ) , ) ) } AlgorithmId :: RsaSha256 => { let sig_bytes = & signature . get_ref ( ) . 0 ; Ok ( CspSignature :: RsaSha256 ( sig_bytes . clone ( ) ) ) } algorithm => Err ( CryptoError :: AlgorithmNotSupported { algorithm , reason : " " . to_string ( ) , } ) , } }
Convert from a BasicSigOf to a CspSignature
Convert from a BasicSigOf to a CspSignature
&self
signature
&BasicSigOf<T>
&self
signature
&BasicSigOf<T>