Rename X509NameRef::all_entries and refactor end-of-iterator checks

This commit is contained in:
Marco Huenseler 2018-06-03 15:37:18 +02:00
parent f5e6d57c47
commit 14b5439347
2 changed files with 8 additions and 6 deletions

View File

@ -826,7 +826,7 @@ impl X509NameRef {
}
/// Returns an iterator over all `X509NameEntry` values
pub fn all_entries<'a>(&'a self) -> X509NameEntries<'a> {
pub fn entries<'a>(&'a self) -> X509NameEntries<'a> {
X509NameEntries {
name: self,
nid: None,
@ -854,17 +854,19 @@ impl<'a> Iterator for X509NameEntries<'a> {
// There is a `Nid` specified to search for
self.loc =
ffi::X509_NAME_get_index_by_NID(self.name.as_ptr(), nid.as_raw(), self.loc);
if self.loc == -1 {
return None;
}
}
None => {
// Iterate over all `Nid`s
self.loc += 1;
if self.loc >= entry_count {
return None;
}
}
}
if self.loc == -1 || self.loc >= entry_count {
return None;
}
let entry = ffi::X509_NAME_get_entry(self.name.as_ptr(), self.loc);
assert!(!entry.is_null());

View File

@ -84,7 +84,7 @@ fn test_nameref_iterator() {
let cert = include_bytes!("../../test/nid_test_cert.pem");
let cert = X509::from_pem(cert).unwrap();
let subject = cert.subject_name();
let mut all_entries = subject.all_entries();
let mut all_entries = subject.entries();
let email = all_entries.next().unwrap();
assert_eq!(email.object().nid().as_raw(), Nid::PKCS9_EMAILADDRESS.as_raw());