use crate::{error::Error, Signature};
#[cfg(feature = "digest-preview")]
use crate::digest::Digest;
#[cfg(feature = "rand-preview")]
use crate::rand_core::{CryptoRng, RngCore};
pub trait Signer<S: Signature> {
fn sign(&self, msg: &[u8]) -> S {
self.try_sign(msg).expect("signature operation failed")
}
fn try_sign(&self, msg: &[u8]) -> Result<S, Error>;
}
#[cfg(feature = "digest-preview")]
#[cfg_attr(docsrs, doc(cfg(feature = "digest-preview")))]
pub trait DigestSigner<D, S>
where
D: Digest,
S: Signature,
{
fn sign_digest(&self, digest: D) -> S {
self.try_sign_digest(digest)
.expect("signature operation failed")
}
fn try_sign_digest(&self, digest: D) -> Result<S, Error>;
}
#[cfg(feature = "rand-preview")]
#[cfg_attr(docsrs, doc(cfg(feature = "rand-preview")))]
pub trait RandomizedSigner<R, S>
where
R: CryptoRng + RngCore,
S: Signature,
{
fn sign_with_rng(&self, rng: &mut R, msg: &[u8]) -> S {
self.try_sign_with_rng(rng, msg)
.expect("signature operation failed")
}
fn try_sign_with_rng(&self, rng: &mut R, msg: &[u8]) -> Result<S, Error>;
}