Enum cryptographic_message_syntax::asn1::rfc5652::Time
source · pub enum Time {
UtcTime(UtcTime),
GeneralizedTime(GeneralizedTime),
}Expand description
Time variant.
Time ::= CHOICE {
utcTime UTCTime,
generalizedTime GeneralizedTime }
Variants§
UtcTime(UtcTime)
GeneralizedTime(GeneralizedTime)
Implementations§
source§impl Time
impl Time
sourcepub fn take_from<S: Source>(
cons: &mut Constructed<'_, S>
) -> Result<Self, DecodeError<S::Error>>
pub fn take_from<S: Source>(
cons: &mut Constructed<'_, S>
) -> Result<Self, DecodeError<S::Error>>
Examples found in repository?
src/lib.rs (line 926)
848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979
fn try_from(signer_info: &crate::asn1::rfc5652::SignerInfo) -> Result<Self, Self::Error> {
let (issuer, serial_number) = match &signer_info.sid {
SignerIdentifier::IssuerAndSerialNumber(issuer) => {
(issuer.issuer.clone(), issuer.serial_number.clone())
}
SignerIdentifier::SubjectKeyIdentifier(_) => {
return Err(CmsError::SubjectKeyIdentifierUnsupported);
}
};
let digest_algorithm = DigestAlgorithm::try_from(&signer_info.digest_algorithm)?;
// The "signature" algorithm can also be a key algorithm identifier. So we
// attempt to resolve using the more robust mechanism.
let signature_algorithm = SignatureAlgorithm::from_oid_and_digest_algorithm(
&signer_info.signature_algorithm.algorithm,
digest_algorithm,
)?;
let signature = signer_info.signature.to_bytes().to_vec();
let signed_attributes = if let Some(attributes) = &signer_info.signed_attributes {
// Content type attribute MUST be present.
let content_type = attributes
.iter()
.find(|attr| attr.typ == OID_CONTENT_TYPE)
.ok_or(CmsError::MissingSignedAttributeContentType)?;
// Content type attribute MUST have exactly 1 value.
if content_type.values.len() != 1 {
return Err(CmsError::MalformedSignedAttributeContentType);
}
let content_type = content_type
.values
.get(0)
.unwrap()
.deref()
.clone()
.decode(|cons| Oid::take_from(cons))
.map_err(|_| CmsError::MalformedSignedAttributeContentType)?;
// Message digest attribute MUST be present.
let message_digest = attributes
.iter()
.find(|attr| attr.typ == OID_MESSAGE_DIGEST)
.ok_or(CmsError::MissingSignedAttributeMessageDigest)?;
// Message digest attribute MUST have exactly 1 value.
if message_digest.values.len() != 1 {
return Err(CmsError::MalformedSignedAttributeMessageDigest);
}
let message_digest = message_digest
.values
.get(0)
.unwrap()
.deref()
.clone()
.decode(|cons| OctetString::take_from(cons))
.map_err(|_| CmsError::MalformedSignedAttributeMessageDigest)?
.to_bytes()
.to_vec();
// Signing time is optional, but common. So we pull it out for convenience.
let signing_time = attributes
.iter()
.find(|attr| attr.typ == OID_SIGNING_TIME)
.map(|attr| {
if attr.values.len() != 1 {
Err(CmsError::MalformedSignedAttributeSigningTime)
} else {
let time = attr
.values
.get(0)
.unwrap()
.deref()
.clone()
.decode(|cons| Time::take_from(cons))?;
let time = chrono::DateTime::from(time);
Ok(time)
}
})
.transpose()?;
Some(SignedAttributes {
content_type,
message_digest,
signing_time,
raw: attributes.clone(),
})
} else {
None
};
let digested_signed_attributes_data = signer_info.signed_attributes_digested_content()?;
let unsigned_attributes =
if let Some(attributes) = &signer_info.unsigned_attributes {
let time_stamp_token =
attributes
.iter()
.find(|attr| attr.typ == OID_TIME_STAMP_TOKEN)
.map(|attr| {
if attr.values.len() != 1 {
Err(CmsError::MalformedUnsignedAttributeTimeStampToken)
} else {
Ok(attr.values.get(0).unwrap().deref().clone().decode(|cons| {
crate::asn1::rfc5652::SignedData::decode(cons)
})?)
}
})
.transpose()?;
Some(UnsignedAttributes { time_stamp_token })
} else {
None
};
Ok(SignerInfo {
issuer,
serial_number,
digest_algorithm,
signature_algorithm,
signature,
signed_attributes,
digested_signed_attributes_data,
unsigned_attributes,
})
}Trait Implementations§
source§impl PartialEq<Time> for Time
impl PartialEq<Time> for Time
impl Eq for Time
impl StructuralEq for Time
impl StructuralPartialEq for Time
Auto Trait Implementations§
impl RefUnwindSafe for Time
impl Send for Time
impl Sync for Time
impl Unpin for Time
impl UnwindSafe for Time
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.