use zeroize::Zeroizing;
use crate::AlgorithmError;
use crypto_core::{AeadAlgorithm, Algorithm, HashAlgorithm, MacAlgorithm};
pub struct AeadParams<'a> {
pub key: &'a [u8],
pub nonce: &'a [u8],
pub aad: &'a [u8],
}
pub struct MacParams<'a> {
pub key: &'a [u8],
}
pub trait SignatureAlgorithm {
const ALG: Algorithm;
fn generate_keypair() -> Result<(Vec<u8>, Zeroizing<Vec<u8>>), AlgorithmError>;
fn sign(secret: &[u8], msg: &[u8]) -> Result<Vec<u8>, AlgorithmError>;
fn verify(public: &[u8], msg: &[u8], sig: &[u8]) -> Result<(), AlgorithmError>;
}
pub trait AeadCipherAlgorithm {
const ALG: AeadAlgorithm;
fn encrypt(params: &AeadParams<'_>, plaintext: &[u8]) -> Result<Vec<u8>, AlgorithmError>;
fn decrypt(
params: &AeadParams<'_>,
ciphertext_with_tag: &[u8],
) -> Result<Zeroizing<Vec<u8>>, AlgorithmError>;
}
pub trait HashDigestAlgorithm {
const ALG: HashAlgorithm;
fn digest(message: &[u8]) -> Result<Vec<u8>, AlgorithmError>;
}
pub trait MacAlgorithmAdapter {
const ALG: MacAlgorithm;
fn authenticate(params: &MacParams<'_>, message: &[u8]) -> Result<Vec<u8>, AlgorithmError>;
fn verify(params: &MacParams<'_>, message: &[u8], tag: &[u8]) -> Result<(), AlgorithmError>;
}