/// Create a new secp256r1 keypair. This function should only be used for
/// testing.
///
/// # Errors
/// * `AlgorithmNotSupported` if an error occurs while generating the key
/// # Returns
/// A tuple of the secret key bytes and public key bytes
Create a new secp256r1 keypair. This function should only be used for
testing.
Create a new secp256r1 keypair . This function should only be used for testing .
pub fn new_keypair() -> CryptoResult<(types::SecretKeyBytes, types::PublicKeyBytes)> {
    let group = EcGroup::from_curve_name(CURVE_NAME)
        .map_err(|e| wrap_openssl_err(e, "unable to create EC group"))?;
    let ec_key =
        EcKey::generate(&group).map_err(|e| wrap_openssl_err(e, "unable to generate EC key"))?;
    let mut ctx =
        BigNumContext::new().map_err(|e| wrap_openssl_err(e, "unable to create BigNumContext"))?;
    let mut sk_der =
        ec_key
            .private_key_to_der()
            .map_err(|e| CryptoError::AlgorithmNotSupported {
                algorithm: AlgorithmId::EcdsaP256,
                reason: format!("OpenSSL failed with error {}", e.to_string()),
            })?;
    let sk = types::SecretKeyBytes(SecretVec::new_and_zeroize_argument(&mut sk_der));
    let pk_bytes = ec_key
        .public_key()
        .to_bytes(
            &group,
            openssl::ec::PointConversionForm::UNCOMPRESSED,
            &mut ctx,
        )
        .map_err(|e| wrap_openssl_err(e, "unable to serialize EC public key"))?;
    let pk = types::PublicKeyBytes::from(pk_bytes);
    Ok((sk, pk))
}
pub fn new_keypair ( ) -> CryptoResult < ( types :: SecretKeyBytes , types :: PublicKeyBytes ) > { let group = EcGroup :: from_curve_name ( CURVE_NAME ) . map_err ( | e | wrap_openssl_err ( e , " " ) ) ? ; let ec_key = EcKey :: generate ( & group ) . map_err ( | e | wrap_openssl_err ( e , " " ) ) ? ; let mut ctx = BigNumContext :: new ( ) . map_err ( | e | wrap_openssl_err ( e , " " ) ) ? ; let mut sk_der = ec_key . private_key_to_der ( ) . map_err ( | e | CryptoError :: AlgorithmNotSupported { algorithm : AlgorithmId :: EcdsaP256 , reason : format ! ( " " e to_string ( ) ) , } ) ? ; let sk = types :: SecretKeyBytes ( SecretVec :: new_and_zeroize_argument ( & mut sk_der ) ) ; let pk_bytes = ec_key . public_key ( ) . to_bytes ( & group , openssl :: ec :: PointConversionForm :: UNCOMPRESSED , & mut ctx , ) . map_err ( | e | wrap_openssl_err ( e , " " ) ) ? ; let pk = types :: PublicKeyBytes :: from ( pk_bytes ) ; Ok ( ( sk , pk ) ) }
Create a new secp256r1 keypair.
Create a new secp256r1 keypair .
A tuple of the secret key bytes and public key bytes
A tuple of the secret key bytes and public key bytes
errors
`AlgorithmNotSupported` if an error occurs while generating the key
` AlgorithmNotSupported ` if an error occurs while generating the key