diff --git a/signature/src/verifier.rs b/signature/src/verifier.rs index 0d17163e3..71fc85615 100644 --- a/signature/src/verifier.rs +++ b/signature/src/verifier.rs @@ -55,3 +55,58 @@ pub trait DigestVerifier { signature: &S, ) -> Result<(), Error>; } + +/// Asynchronously verify the provided message bytestring using `Self`. +/// +/// This trait is an async equivalent of the [`Verifier`] trait. +pub trait AsyncVerifier { + /// Asynchronously verify that the provided signature for a given message + /// bytestring is authentic. + /// + /// Returns `Error` if it is inauthentic, or otherwise returns `()`. + async fn verify_async(&self, msg: &[u8], signature: &S) -> Result<(), Error>; +} + +impl AsyncVerifier for T +where + T: Verifier, +{ + async fn verify_async(&self, msg: &[u8], signature: &S) -> Result<(), Error> { + self.verify(msg, signature) + } +} + +/// Asynchronous equivalent of [`MultipartVerifier`] where the message is +/// provided in non-contiguous byte slices. +/// +/// This trait is an async equivalent of the [`MultipartVerifier`] trait. +pub trait AsyncMultipartVerifier { + /// Async equivalent of [`MultipartVerifier::multipart_verify()`] where the + /// message is provided in non-contiguous byte slices. + async fn multipart_verify_async(&self, msg: &[&[u8]], signature: &S) -> Result<(), Error>; +} + +impl AsyncMultipartVerifier for T +where + T: MultipartVerifier, +{ + async fn multipart_verify_async(&self, msg: &[&[u8]], signature: &S) -> Result<(), Error> { + self.multipart_verify(msg, signature) + } +} + +/// Asynchronously verify the provided signature for the given prehashed +/// message `Digest` is authentic. +#[cfg(feature = "digest")] +pub trait AsyncDigestVerifier { + /// Asynchronously verify the signature against the received `Digest` + /// output, by updating it with the message. + /// + /// The given function can be invoked multiple times. It is expected that + /// in each invocation the `Digest` is updated with the entire equal message. + async fn verify_digest_async Result<(), Error>>( + &self, + f: F, + signature: &S, + ) -> Result<(), Error>; +}