1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#![cfg_attr(docsrs, feature(doc_cfg))]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg",
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg",
html_root_url = "https://docs.rs/async-signature/0.0.1"
)]
#![forbid(unsafe_code)]
#![warn(missing_docs, rust_2018_idioms, unused_qualifications)]
pub use signature::{self, Error, Signature};
#[cfg(feature = "digest")]
pub use signature::digest::{self, Digest};
use async_trait::async_trait;
#[async_trait]
pub trait AsyncSigner<S>
where
Self: Send + Sync,
S: Signature + Send + 'static,
{
async fn sign_async(&self, msg: &[u8]) -> Result<S, Error>;
}
#[async_trait]
impl<S, T> AsyncSigner<S> for T
where
S: Signature + Send + 'static,
T: signature::Signer<S> + Send + Sync,
{
async fn sign_async(&self, msg: &[u8]) -> Result<S, Error> {
self.try_sign(msg)
}
}
#[cfg(feature = "digest")]
#[cfg_attr(docsrs, doc(cfg(feature = "digest")))]
#[async_trait]
pub trait AsyncDigestSigner<D, S>
where
Self: Send + Sync,
D: Digest + Send + 'static,
S: Signature + 'static,
{
async fn sign_digest_async(&self, digest: D) -> Result<S, Error>;
}
#[cfg(feature = "digest")]
#[async_trait]
impl<D, S, T> AsyncDigestSigner<D, S> for T
where
D: Digest + Send + 'static,
S: Signature + Send + 'static,
T: signature::DigestSigner<D, S> + Send + Sync,
{
async fn sign_digest_async(&self, digest: D) -> Result<S, Error> {
self.try_sign_digest(digest)
}
}