From 4d1ecc2753d6ac70a76ed3b8e1a2005d2e2b32d0 Mon Sep 17 00:00:00 2001 From: Daniel McCarney Date: Mon, 8 Jan 2024 14:15:22 -0500 Subject: [PATCH] x509: remove unused NameRelativeToCrlIssuer field In practice we never examine the `untrusted::Input` field of a `DistributionPointName::NameRelativeToCrlIssuer` variant. Nightly clippy is flagging this: ``` error: field `0` is never read --> src/x509.rs:89:29 | 89 | NameRelativeToCrlIssuer(untrusted::Input<'a>), | ----------------------- ^^^^^^^^^^^^^^^^^^^^ | | | field in this variant | help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field | 89 | NameRelativeToCrlIssuer(()), | ~~ ``` This commit switches `DistributionPointName::NameRelativeToCrlIssuer` to be a variant without any fields to resolve this finding. --- src/cert.rs | 14 ++++++-------- src/crl/types.rs | 4 ++-- src/x509.rs | 6 ++---- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/cert.rs b/src/cert.rs index df7a5fcb..1021cf4c 100644 --- a/src/cert.rs +++ b/src/cert.rs @@ -408,7 +408,7 @@ mod tests { // We expect the distribution point name to be a sequence of GeneralNames, not a name // relative to the CRL issuer. let names = match distribution_point_name { - DistributionPointName::NameRelativeToCrlIssuer(_) => { + DistributionPointName::NameRelativeToCrlIssuer => { panic!("unexpected name relative to crl issuer") } DistributionPointName::FullName(names) => names, @@ -566,12 +566,10 @@ mod tests { .expect("missing distribution point name"); // We expect the distribution point name to be a name relative to the CRL issuer. - match distribution_point_name { - DistributionPointName::NameRelativeToCrlIssuer(name) => { - assert!(!name.is_empty()); - } - DistributionPointName::FullName(_) => panic!("unexpected full name sequence"), - }; + assert!(matches!( + distribution_point_name, + DistributionPointName::NameRelativeToCrlIssuer + )); } #[test] @@ -633,7 +631,7 @@ mod tests { .expect("failed to parse distribution point names") .expect("missing distribution point name") { - DistributionPointName::NameRelativeToCrlIssuer(_) => { + DistributionPointName::NameRelativeToCrlIssuer => { panic!("unexpected relative name") } DistributionPointName::FullName(names) => names, diff --git a/src/crl/types.rs b/src/crl/types.rs index fd844336..148dcf4a 100644 --- a/src/crl/types.rs +++ b/src/crl/types.rs @@ -538,7 +538,7 @@ impl<'a> IssuingDistributionPoint<'a> { use DistributionPointName::*; match result.names() { Ok(Some(FullName(_))) => Ok(result), - Ok(Some(NameRelativeToCrlIssuer(_))) | Ok(None) => { + Ok(Some(NameRelativeToCrlIssuer)) | Ok(None) => { Err(Error::UnsupportedCrlIssuingDistributionPoint) } Err(_) => Err(Error::MalformedExtensions), @@ -944,7 +944,7 @@ mod tests { .expect("failed to parse distribution point names") .expect("missing distribution point name"); let uri = match dp_name { - DistributionPointName::NameRelativeToCrlIssuer(_) => { + DistributionPointName::NameRelativeToCrlIssuer => { panic!("unexpected relative dp name") } DistributionPointName::FullName(general_names) => { diff --git a/src/x509.rs b/src/x509.rs index c6006a5d..fb9be451 100644 --- a/src/x509.rs +++ b/src/x509.rs @@ -86,7 +86,7 @@ pub(crate) fn remember_extension( /// [^1]: pub(crate) enum DistributionPointName<'a> { /// The distribution point name is a relative distinguished name, relative to the CRL issuer. - NameRelativeToCrlIssuer(untrusted::Input<'a>), + NameRelativeToCrlIssuer, /// The distribution point name is a sequence of [GeneralName] items. FullName(DerIterator<'a, GeneralName<'a>>), } @@ -102,9 +102,7 @@ impl<'a> FromDer<'a> for DistributionPointName<'a> { let (tag, value) = der::read_tag_and_get_value(reader)?; match tag { FULL_NAME_TAG => Ok(DistributionPointName::FullName(DerIterator::new(value))), - NAME_RELATIVE_TO_CRL_ISSUER_TAG => { - Ok(DistributionPointName::NameRelativeToCrlIssuer(value)) - } + NAME_RELATIVE_TO_CRL_ISSUER_TAG => Ok(DistributionPointName::NameRelativeToCrlIssuer), _ => Err(Error::BadDer), } }