Skip to content

Commit 3a0d7d5

Browse files
committed
Creation of PKCS RustCrypto#7 started
1 parent 31ea48a commit 3a0d7d5

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

Diff for: pkcs7/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub mod revocation_info_choices;
2525
pub mod signed_data_content;
2626
pub mod signer_info;
2727

28-
mod content_info;
28+
pub mod content_info;
2929
mod content_type;
3030

3131
pub use crate::{content_info::ContentInfo, content_type::ContentType};

Diff for: pkcs7/src/signed_data_content.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ use spki::AlgorithmIdentifierRef;
1111
/// ```text
1212
/// DigestAlgorithmIdentifier ::= AlgorithmIdentifier
1313
/// ```
14-
type DigestAlgorithmIdentifier<'a> = AlgorithmIdentifierRef<'a>;
14+
pub type DigestAlgorithmIdentifier<'a> = AlgorithmIdentifierRef<'a>;
1515

1616
/// ```text
1717
/// DigestAlgorithmIdentifiers ::= SET OF DigestAlgorithmIdentifier
1818
/// ```
19-
type DigestAlgorithmIdentifiers<'a> = SetOfVec<DigestAlgorithmIdentifier<'a>>;
19+
pub type DigestAlgorithmIdentifiers<'a> = SetOfVec<DigestAlgorithmIdentifier<'a>>;
2020

2121
/// ```text
2222
/// CertificateSet ::= SET OF CertificateChoices
2323
/// ```
24-
type CertificateSet<'a> = SetOfVec<CertificateChoices<'a>>;
24+
pub type CertificateSet<'a> = SetOfVec<CertificateChoices<'a>>;
2525

2626
/// Signed-data content type [RFC 5652 § 5](https://datatracker.ietf.org/doc/html/rfc5652#section-5)
2727
///

Diff for: pkcs7/tests/content_tests.rs

+56
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ fn decode_signed_scep_example() {
139139
}
140140
_ => panic!("expected ContentInfo::SignedData(Some(_))"),
141141
}
142+
143+
let mut buf = vec![0u8; bytes.len()];
144+
let encoded_content = encode_content_info(&content, &mut buf);
145+
println!("{:?}", encoded_content);
142146
}
143147

144148
// TODO(tarcieri): BER support
@@ -186,3 +190,55 @@ fn decode_signed_der() {
186190
10034
187191
);
188192
}
193+
194+
use pkcs7::{
195+
signed_data_content::{CertificateSet, DigestAlgorithmIdentifier, DigestAlgorithmIdentifiers},
196+
signer_info::{SignerInfo, SignerInfos},
197+
};
198+
199+
const OID_ED25519: &str = "1.3.101.112"; // {iso(1) identified-organization(3) thawte(101) id-Ed25519(112)}
200+
const OID_PKCS7_SIGNED_DATA: &str = "1.2.840.113549.1.7.2"; // {iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs-7(7) signedData(2)}
201+
202+
#[test]
203+
fn test_make_pkcs7_signed_data() {
204+
205+
let content_info = ContentInfo::SignedData(SignedDataContent {
206+
version: pkcs7::cms_version::CmsVersion::V1,
207+
digest_algorithms: get_digest_algorithms(),
208+
encap_content_info: get_encap_content_info(),
209+
certificates: get_certificates(),
210+
crls: None,
211+
signer_infos: get_signer_infos(),
212+
});
213+
214+
let mut buf = vec![0u8; 10000];
215+
let _encoded_content = encode_content_info(&content_info, &mut buf);
216+
}
217+
218+
fn get_digest_algorithms<'a>() -> DigestAlgorithmIdentifiers<'a> {
219+
let digest_algorithm = DigestAlgorithmIdentifier {
220+
oid: der::asn1::ObjectIdentifier::new(OID_ED25519).unwrap(),
221+
parameters: None
222+
};
223+
let mut digest_algorithms = DigestAlgorithmIdentifiers::new();
224+
digest_algorithms.add(digest_algorithm).unwrap();
225+
digest_algorithms
226+
}
227+
228+
fn get_encap_content_info<'a>() -> EncapsulatedContentInfo<'a> {
229+
EncapsulatedContentInfo {
230+
e_content_type: der::asn1::ObjectIdentifier::new(OID_PKCS7_SIGNED_DATA).unwrap(),
231+
e_content: None,
232+
}
233+
}
234+
235+
fn get_certificates<'a>() -> Option<CertificateSet<'a>> {
236+
None
237+
}
238+
239+
fn get_signer_infos<'a>() -> SignerInfos<'a> {
240+
let signer_infos = SignerInfos::new();
241+
signer_infos
242+
}
243+
244+

0 commit comments

Comments
 (0)