Skip to content

Commit ce94ca2

Browse files
committed
Simplify NameIterator state
1 parent b73e2c4 commit ce94ca2

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

src/subject_name/mod.rs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -227,29 +227,27 @@ impl<'a> Iterator for NameIterator<'a> {
227227
type Item = Result<GeneralName<'a>, Error>;
228228

229229
fn next(&mut self) -> Option<Self::Item> {
230-
if let Some(subject_alt_name) = &mut self.subject_alt_name {
231-
// https://bugzilla.mozilla.org/show_bug.cgi?id=1143085: An empty
232-
// subjectAltName is not legal, but some certificates have an empty
233-
// subjectAltName. Since we don't support CN-IDs, the certificate
234-
// will be rejected either way, but checking `at_end` before
235-
// attempting to parse the first entry allows us to return a better
236-
// error code.
237-
238-
if !subject_alt_name.at_end() {
239-
let err = match GeneralName::from_der(subject_alt_name) {
240-
Ok(name) => return Some(Ok(name)),
241-
Err(err) => err,
242-
};
243-
244-
// Make sure we don't yield any items after this error.
245-
self.subject_alt_name = None;
246-
return Some(Err(err));
247-
} else {
248-
self.subject_alt_name = None;
249-
}
230+
let subject_alt_name = self.subject_alt_name.as_mut()?;
231+
// https://bugzilla.mozilla.org/show_bug.cgi?id=1143085: An empty
232+
// subjectAltName is not legal, but some certificates have an empty
233+
// subjectAltName. Since we don't support CN-IDs, the certificate
234+
// will be rejected either way, but checking `at_end` before
235+
// attempting to parse the first entry allows us to return a better
236+
// error code.
237+
238+
if subject_alt_name.at_end() {
239+
self.subject_alt_name = None;
240+
return None;
250241
}
251242

252-
None
243+
let err = match GeneralName::from_der(subject_alt_name) {
244+
Ok(name) => return Some(Ok(name)),
245+
Err(err) => err,
246+
};
247+
248+
// Make sure we don't yield any items after this error.
249+
self.subject_alt_name = None;
250+
Some(Err(err))
253251
}
254252
}
255253

0 commit comments

Comments
 (0)