mirror of
https://github.com/RustCrypto/signatures
synced 2026-06-21 13:45:42 +00:00
Merge pull request #7 from RustCrypto/sign-and-verify-traits
Signing and verification traits
This commit is contained in:
@@ -12,8 +12,9 @@ keywords = ["crypto", "ecdsa", "ed25519", "signature", "signing"]
|
||||
categories = ["cryptography", "no-std"]
|
||||
|
||||
[dependencies]
|
||||
digest = { version = "0.8", optional = true, default-features = false }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
default = ["digest", "std"]
|
||||
alloc = []
|
||||
std = ["alloc"]
|
||||
|
||||
@@ -14,12 +14,17 @@
|
||||
unused_qualifications
|
||||
)]
|
||||
|
||||
#[cfg(feature = "digest")]
|
||||
pub extern crate digest;
|
||||
|
||||
#[cfg(any(feature = "std", test))]
|
||||
#[macro_use]
|
||||
extern crate std;
|
||||
|
||||
mod error;
|
||||
mod prelude;
|
||||
pub mod sign;
|
||||
mod signature;
|
||||
pub mod verify;
|
||||
|
||||
pub use crate::{error::Error, signature::Signature};
|
||||
pub use crate::{error::Error, sign::Sign, signature::Signature, verify::Verify};
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
//! Support for signing messages which have been prehashed messages using
|
||||
//! the `Digest` trait.
|
||||
//!
|
||||
//! For use signature algorithms that support an Initialize-Update-Finalize
|
||||
//! (IUF) API, such as ECDSA or Ed25519ph.
|
||||
|
||||
use crate::{error::Error, Signature};
|
||||
use digest::Digest;
|
||||
|
||||
/// Sign the given prehashed message `Digest` using `Self`.
|
||||
pub trait SignDigest<D, S>: Send + Sync
|
||||
where
|
||||
D: Digest,
|
||||
S: Signature,
|
||||
{
|
||||
/// Sign the given prehashed message `Digest`, returning a signature.
|
||||
fn sign(&self, digest: D) -> Result<S, Error>;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
//! Traits for generating digital signatures
|
||||
|
||||
#[cfg(feature = "digest")]
|
||||
pub(crate) mod digest;
|
||||
|
||||
#[cfg(feature = "digest")]
|
||||
pub use self::digest::SignDigest;
|
||||
use crate::{error::Error, Signature};
|
||||
|
||||
/// Sign the provided message bytestring using `Self` (e.g. a cryptographic key
|
||||
/// or connection to an HSM), returning a digital signature.
|
||||
pub trait Sign<S: Signature>: Send + Sync {
|
||||
/// Sign the given message and return a digital signature
|
||||
fn sign(&self, msg: &[u8]) -> Result<S, Error>;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//! Support for verifying messages which have been prehashed messages using
|
||||
//! the `Digest` trait.
|
||||
//!
|
||||
//! For use signature algorithms that support an Initialize-Update-Finalize
|
||||
//! (IUF) API, such as ECDSA or Ed25519ph.
|
||||
|
||||
use crate::{error::Error, Signature};
|
||||
use digest::Digest;
|
||||
|
||||
/// Verify the provided signature for the given prehashed message `Digest`
|
||||
/// is authentic.
|
||||
pub trait VerifyDigest<D, S>: Send + Sync
|
||||
where
|
||||
D: Digest,
|
||||
S: Signature,
|
||||
{
|
||||
/// Verify the signature against the given `Digest`
|
||||
fn verify(&self, digest: D, signature: &S) -> Result<(), Error>;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
//! Trait for verifying digital signatures
|
||||
|
||||
#[cfg(feature = "digest")]
|
||||
pub(crate) mod digest;
|
||||
|
||||
#[cfg(feature = "digest")]
|
||||
pub use self::digest::VerifyDigest;
|
||||
use crate::{error::Error, Signature};
|
||||
|
||||
/// Verify the provided message bytestring using `Self` (e.g. a public key)
|
||||
pub trait Verify<S: Signature>: Send + Sync {
|
||||
/// Use `Self` to verify that the provided signature for a given message
|
||||
/// bytestring is authentic.
|
||||
///
|
||||
/// Returns `Error` if it is inauthentic, or otherwise returns `()`.
|
||||
fn verify(&self, msg: &[u8], signature: &S) -> Result<(), Error>;
|
||||
}
|
||||
Reference in New Issue
Block a user