Skip to content

Commit 3dd5e79

Browse files
committed
x509-cert: make name an owned type
1 parent 4811a2d commit 3dd5e79

File tree

11 files changed

+63
-69
lines changed

11 files changed

+63
-69
lines changed

x509-cert/src/anchor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub struct TrustAnchorInfo<'a> {
7575
#[derive(Clone, Debug, Eq, PartialEq, Sequence)]
7676
#[allow(missing_docs)]
7777
pub struct CertPathControls<'a> {
78-
pub ta_name: Name<'a>,
78+
pub ta_name: Name,
7979

8080
#[asn1(context_specific = "0", tag_mode = "IMPLICIT", optional = "true")]
8181
pub certificate: Option<Certificate<'a>>,

x509-cert/src/attr.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use const_oid::db::rfc4519::{COUNTRY_NAME, DOMAIN_COMPONENT};
55
use core::fmt::{self, Write};
66

77
use const_oid::db::DB;
8-
use der::asn1::{AnyRef, ObjectIdentifier, SetOfVec};
8+
use der::asn1::{Any, ObjectIdentifier, SetOfVec};
99
use der::{Decode, Encode, Error, ErrorKind, Sequence, Tag, Tagged, ValueOrd};
1010

1111
/// X.501 `AttributeType` as defined in [RFC 5280 Appendix A.1].
@@ -24,7 +24,7 @@ pub type AttributeType = ObjectIdentifier;
2424
/// ```
2525
///
2626
/// [RFC 5280 Appendix A.1]: https://datatracker.ietf.org/doc/html/rfc5280#appendix-A.1
27-
pub type AttributeValue<'a> = AnyRef<'a>;
27+
pub type AttributeValue = Any;
2828

2929
/// X.501 `Attribute` as defined in [RFC 5280 Appendix A.1].
3030
///
@@ -50,15 +50,15 @@ pub type AttributeValue<'a> = AnyRef<'a>;
5050
/// [RFC 5280 Appendix A.1]: https://datatracker.ietf.org/doc/html/rfc5280#appendix-A.1
5151
#[derive(Clone, Debug, PartialEq, Eq, Sequence, ValueOrd)]
5252
#[allow(missing_docs)]
53-
pub struct Attribute<'a> {
53+
pub struct Attribute {
5454
pub oid: AttributeType,
55-
pub values: SetOfVec<AttributeValue<'a>>,
55+
pub values: SetOfVec<AttributeValue>,
5656
}
5757

58-
impl<'a> TryFrom<&'a [u8]> for Attribute<'a> {
58+
impl TryFrom<&[u8]> for Attribute {
5959
type Error = Error;
6060

61-
fn try_from(bytes: &'a [u8]) -> Result<Self, Self::Error> {
61+
fn try_from(bytes: &[u8]) -> Result<Self, Self::Error> {
6262
Self::from_der(bytes)
6363
}
6464
}
@@ -70,7 +70,7 @@ impl<'a> TryFrom<&'a [u8]> for Attribute<'a> {
7070
/// ```
7171
///
7272
/// [RFC 2986 Section 4]: https://datatracker.ietf.org/doc/html/rfc2986#section-4
73-
pub type Attributes<'a> = SetOfVec<Attribute<'a>>;
73+
pub type Attributes = SetOfVec<Attribute>;
7474

7575
/// X.501 `AttributeTypeAndValue` as defined in [RFC 5280 Appendix A.1].
7676
///
@@ -82,11 +82,11 @@ pub type Attributes<'a> = SetOfVec<Attribute<'a>>;
8282
/// ```
8383
///
8484
/// [RFC 5280 Appendix A.1]: https://datatracker.ietf.org/doc/html/rfc5280#appendix-A.1
85-
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Sequence, ValueOrd)]
85+
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Sequence, ValueOrd)]
8686
#[allow(missing_docs)]
87-
pub struct AttributeTypeAndValue<'a> {
87+
pub struct AttributeTypeAndValue {
8888
pub oid: AttributeType,
89-
pub value: AnyRef<'a>,
89+
pub value: AttributeValue,
9090
}
9191

9292
#[derive(Copy, Clone)]
@@ -141,7 +141,7 @@ impl Parser {
141141
}
142142
}
143143

144-
impl AttributeTypeAndValue<'_> {
144+
impl AttributeTypeAndValue {
145145
/// Parses the hex value in the `OID=#HEX` format.
146146
fn encode_hex(oid: ObjectIdentifier, val: &str) -> Result<Vec<u8>, Error> {
147147
// Ensure an even number of hex bytes.
@@ -169,7 +169,7 @@ impl AttributeTypeAndValue<'_> {
169169
}
170170

171171
// Serialize.
172-
let value = AnyRef::from_der(&bytes)?;
172+
let value = Any::from_der(&bytes)?;
173173
let atv = AttributeTypeAndValue { oid, value };
174174
atv.to_vec()
175175
}
@@ -189,7 +189,7 @@ impl AttributeTypeAndValue<'_> {
189189
};
190190

