use alloc::vec::Vec;
use crate::algorithms::CryptoAlgorithm;
pub use signature::{
DigestSigner, DigestVerifier, Error as SignatureError, Keypair, RandomizedSigner, Signer, Verifier,
};
pub trait CryptoSigner<S>: CryptoAlgorithm + Signer<S> {
fn has_private_key(&self) -> bool;
}
pub trait CryptoVerifier<S>: CryptoAlgorithm + Verifier<S> {
fn public_key_bytes(&self) -> Vec<u8>;
}
pub trait CryptoKeyPair<S>: CryptoAlgorithm + Keypair + Signer<S> + Clone
where
Self::VerifyingKey: CryptoVerifier<S>,
{
type SigningKey: CryptoSigner<S>;
fn to_public_key(&self) -> Self::VerifyingKey {
self.verifying_key()
}
fn take_private_key(self) -> Self::SigningKey;
}
#[derive(Debug, Copy, Clone, Default)]
pub struct SigningOptions {
pub raw: bool,
pub for_cert: bool,
}
impl SigningOptions {
pub fn raw() -> Self {
Self { raw: true, for_cert: false }
}
pub fn for_cert() -> Self {
Self { raw: false, for_cert: true }
}
}
pub trait CryptoSignerWithOptions<S>: CryptoSigner<S> {
fn sign_with_options<T: AsRef<[u8]>>(&self, message: T, options: SigningOptions) -> Result<S, SignatureError>;
}
pub trait CryptoVerifierWithOptions<S>: CryptoVerifier<S> {
fn verify_with_options<T: AsRef<[u8]>>(
&self,
message: T,
signature: &S,
options: SigningOptions,
) -> Result<(), SignatureError>;
}