pub struct SignerInfo { /* private fields */ }
Expand description
Represents a CMS SignerInfo structure.
This is a high-level interface to the SignerInfo ASN.1 type. It supports performing common operations against that type.
Instances of this type are logically equivalent to a single
signed assertion within a SignedData
payload. There can be multiple
signers per SignedData
, which is why this type exists on its own.
Implementations§
Source§impl SignerInfo
impl SignerInfo
Sourcepub fn certificate_issuer_and_serial(&self) -> Option<(&Name, &Integer)>
pub fn certificate_issuer_and_serial(&self) -> Option<(&Name, &Integer)>
Obtain the signing X.509 certificate’s issuer name and its serial number.
The returned value can be used to locate the certificate so verification can be performed.
Sourcepub fn digest_algorithm(&self) -> DigestAlgorithm
pub fn digest_algorithm(&self) -> DigestAlgorithm
Obtain the message digest algorithm used by this signer.
Sourcepub fn signature_algorithm(&self) -> SignatureAlgorithm
pub fn signature_algorithm(&self) -> SignatureAlgorithm
Obtain the cryptographic signing algorithm used by this signer.
Sourcepub fn signature(&self) -> &[u8] ⓘ
pub fn signature(&self) -> &[u8] ⓘ
Obtain the raw bytes constituting the cryptographic signature.
This is the signature that should be verified.
Sourcepub fn signed_attributes(&self) -> Option<&SignedAttributes>
pub fn signed_attributes(&self) -> Option<&SignedAttributes>
Obtain the SignedAttributes
attached to this instance.
Sourcepub fn unsigned_attributes(&self) -> Option<&UnsignedAttributes>
pub fn unsigned_attributes(&self) -> Option<&UnsignedAttributes>
Obtain the UnsignedAttributes
attached to this instance.
Sourcepub fn verify_signature_with_signed_data(
&self,
signed_data: &SignedData,
) -> Result<(), CmsError>
pub fn verify_signature_with_signed_data( &self, signed_data: &SignedData, ) -> Result<(), CmsError>
Verifies the signature defined by this signer given a SignedData instance.
This function will perform cryptographic verification that the signature
contained within this SignerInfo
instance is valid for the content that
was signed. The content that was signed is the encapsulated content from
the SignedData
instance (its .signed_data()
value) combined with
the SignedAttributes
attached to this instance.
§IMPORTANT SECURITY LIMITATIONS
This method only performs signature verification. It:
- DOES NOT verify the digest hash embedded within
SignedAttributes
(if present). - DOES NOT validate the signing certificate in any way.
- DOES NOT validate that the cryptography used is appropriate.
- DOES NOT verify the time stamp token, if present.
See the crate’s documentation for more on the security implications.
Sourcepub fn verify_signature_with_signed_data_and_content(
&self,
signed_data: &SignedData,
signed_content: &[u8],
) -> Result<(), CmsError>
pub fn verify_signature_with_signed_data_and_content( &self, signed_data: &SignedData, signed_content: &[u8], ) -> Result<(), CmsError>
Verifies the signature defined by this signer given a SignedData and signed content.
This function will perform cryptographic verification that the signature contained within
this SignerInfo is valid for signed_content
. Unlike
Self::verify_signature_with_signed_data(), the content that was signed is passed in
explicitly instead of derived from SignedData.
This is a low-level API that bypasses the normal rules for deriving the raw content a
cryptographic signature was made over. You probably want to use
Self::verify_signature_with_signed_data() instead. Also note that signed_content
here
may or may not be the encapsulated content which is ultimately signed.
This method only performs cryptographic signature verification. It is therefore subject to the same limitations as Self::verify_signature_with_signed_data().
Sourcepub fn verify_message_digest_with_signed_data(
&self,
signed_data: &SignedData,
) -> Result<(), CmsError>
pub fn verify_message_digest_with_signed_data( &self, signed_data: &SignedData, ) -> Result<(), CmsError>
Verifies the digest stored in signed attributes matches that of content in a SignedData
.
If signed attributes are present on this instance, they must contain
a message-digest
attribute defining the digest of data that was
signed. The specification says this digested data should come from
the encapsulated content within SignedData
(SignedData.signed_content()
).
Note that some utilities of CMS will not store a computed digest
in message-digest
that came from SignedData
or is using
the digest algorithm indicated by this SignerInfo
. This is strictly
in violation of the specification but it does occur.
§IMPORTANT SECURITY LIMITATIONS
This method only performs message digest verification. It:
- DOES NOT verify the signature over the signed data or anything about the signer.
- DOES NOT validate that the digest algorithm is strong/appropriate.
- DOES NOT compare the digests in a manner that is immune to timing side-channels.
See the crate’s documentation for more on the security implications.
Sourcepub fn verify_message_digest_with_content(
&self,
data: &[u8],
) -> Result<(), CmsError>
pub fn verify_message_digest_with_content( &self, data: &[u8], ) -> Result<(), CmsError>
Verifies the message digest stored in signed attributes using explicit encapsulated content.
Typically, the digest is computed over content stored in the SignedData instance. However, it is possible for the signed content to be external. This function allows you to define the source of that external content.
Behavior is very similar to SignerInfo::verify_message_digest_with_signed_data except the original content that was digested is explicitly passed in. This content is appended with the signed attributes data on this SignerInfo.
The security limitations from SignerInfo::verify_message_digest_with_signed_data apply to this function as well.
Sourcepub fn signature_verifier<'a, C>(
&self,
certs: C,
) -> Result<UnparsedPublicKey<Vec<u8>>, CmsError>where
C: Iterator<Item = &'a CapturedX509Certificate>,
pub fn signature_verifier<'a, C>(
&self,
certs: C,
) -> Result<UnparsedPublicKey<Vec<u8>>, CmsError>where
C: Iterator<Item = &'a CapturedX509Certificate>,
Obtain an entity for validating the signature described by this instance.
This will attempt to locate the certificate used by this signing info structure in the passed iterable of certificates and then construct a signature verifier that can be used to verify content integrity.
If the certificate referenced by this signing info could not be found, an error occurs.
If the signing key’s algorithm or signature algorithm aren’t supported, an error occurs.
Sourcepub fn time_stamp_token_signed_data(
&self,
) -> Result<Option<SignedData>, CmsError>
pub fn time_stamp_token_signed_data( &self, ) -> Result<Option<SignedData>, CmsError>
Resolve the time-stamp token SignedData for this signer.
The time-stamp token is a SignedData ASN.1 structure embedded as an unsigned attribute. This is a convenience method to extract it and turn it into a SignedData.
Returns Ok(Some)
on success, Ok(None)
if there is no time-stamp token,
and Err
if there is a parsing error.
Sourcepub fn verify_time_stamp_token(&self) -> Result<Option<()>, CmsError>
pub fn verify_time_stamp_token(&self) -> Result<Option<()>, CmsError>
Verify the time-stamp token in this instance.
The time-stamp token is a SignedData ASN.1 structure embedded as an unsigned attribute. So this method reconstructs that data structure and effectively calls SignerInfo::verify_signature_with_signed_data and SignerInfo::verify_message_digest_with_signed_data.
Returns Ok(None)
if there is no time-stamp token and Ok(Some(()))
if
there is and the token validates. Err
occurs on any parse or verification
error.
Sourcepub fn signed_content_with_signed_data(
&self,
signed_data: &SignedData,
) -> Vec<u8> ⓘ
pub fn signed_content_with_signed_data( &self, signed_data: &SignedData, ) -> Vec<u8> ⓘ
Obtain the raw bytes of content that was signed given a SignedData
.
This joins the encapsulated content from SignedData
with SignedAttributes
on this instance to produce a new blob. This new blob is the message
that is signed and whose signature is embedded in SignerInfo
instances.
Sourcepub fn signed_content(&self, content: Option<&[u8]>) -> Vec<u8> ⓘ
pub fn signed_content(&self, content: Option<&[u8]>) -> Vec<u8> ⓘ
Obtain the raw bytes of content that were digested and signed.
The returned value is the message that was signed and whose signature of which needs to be verified.
The optional content argument is the encapContentInfo eContent
field, typically the value of SignedData.signed_content()
.
Sourcepub fn signed_attributes_data(&self) -> Option<&[u8]>
pub fn signed_attributes_data(&self) -> Option<&[u8]>
Obtain the raw bytes constituting SignerInfo.signedAttrs
as encoded for signatures.
Cryptographic signatures in the SignerInfo
ASN.1 type are made from the digest
of the EXPLICIT SET OF
DER encoding of SignerInfo.signedAttrs
, if signed
attributes are present. This function resolves the raw bytes that are used
for digest computation and later signing.
This should always be Some
if the instance was constructed from an ASN.1
value that had signed attributes.
Sourcepub fn compute_digest_with_signed_data(
&self,
signed_data: &SignedData,
) -> Digest
pub fn compute_digest_with_signed_data( &self, signed_data: &SignedData, ) -> Digest
Compute a message digest using a SignedData
instance.
This will obtain the encapsulated content blob from a SignedData
and digest it using the algorithm configured on this instance.
The resulting digest is typically stored in the message-digest
attribute of SignedData
.
Sourcepub fn compute_digest(&self, content: Option<&[u8]>) -> Digest
pub fn compute_digest(&self, content: Option<&[u8]>) -> Digest
Compute a message digest using the configured algorithm.
This method calls into compute_digest_with_algorithm()
using the
digest algorithm stored in this instance.
Sourcepub fn compute_digest_with_algorithm(
&self,
content: Option<&[u8]>,
alg: DigestAlgorithm,
) -> Digest
pub fn compute_digest_with_algorithm( &self, content: Option<&[u8]>, alg: DigestAlgorithm, ) -> Digest
Compute a message digest using an explicit digest algorithm.
This will compute the hash/digest of the passed in content.
Trait Implementations§
Source§impl Clone for SignerInfo
impl Clone for SignerInfo
Source§fn clone(&self) -> SignerInfo
fn clone(&self) -> SignerInfo
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for SignerInfo
impl Debug for SignerInfo
Source§impl TryFrom<&SignerInfo> for SignerInfo
impl TryFrom<&SignerInfo> for SignerInfo
Auto Trait Implementations§
impl !Freeze for SignerInfo
impl RefUnwindSafe for SignerInfo
impl Send for SignerInfo
impl Sync for SignerInfo
impl Unpin for SignerInfo
impl UnwindSafe for SignerInfo
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)