191191
// Serialize.
192-
let value = AnyRef::new(tag, parser.as_bytes())?;
192+
let value = Any::new(tag, parser.as_bytes())?;
193193
let atv = AttributeTypeAndValue { oid, value };
194194
atv.to_vec()
195195
}
@@ -221,7 +221,7 @@ impl AttributeTypeAndValue<'_> {
221221
/// Serializes the structure according to the rules in [RFC 4514].
222222
///
223223
/// [RFC 4514]: https://datatracker.ietf.org/doc/html/rfc4514
224-
impl fmt::Display for AttributeTypeAndValue<'_> {
224+
impl fmt::Display for AttributeTypeAndValue {
225225
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
226226
let val = match self.value.tag() {
227227
Tag::PrintableString => self.value.printable_string().ok().map(|s| s.as_str()),

x509-cert/src/certificate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ pub struct TbsCertificate<'a> {
8585

8686
pub serial_number: UIntRef<'a>,
8787
pub signature: AlgorithmIdentifier<'a>,
88-
pub issuer: Name<'a>,
88+
pub issuer: Name,
8989
pub validity: Validity,
90-
pub subject: Name<'a>,
90+
pub subject: Name,
9191
pub subject_public_key_info: SubjectPublicKeyInfo<'a>,
9292

9393
#[asn1(context_specific = "1", tag_mode = "IMPLICIT", optional = "true")]

x509-cert/src/crl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub struct RevokedCert<'a> {
7676
pub struct TbsCertList<'a> {
7777
pub version: Version,
7878
pub signature: AlgorithmIdentifier<'a>,
79-
pub issuer: Name<'a>,
79+
pub issuer: Name,
8080
pub this_update: Time,
8181
pub next_update: Option<Time>,
8282
pub revoked_certificates: Option<Vec<RevokedCert<'a>>>,

x509-cert/src/ext/pkix.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,13 @@ impl_newtype!(IssuerAltName<'a>, name::GeneralNames<'a>);
8989
///
9090
/// [RFC 5280 Section 4.2.1.8]: https://datatracker.ietf.org/doc/html/rfc5280#section-4.2.1.8
9191
#[derive(Clone, Debug, Default, PartialEq, Eq)]
92-
pub struct SubjectDirectoryAttributes<'a>(pub Vec<AttributeTypeAndValue<'a>>);
92+
pub struct SubjectDirectoryAttributes(pub Vec<AttributeTypeAndValue>);
9393

94-
impl<'a> AssociatedOid for SubjectDirectoryAttributes<'a> {
94+
impl AssociatedOid for SubjectDirectoryAttributes {
9595
const OID: ObjectIdentifier = ID_CE_SUBJECT_DIRECTORY_ATTRIBUTES;
9696
}
9797

98-
impl_newtype!(
99-
SubjectDirectoryAttributes<'a>,
100-
Vec<AttributeTypeAndValue<'a>>
101-
);
98+
impl_newtype!(SubjectDirectoryAttributes, Vec<AttributeTypeAndValue>);
10299

103100
/// InhibitAnyPolicy as defined in [RFC 5280 Section 4.2.1.14].
104101
///

x509-cert/src/ext/pkix/name/dp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ pub enum DistributionPointName<'a> {
2020
FullName(GeneralNames<'a>),
2121

2222
#[asn1(context_specific = "1", tag_mode = "IMPLICIT", constructed = "true")]
23-
NameRelativeToCRLIssuer(RelativeDistinguishedName<'a>),
23+
NameRelativeToCRLIssuer(RelativeDistinguishedName),
2424
}

x509-cert/src/ext/pkix/name/general.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub enum GeneralName<'a> {
4747
DnsName(Ia5StringRef<'a>),
4848

4949
#[asn1(context_specific = "4", tag_mode = "EXPLICIT", constructed = "true")]
50-
DirectoryName(Name<'a>),
50+
DirectoryName(Name),
5151

5252
#[asn1(context_specific = "5", tag_mode = "IMPLICIT", constructed = "true")]
5353
EdiPartyName(EdiPartyName<'a>),

x509-cert/src/name.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use der::{asn1::SetOfVec, Decode, Encode};
1212
/// ```
1313
///
1414
/// [RFC 5280 Section 4.1.2.4]: https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.4
15-
pub type Name<'a> = RdnSequence<'a>;
15+
pub type Name = RdnSequence;
1616

1717
/// X.501 RDNSequence as defined in [RFC 5280 Section 4.1.2.4].
1818
///
@@ -22,9 +22,9 @@ pub type Name<'a> = RdnSequence<'a>;
2222
///
2323
/// [RFC 5280 Section 4.1.2.4]: https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.4
2424
#[derive(Clone, Debug, Default, PartialEq, Eq)]
25-
pub struct RdnSequence<'a>(pub Vec<RelativeDistinguishedName<'a>>);
25+
pub struct RdnSequence(pub Vec<RelativeDistinguishedName>);
2626

27-
impl RdnSequence<'_> {
27+
impl RdnSequence {
2828
/// Converts an RDNSequence string into an encoded RDNSequence
2929
///
3030
/// This function follows the rules in [RFC 4514].
@@ -47,7 +47,7 @@ impl RdnSequence<'_> {
4747
/// Serializes the structure according to the rules in [RFC 4514].
4848
///
4949
/// [RFC 4514]: https://datatracker.ietf.org/doc/html/rfc4514
50-
impl fmt::Display for RdnSequence<'_> {
50+
impl fmt::Display for RdnSequence {
5151
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5252
for (i, atv) in self.0.iter().enumerate() {
5353
match i {
@@ -60,7 +60,7 @@ impl fmt::Display for RdnSequence<'_> {
6060
}
6161
}
6262

63-
impl_newtype!(RdnSequence<'a>, Vec<RelativeDistinguishedName<'a>>);
63+
impl_newtype!(RdnSequence, Vec<RelativeDistinguishedName>);
6464

6565
/// Find the indices of all non-escaped separators.
6666
fn find(s: &str, b: u8) -> impl '_ + Iterator<Item = usize> {
@@ -98,7 +98,7 @@ fn split(s: &str, b: u8) -> impl '_ + Iterator<Item = &'_ str> {
9898
/// ```
9999
///
100100
/// [RFC 5280 Section 4.1.2.4]: https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.4
101-
pub type DistinguishedName<'a> = RdnSequence<'a>;
101+
pub type DistinguishedName = RdnSequence;
102102

103103
/// RelativeDistinguishedName as defined in [RFC 5280 Section 4.1.2.4].
104104
///
@@ -125,9 +125,9 @@ pub type DistinguishedName<'a> = RdnSequence<'a>;
125125
///
126126
/// [RFC 5280 Section 4.1.2.4]: https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.4
127127
#[derive(Clone, Debug, Default, PartialEq, Eq)]
128-
pub struct RelativeDistinguishedName<'a>(pub SetOfVec<AttributeTypeAndValue<'a>>);
128+
pub struct RelativeDistinguishedName(pub SetOfVec<AttributeTypeAndValue>);
129129

130-
impl RelativeDistinguishedName<'_> {
130+
impl RelativeDistinguishedName {
131131
/// Converts an RelativeDistinguishedName string into an encoded RelativeDistinguishedName
132132
///
133133
/// This function follows the rules in [RFC 4514].
@@ -150,7 +150,7 @@ impl RelativeDistinguishedName<'_> {
150150
/// Serializes the structure according to the rules in [RFC 4514].
151151
///
152152
/// [RFC 4514]: https://datatracker.ietf.org/doc/html/rfc4514
153-
impl fmt::Display for RelativeDistinguishedName<'_> {
153+
impl fmt::Display for RelativeDistinguishedName {
154154
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
155155
for (i, atv) in self.0.iter().enumerate() {
156156
match i {
@@ -163,7 +163,4 @@ impl fmt::Display for RelativeDistinguishedName<'_> {
163163
}
164164
}
165165

166-
impl_newtype!(
167-
RelativeDistinguishedName<'a>,
168-
SetOfVec<AttributeTypeAndValue<'a>>
169-
);
166+
impl_newtype!(RelativeDistinguishedName, SetOfVec<AttributeTypeAndValue>);

x509-cert/src/request.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ pub struct CertReqInfo<'a> {
4040
pub version: Version,
4141

4242
/// Subject name.
43-
pub subject: Name<'a>,
43+
pub subject: Name,
4444

4545
/// Subject public key info.
4646
pub public_key: SubjectPublicKeyInfo<'a>,
4747

4848
/// Request attributes.
4949
#[asn1(context_specific = "0", tag_mode = "IMPLICIT")]
50-
pub attributes: Attributes<'a>,
50+
pub attributes: Attributes,
5151
}
5252

5353
impl<'a> TryFrom<&'a [u8]> for CertReqInfo<'a> {

0 commit comments

Comments
 (0)