pub trait SignatureVerifier {
// Required method
fn verify_signature(
&self,
algorithm: AlgorithmIdentifierRef<'_>,
issuer_spki: SubjectPublicKeyInfoRef<'_>,
message: &[u8],
signature: &[u8],
) -> Result<(), VerificationError>;
}Expand description
Pluggable signature verification backend.
Implement this trait to provide algorithm-specific signature verification.
The trait is OID-dispatched: the algorithm argument carries the OID and
any parameters from the certificate’s signatureAlgorithm field.
This trait is object-safe and can be used as dyn SignatureVerifier.
All method arguments are either &self or borrows, so no Sized bound
is implied.
§Implementing a custom backend
use der::asn1::ObjectIdentifier;
const MY_RSA_OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.2.840.113549.1.1.11");
const MY_ECDSA_OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.2.840.10045.4.3.2");
struct MyVerifier;
impl pkix_path::SignatureVerifier for MyVerifier {
fn verify_signature(
&self,
algorithm: spki::AlgorithmIdentifierRef<'_>,
_issuer_spki: spki::SubjectPublicKeyInfoRef<'_>,
_message: &[u8],
_signature: &[u8],
) -> Result<(), pkix_path::VerificationError> {
match algorithm.oid {
MY_RSA_OID => { Ok(()) /* RSA verification */ }
MY_ECDSA_OID => { Ok(()) /* ECDSA verification */ }
_ => Err(pkix_path::VerificationError::unsupported_algorithm()),
}
}
}Required Methods§
Sourcefn verify_signature(
&self,
algorithm: AlgorithmIdentifierRef<'_>,
issuer_spki: SubjectPublicKeyInfoRef<'_>,
message: &[u8],
signature: &[u8],
) -> Result<(), VerificationError>
fn verify_signature( &self, algorithm: AlgorithmIdentifierRef<'_>, issuer_spki: SubjectPublicKeyInfoRef<'_>, message: &[u8], signature: &[u8], ) -> Result<(), VerificationError>
Verify signature over message.
algorithm— from the subject cert’ssignatureAlgorithmfieldissuer_spki— SPKI extracted from the issuer or trust anchor certmessage— DER-encodedTBSCertificate(the bytes that were signed)signature— raw signature bytes (BitStringcontent, not the wrapper)
Returns Ok(()) when the signature verifies. The caller
(validate_path) adds the chain index: an error of kind
VerificationErrorKind::InvalidSignature becomes
Error::SignatureInvalid, any other kind
Error::SignatureNotVerified — the verifier does not need to know
the index.
§Errors
Returns a VerificationError whose kind says why the signature
was not accepted: the algorithm is not supported
(UnsupportedAlgorithm),
the issuer key is unsupported or does not fit the algorithm
(UnsupportedKey) or does
not decode (MalformedKey),
or the signature is malformed or does not verify
(InvalidSignature).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<T: SignatureVerifier + ?Sized> SignatureVerifier for &T
Forwarding impl so a shared reference to a verifier is itself a
verifier.
impl<T: SignatureVerifier + ?Sized> SignatureVerifier for &T
Forwarding impl so a shared reference to a verifier is itself a verifier.
This is what makes a verifier that cannot be Clone usable.
crate::validate_path and the CrlChecker / OcspChecker types in
pkix-revocation take a verifier by value and require Clone, since
they hold it and may be cloned themselves. A verifier that owns a
hardware token handle, an open session, or anything else not
duplicable therefore could not be used at all.
With this impl it can: pass &verifier and the type parameter
becomes &V, which is Copy, so the Clone bound is satisfied for
free and nothing is duplicated. The borrow is the only cost, and it
is what a scoped validation wants anyway.
For a verifier shared by something outliving a borrow — a fetcher
held for the life of a process — use the Arc impl below instead.
fn verify_signature( &self, algorithm: AlgorithmIdentifierRef<'_>, issuer_spki: SubjectPublicKeyInfoRef<'_>, message: &[u8], signature: &[u8], ) -> Result<(), VerificationError>
Source§impl<T: SignatureVerifier + ?Sized> SignatureVerifier for Arc<T>
Available on crate feature std only.Forwarding impl so an Arc-shared verifier is itself a verifier.
impl<T: SignatureVerifier + ?Sized> SignatureVerifier for Arc<T>
std only.Forwarding impl so an Arc-shared verifier is itself a verifier.
The owned counterpart to the &T impl above, for a verifier that has
to outlive any particular borrow. Arc<V> is Clone whatever V is,
and cloning it is a refcount bump rather than a duplication of
whatever the verifier holds.
§Why this is gated on std
Arc lives in alloc::sync, which exists only on targets with
atomic compare-and-swap. Implementing it unconditionally would make
this crate stop compiling for a no_std target without atomics
(thumbv6m-none-eabi, for instance) in exchange for a convenience.
Under std those atomics are guaranteed, so the impl is free there.
A no_std consumer that does have atomics and wants this shape can
write the same four-line forwarding impl over its own newtype.
fn verify_signature( &self, algorithm: AlgorithmIdentifierRef<'_>, issuer_spki: SubjectPublicKeyInfoRef<'_>, message: &[u8], signature: &[u8], ) -> Result<(), VerificationError>
Implementors§
impl SignatureVerifier for DefaultVerifier
ed25519 or p256 or p384 or p521 or rsa only.impl SignatureVerifier for EcdsaP256Verifier
p256 only.impl SignatureVerifier for EcdsaP384Verifier
p384 only.impl SignatureVerifier for EcdsaP521Verifier
p521 only.impl SignatureVerifier for Ed25519Verifier
ed25519 only.impl SignatureVerifier for RsaPkcs1v15Sha256Verifier
rsa only.impl SignatureVerifier for RsaPkcs1v15Sha384Verifier
rsa only.impl SignatureVerifier for RsaPkcs1v15Sha512Verifier
rsa only.impl SignatureVerifier for RsaPssVerifier
rsa only.