#![doc = include_str!("../README.md")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg",
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg"
)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![forbid(unsafe_code)]
#![warn(
missing_docs,
rust_2018_idioms,
unused_qualifications,
missing_debug_implementations
)]
pub use signature::{self, Error};
#[cfg(feature = "digest")]
pub use signature::digest::{self, Digest};
#[cfg(feature = "rand_core")]
use signature::rand_core::CryptoRngCore;
#[allow(async_fn_in_trait)]
pub trait AsyncSigner<S> {
async fn sign_async(&self, msg: &[u8]) -> Result<S, Error>;
}
impl<S, T> AsyncSigner<S> for T
where
T: signature::Signer<S>,
{
async fn sign_async(&self, msg: &[u8]) -> Result<S, Error> {
self.try_sign(msg)
}
}
#[cfg(feature = "digest")]
#[allow(async_fn_in_trait)]
pub trait AsyncDigestSigner<D, S>
where
D: Digest,
{
async fn sign_digest_async(&self, digest: D) -> Result<S, Error>;
}
#[cfg(feature = "digest")]
impl<D, S, T> AsyncDigestSigner<D, S> for T
where
D: Digest,
T: signature::DigestSigner<D, S>,
{
async fn sign_digest_async(&self, digest: D) -> Result<S, Error> {
self.try_sign_digest(digest)
}
}
#[cfg(feature = "rand_core")]
#[allow(async_fn_in_trait)]
pub trait AsyncRandomizedSigner<S> {
async fn sign_with_rng_async(&self, rng: &mut impl CryptoRngCore, msg: &[u8]) -> S {
self.try_sign_with_rng_async(rng, msg)
.await
.expect("signature operation failed")
}
async fn try_sign_with_rng_async(
&self,
rng: &mut impl CryptoRngCore,
msg: &[u8],
) -> Result<S, Error>;
}
#[cfg(feature = "rand_core")]
impl<S, T> AsyncRandomizedSigner<S> for T
where
T: signature::RandomizedSigner<S>,
{
async fn try_sign_with_rng_async(
&self,
rng: &mut impl CryptoRngCore,
msg: &[u8],
) -> Result<S, Error> {
self.try_sign_with_rng(rng, msg)
}
}