|
2 | 2 |
|
3 | 3 | use cms::content_info::ContentInfo;
|
4 | 4 | use cms::signed_data::{SignedData, SignerInfos};
|
5 |
| -use der::{AnyRef, Decode, DecodePem, Encode, ErrorKind, Tag}; |
6 |
| -use x509_cert::Certificate; |
| 5 | +use const_oid::db::rfc5911; |
| 6 | +use core::str::FromStr; |
| 7 | +use der::{AnyRef, DateTime, Decode, DecodePem, Encode, ErrorKind, Tag, asn1::SetOfVec}; |
| 8 | +use x509_cert::{ |
| 9 | + Certificate, |
| 10 | + attr::{Attribute, AttributeValue}, |
| 11 | + time::Time, |
| 12 | +}; |
7 | 13 |
|
8 | 14 | #[test]
|
9 | 15 | fn trust_list_sd_test() {
|
@@ -143,3 +149,23 @@ fn certs_to_p7b() {
|
143 | 149 | let p7b_buf2 = p7b_ee.to_der().unwrap();
|
144 | 150 | assert_eq!(p7b_buf, p7b_buf2.as_slice());
|
145 | 151 | }
|
| 152 | + |
| 153 | +#[test] |
| 154 | +fn encode_decode_signing_time() { |
| 155 | + let time = DateTime::from_str("2024-12-31T23:59:59Z").unwrap(); |
| 156 | + |
| 157 | + // First serialize the attribute |
| 158 | + let time = Time::from(time); |
| 159 | + let time_der = time.to_der().unwrap(); |
| 160 | + let signing_time_attribute_value = AttributeValue::from_der(&time_der).unwrap(); |
| 161 | + let mut values = SetOfVec::<AttributeValue>::new(); |
| 162 | + values.insert(signing_time_attribute_value.clone()).unwrap(); |
| 163 | + let _attribute = Attribute { |
| 164 | + oid: rfc5911::ID_SIGNING_TIME, |
| 165 | + values, |
| 166 | + }; |
| 167 | + |
| 168 | + // and deserialize |
| 169 | + let time_deserialized = signing_time_attribute_value.decode_as::<Time>().unwrap(); |
| 170 | + assert_eq!(time, time_deserialized); |
| 171 | +} |
0 commit comments