Skip to content

Commit

Permalink
Remove pointless lifetimes (#9896)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex authored Nov 18, 2023
1 parent c80da81 commit 79fc4cc
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 29 deletions.
27 changes: 13 additions & 14 deletions src/rust/cryptography-x509/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use crate::oid;
use asn1::Asn1DefinedByWritable;
use std::marker::PhantomData;

#[derive(asn1::Asn1Read, asn1::Asn1Write, PartialEq, Hash, Clone, Eq, Debug)]
pub struct AlgorithmIdentifier<'a> {
Expand Down Expand Up @@ -180,45 +179,45 @@ impl Time {
}

#[derive(Hash, PartialEq, Eq, Clone)]
pub enum Asn1ReadableOrWritable<'a, T, U> {
Read(T, PhantomData<&'a ()>),
Write(U, PhantomData<&'a ()>),
pub enum Asn1ReadableOrWritable<T, U> {
Read(T),
Write(U),
}

impl<'a, T, U> Asn1ReadableOrWritable<'a, T, U> {
impl<T, U> Asn1ReadableOrWritable<T, U> {
pub fn new_read(v: T) -> Self {
Asn1ReadableOrWritable::Read(v, PhantomData)
Asn1ReadableOrWritable::Read(v)
}

pub fn new_write(v: U) -> Self {
Asn1ReadableOrWritable::Write(v, PhantomData)
Asn1ReadableOrWritable::Write(v)
}

pub fn unwrap_read(&self) -> &T {
match self {
Asn1ReadableOrWritable::Read(v, _) => v,
Asn1ReadableOrWritable::Write(_, _) => panic!("unwrap_read called on a Write value"),
Asn1ReadableOrWritable::Read(v) => v,
Asn1ReadableOrWritable::Write(_) => panic!("unwrap_read called on a Write value"),
}
}
}

impl<'a, T: asn1::SimpleAsn1Readable<'a>, U> asn1::SimpleAsn1Readable<'a>
for Asn1ReadableOrWritable<'a, T, U>
for Asn1ReadableOrWritable<T, U>
{
const TAG: asn1::Tag = T::TAG;
fn parse_data(data: &'a [u8]) -> asn1::ParseResult<Self> {
Ok(Self::new_read(T::parse_data(data)?))
}
}

impl<'a, T: asn1::SimpleAsn1Writable, U: asn1::SimpleAsn1Writable> asn1::SimpleAsn1Writable
for Asn1ReadableOrWritable<'a, T, U>
impl<T: asn1::SimpleAsn1Writable, U: asn1::SimpleAsn1Writable> asn1::SimpleAsn1Writable
for Asn1ReadableOrWritable<T, U>
{
const TAG: asn1::Tag = U::TAG;
fn write_data(&self, w: &mut asn1::WriteBuf) -> asn1::WriteResult {
match self {
Asn1ReadableOrWritable::Read(v, _) => T::write_data(v, w),
Asn1ReadableOrWritable::Write(v, _) => U::write_data(v, w),
Asn1ReadableOrWritable::Read(v) => T::write_data(v, w),
Asn1ReadableOrWritable::Write(v) => U::write_data(v, w),
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/rust/cryptography-x509/src/crl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
};

pub type ReasonFlags<'a> =
Option<common::Asn1ReadableOrWritable<'a, asn1::BitString<'a>, asn1::OwnedBitString>>;
Option<common::Asn1ReadableOrWritable<asn1::BitString<'a>, asn1::OwnedBitString>>;

#[derive(asn1::Asn1Read, asn1::Asn1Write, PartialEq, Eq, Hash)]
pub struct CertificateRevocationList<'a> {
Expand All @@ -20,7 +20,6 @@ pub struct CertificateRevocationList<'a> {

pub type RevokedCertificates<'a> = Option<
common::Asn1ReadableOrWritable<
'a,
asn1::SequenceOf<'a, RevokedCertificate<'a>>,
asn1::SequenceOfWriter<'a, RevokedCertificate<'a>, Vec<RevokedCertificate<'a>>>,
>,
Expand Down
2 changes: 0 additions & 2 deletions src/rust/cryptography-x509/src/csr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ pub fn check_attribute_length<'a>(
}

pub type Attributes<'a> = common::Asn1ReadableOrWritable<
'a,
asn1::SetOf<'a, Attribute<'a>>,
asn1::SetOfWriter<'a, Attribute<'a>, Vec<Attribute<'a>>>,
>;
Expand All @@ -63,7 +62,6 @@ pub type Attributes<'a> = common::Asn1ReadableOrWritable<
pub struct Attribute<'a> {
pub type_id: asn1::ObjectIdentifier,
pub values: common::Asn1ReadableOrWritable<
'a,
asn1::SetOf<'a, asn1::Tlv<'a>>,
asn1::SetOfWriter<'a, common::RawTlv<'a>, [common::RawTlv<'a>; 1]>,
>,
Expand Down
6 changes: 0 additions & 6 deletions src/rust/cryptography-x509/src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::name;
pub struct DuplicateExtensionsError(pub asn1::ObjectIdentifier);

pub type RawExtensions<'a> = common::Asn1ReadableOrWritable<
'a,
asn1::SequenceOf<'a, Extension<'a>>,
asn1::SequenceOfWriter<'a, Extension<'a>, Vec<Extension<'a>>>,
>;
Expand Down Expand Up @@ -95,14 +94,12 @@ pub struct AccessDescription<'a> {
}

pub type SequenceOfAccessDescriptions<'a> = common::Asn1ReadableOrWritable<
'a,
asn1::SequenceOf<'a, AccessDescription<'a>>,
asn1::SequenceOfWriter<'a, AccessDescription<'a>, Vec<AccessDescription<'a>>>,
>;

// Needed due to clippy type complexity warning.
type SequenceOfPolicyQualifiers<'a> = common::Asn1ReadableOrWritable<
'a,
asn1::SequenceOf<'a, PolicyQualifierInfo<'a>>,
asn1::SequenceOfWriter<'a, PolicyQualifierInfo<'a>, Vec<PolicyQualifierInfo<'a>>>,
>;
Expand Down Expand Up @@ -135,7 +132,6 @@ pub struct UserNotice<'a> {
pub struct NoticeReference<'a> {
pub organization: DisplayText<'a>,
pub notice_numbers: common::Asn1ReadableOrWritable<
'a,
asn1::SequenceOf<'a, asn1::BigUint<'a>>,
asn1::SequenceOfWriter<'a, asn1::BigUint<'a>, Vec<asn1::BigUint<'a>>>,
>,
Expand All @@ -154,7 +150,6 @@ pub enum DisplayText<'a> {

// Needed due to clippy type complexity warning.
pub type SequenceOfSubtrees<'a> = common::Asn1ReadableOrWritable<
'a,
asn1::SequenceOf<'a, GeneralSubtree<'a>>,
asn1::SequenceOfWriter<'a, GeneralSubtree<'a>, Vec<GeneralSubtree<'a>>>,
>;
Expand Down Expand Up @@ -207,7 +202,6 @@ pub enum DistributionPointName<'a> {
#[implicit(1)]
NameRelativeToCRLIssuer(
common::Asn1ReadableOrWritable<
'a,
asn1::SetOf<'a, common::AttributeTypeValue<'a>>,
asn1::SetOfWriter<
'a,
Expand Down
2 changes: 0 additions & 2 deletions src/rust/cryptography-x509/src/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::common;
pub type NameReadable<'a> = asn1::SequenceOf<'a, asn1::SetOf<'a, common::AttributeTypeValue<'a>>>;

pub type Name<'a> = common::Asn1ReadableOrWritable<
'a,
NameReadable<'a>,
asn1::SequenceOfWriter<
'a,
Expand Down Expand Up @@ -84,7 +83,6 @@ pub enum GeneralName<'a> {
}

pub(crate) type SequenceOfGeneralName<'a> = common::Asn1ReadableOrWritable<
'a,
asn1::SequenceOf<'a, GeneralName<'a>>,
asn1::SequenceOfWriter<'a, GeneralName<'a>, Vec<GeneralName<'a>>>,
>;
1 change: 0 additions & 1 deletion src/rust/cryptography-x509/src/ocsp_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub struct TBSRequest<'a> {
#[explicit(1)]
pub requestor_name: Option<name::GeneralName<'a>>,
pub request_list: common::Asn1ReadableOrWritable<
'a,
asn1::SequenceOf<'a, Request<'a>>,
asn1::SequenceOfWriter<'a, Request<'a>>,
>,
Expand Down
2 changes: 0 additions & 2 deletions src/rust/cryptography-x509/src/ocsp_resp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ pub struct ResponseBytes<'a> {

pub type OCSPCerts<'a> = Option<
common::Asn1ReadableOrWritable<
'a,
asn1::SequenceOf<'a, certificate::Certificate<'a>>,
asn1::SequenceOfWriter<'a, certificate::Certificate<'a>, Vec<certificate::Certificate<'a>>>,
>,
Expand All @@ -46,7 +45,6 @@ pub struct ResponseData<'a> {
pub responder_id: ResponderId<'a>,
pub produced_at: asn1::GeneralizedTime,
pub responses: common::Asn1ReadableOrWritable<
'a,
asn1::SequenceOf<'a, SingleResponse<'a>>,
asn1::SequenceOfWriter<'a, SingleResponse<'a>, Vec<SingleResponse<'a>>>,
>,
Expand Down

0 comments on commit 79fc4cc

Please sign in to comment.