Skip to content

Commit 4770f05

Browse files
committed
Convert PKCS#7 types to GATs
This does not currently work because rust-asn1 doesn't handle Asn1Definedby{Readable,Writable} correctly
1 parent 7971c6b commit 4770f05

File tree

3 files changed

+29
-36
lines changed

3 files changed

+29
-36
lines changed

src/rust/cryptography-x509/src/common.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ impl<T: asn1::SimpleAsn1Writable, U: asn1::SimpleAsn1Writable> asn1::SimpleAsn1W
265265

266266
pub trait Asn1Operation {
267267
type SequenceOfVec<'a, T>
268+
where
269+
T: 'a;
270+
type SetOf<'a, T>
268271
where
269272
T: 'a;
270273
type SetOfVec<'a, T>
@@ -281,6 +284,10 @@ impl Asn1Operation for Asn1Read {
281284
= asn1::SequenceOf<'a, T>
282285
where
283286
T: 'a;
287+
type SetOf<'a, T>
288+
= asn1::SetOf<'a, T>
289+
where
290+
T: 'a;
284291
type SetOfVec<'a, T>
285292
= asn1::SetOf<'a, T>
286293
where
@@ -292,6 +299,10 @@ impl Asn1Operation for Asn1Write {
292299
= asn1::SequenceOfWriter<'a, T, Vec<T>>
293300
where
294301
T: 'a;
302+
type SetOf<'a, T>
303+
= asn1::SetOfWriter<'a, T>
304+
where
305+
T: 'a;
295306
type SetOfVec<'a, T>
296307
= asn1::SetOfWriter<'a, T, Vec<T>>
297308
where

src/rust/cryptography-x509/src/pkcs12.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// 2.0, and the BSD License. See the LICENSE file in the root of this repository
33
// for complete details.
44

5-
use crate::common::{AlgorithmIdentifier, Utf8StoredBMPString};
5+
use crate::common::{AlgorithmIdentifier, Asn1Operation, Utf8StoredBMPString};
66
use crate::pkcs7;
77

88
pub const CERT_BAG_OID: asn1::ObjectIdentifier = asn1::oid!(1, 2, 840, 113549, 1, 12, 10, 1, 3);
@@ -14,9 +14,9 @@ pub const FRIENDLY_NAME_OID: asn1::ObjectIdentifier = asn1::oid!(1, 2, 840, 1135
1414
pub const LOCAL_KEY_ID_OID: asn1::ObjectIdentifier = asn1::oid!(1, 2, 840, 113549, 1, 9, 21);
1515

1616
#[derive(asn1::Asn1Write)]
17-
pub struct Pfx<'a> {
17+
pub struct Pfx<'a, Op: Asn1Operation> {
1818
pub version: u8,
19-
pub auth_safe: pkcs7::ContentInfo<'a>,
19+
pub auth_safe: pkcs7::ContentInfo<'a, Op>,
2020
pub mac_data: Option<MacData<'a>>,
2121
}
2222

src/rust/cryptography-x509/src/pkcs7.rs

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// 2.0, and the BSD License. See the LICENSE file in the root of this repository
33
// for complete details.
44

5+
use crate::common::Asn1Operation;
56
use crate::{certificate, common, csr, name};
67

78
pub const PKCS7_DATA_OID: asn1::ObjectIdentifier = asn1::oid!(1, 2, 840, 113549, 1, 7, 1);
@@ -10,54 +11,38 @@ pub const PKCS7_ENVELOPED_DATA_OID: asn1::ObjectIdentifier = asn1::oid!(1, 2, 84
1011
pub const PKCS7_ENCRYPTED_DATA_OID: asn1::ObjectIdentifier = asn1::oid!(1, 2, 840, 113549, 1, 7, 6);
1112

1213
#[derive(asn1::Asn1Write, asn1::Asn1Read)]
13-
pub struct ContentInfo<'a> {
14+
pub struct ContentInfo<'a, Op: Asn1Operation> {
1415
pub _content_type: asn1::DefinedByMarker<asn1::ObjectIdentifier>,
1516

1617
#[defined_by(_content_type)]
17-
pub content: Content<'a>,
18+
pub content: Content<'a, Op>,
1819
}
1920

2021
#[derive(asn1::Asn1DefinedByWrite, asn1::Asn1DefinedByRead)]
21-
pub enum Content<'a> {
22+
pub enum Content<'a, Op: Asn1Operation> {
2223
#[defined_by(PKCS7_ENVELOPED_DATA_OID)]
23-
EnvelopedData(asn1::Explicit<Box<EnvelopedData<'a>>, 0>),
24+
EnvelopedData(asn1::Explicit<Box<EnvelopedData<'a, Op>>, 0>),
2425
#[defined_by(PKCS7_SIGNED_DATA_OID)]
25-
SignedData(asn1::Explicit<Box<SignedData<'a>>, 0>),
26+
SignedData(asn1::Explicit<Box<SignedData<'a, Op>>, 0>),
2627
#[defined_by(PKCS7_DATA_OID)]
2728
Data(Option<asn1::Explicit<&'a [u8], 0>>),
2829
#[defined_by(PKCS7_ENCRYPTED_DATA_OID)]
2930
EncryptedData(asn1::Explicit<EncryptedData<'a>, 0>),
3031
}
3132

3233
#[derive(asn1::Asn1Write, asn1::Asn1Read)]
33-
pub struct SignedData<'a> {
34+
pub struct SignedData<'a, Op: Asn1Operation> {
3435
pub version: u8,
35-
pub digest_algorithms: common::Asn1ReadableOrWritable<
36-
asn1::SetOf<'a, common::AlgorithmIdentifier<'a>>,
37-
asn1::SetOfWriter<'a, common::AlgorithmIdentifier<'a>>,
38-
>,
39-
pub content_info: ContentInfo<'a>,
36+
pub digest_algorithms: Op::SetOf<'a, common::AlgorithmIdentifier<'a>>,
37+
pub content_info: ContentInfo<'a, Op>,
4038
#[implicit(0)]
41-
pub certificates: Option<
42-
common::Asn1ReadableOrWritable<
43-
asn1::SetOf<'a, certificate::Certificate<'a>>,
44-
asn1::SetOfWriter<'a, certificate::Certificate<'a>>,
45-
>,
46-
>,
39+
pub certificates: Option<Op::SetOf<'a, certificate::Certificate<'a>>>,
4740

4841
// We don't ever supply any of these, so for now, don't fill out the fields.
4942
#[implicit(1)]
50-
pub crls: Option<
51-
common::Asn1ReadableOrWritable<
52-
asn1::SetOf<'a, asn1::Sequence<'a>>,
53-
asn1::SetOfWriter<'a, asn1::Sequence<'a>>,
54-
>,
55-
>,
56-
57-
pub signer_infos: common::Asn1ReadableOrWritable<
58-
asn1::SetOf<'a, SignerInfo<'a>>,
59-
asn1::SetOfWriter<'a, SignerInfo<'a>>,
60-
>,
43+
pub crls: Option<Op::SetOf<'a, asn1::Sequence<'a>>>,
44+
45+
pub signer_infos: Op::SetOf<'a, SignerInfo<'a>>,
6146
}
6247

6348
#[derive(asn1::Asn1Write, asn1::Asn1Read)]
@@ -76,12 +61,9 @@ pub struct SignerInfo<'a> {
7661
}
7762

7863
#[derive(asn1::Asn1Write, asn1::Asn1Read)]
79-
pub struct EnvelopedData<'a> {
64+
pub struct EnvelopedData<'a, Op: Asn1Operation> {
8065
pub version: u8,
81-
pub recipient_infos: common::Asn1ReadableOrWritable<
82-
asn1::SetOf<'a, RecipientInfo<'a>>,
83-
asn1::SetOfWriter<'a, RecipientInfo<'a>>,
84-
>,
66+
pub recipient_infos: Op::SetOf<'a, RecipientInfo<'a>>,
8567
pub encrypted_content_info: EncryptedContentInfo<'a>,
8668
}
8769

0 commit comments

Comments
 (0)