Skip to content

Commit

Permalink
x509: remove unused NameRelativeToCrlIssuer field
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cpu committed Jan 8, 2024
1 parent 34d2188 commit 4d1ecc2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
14 changes: 6 additions & 8 deletions src/cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/crl/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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) => {
Expand Down
6 changes: 2 additions & 4 deletions src/x509.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub(crate) fn remember_extension(
/// [^1]: <https://datatracker.ietf.org/doc/html/rfc5280#section-4.2.1.13>
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>>),
}
Expand All @@ -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),
}
}
Expand Down

0 comments on commit 4d1ecc2

Please sign in to comment.