Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion cms/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ use core::borrow::Borrow;
use der::{
DecodeValue, EncodeValue, FixedTag, Length, Tag,
asn1::{OctetString, OctetStringRef},
oid::db::rfc6268,
};
use x509_cert::time::Time;

use x509_cert::{attr::Attribute, time::Time};

use crate::signed_data::SignerInfo;

Expand Down Expand Up @@ -101,6 +103,30 @@ impl From<MessageDigest> for vec::Vec<u8> {
}
}

impl TryFrom<&Attribute> for MessageDigest {
type Error = der::Error;

fn try_from(attr: &Attribute) -> Result<Self, Self::Error> {
if attr.oid != rfc6268::ID_MESSAGE_DIGEST {
return Err(der::ErrorKind::OidUnknown { oid: attr.oid }.into());
}

// A message-digest attribute MUST have a single attribute value, even
// though the syntax is defined as a SET OF AttributeValue. There MUST
// NOT be zero or multiple instances of AttributeValue present.

if attr.values.len() != 1 {
return Err(der::ErrorKind::Value { tag: Tag::Set }.into());
}
let message_digest = attr
.values
.get(0)
.expect("Invariant violation, only one value is present in the attribute");

message_digest.decode_as::<OctetString>().map(Self)
}
}

/// The `SigningTime` attribute is defined in [RFC 5652 Section 11.3].
///
/// ```text
Expand Down