Skip to content

Commit

Permalink
Simplify NameIterator state
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Jan 20, 2025
1 parent b73e2c4 commit ce94ca2
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions src/subject_name/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,29 +227,27 @@ impl<'a> Iterator for NameIterator<'a> {
type Item = Result<GeneralName<'a>, Error>;

fn next(&mut self) -> Option<Self::Item> {
if let Some(subject_alt_name) = &mut self.subject_alt_name {
// https://bugzilla.mozilla.org/show_bug.cgi?id=1143085: An empty
// subjectAltName is not legal, but some certificates have an empty
// subjectAltName. Since we don't support CN-IDs, the certificate
// will be rejected either way, but checking `at_end` before
// attempting to parse the first entry allows us to return a better
// error code.

if !subject_alt_name.at_end() {
let err = match GeneralName::from_der(subject_alt_name) {
Ok(name) => return Some(Ok(name)),
Err(err) => err,
};

// Make sure we don't yield any items after this error.
self.subject_alt_name = None;
return Some(Err(err));
} else {
self.subject_alt_name = None;
}
let subject_alt_name = self.subject_alt_name.as_mut()?;
// https://bugzilla.mozilla.org/show_bug.cgi?id=1143085: An empty
// subjectAltName is not legal, but some certificates have an empty
// subjectAltName. Since we don't support CN-IDs, the certificate
// will be rejected either way, but checking `at_end` before
// attempting to parse the first entry allows us to return a better
// error code.

if subject_alt_name.at_end() {
self.subject_alt_name = None;
return None;
}

None
let err = match GeneralName::from_der(subject_alt_name) {
Ok(name) => return Some(Ok(name)),
Err(err) => err,
};

// Make sure we don't yield any items after this error.
self.subject_alt_name = None;
Some(Err(err))

Check warning on line 250 in src/subject_name/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/subject_name/mod.rs#L245-L250

Added lines #L245 - L250 were not covered by tests
}
}

Expand Down

0 comments on commit ce94ca2

Please sign in to comment.