Merge pull request #386 from frewsxcv/general-names
Implement `iter` method on `GeneralNames`.
This commit is contained in:
commit
5c1c89b0e2
|
|
@ -810,6 +810,32 @@ impl<'a> GeneralNames<'a> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> GeneralNamesIter {
|
||||
GeneralNamesIter {
|
||||
names: self,
|
||||
idx: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct GeneralNamesIter<'a> {
|
||||
names: &'a GeneralNames<'a>,
|
||||
idx: usize,
|
||||
}
|
||||
|
||||
impl<'a> Iterator for GeneralNamesIter<'a> {
|
||||
type Item = GeneralName<'a>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.idx < self.names.len() {
|
||||
let name = self.names.get(self.idx);
|
||||
self.idx += 1;
|
||||
Some(name)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct GeneralName<'a> {
|
||||
|
|
|
|||
|
|
@ -169,3 +169,16 @@ fn test_subject_alt_name() {
|
|||
assert_eq!(subject_alt_names.get(1).ipadd(), Some(&[127, 0, 0, 1][..]));
|
||||
assert_eq!(subject_alt_names.get(2).ipadd(), Some(&b"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x01"[..]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_subject_alt_name_iter() {
|
||||
let mut file = File::open("test/alt_name_cert.pem").unwrap();
|
||||
let cert = X509::from_pem(&mut file).unwrap();
|
||||
|
||||
let subject_alt_names = cert.subject_alt_names().unwrap();
|
||||
let mut subject_alt_names_iter = subject_alt_names.iter();
|
||||
assert_eq!(subject_alt_names_iter.next().unwrap().dns(), Some("foobar.com"));
|
||||
assert_eq!(subject_alt_names_iter.next().unwrap().ipadd(), Some(&[127, 0, 0, 1][..]));
|
||||
assert_eq!(subject_alt_names_iter.next().unwrap().ipadd(), Some(&b"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x01"[..]));
|
||||
assert!(subject_alt_names_iter.next().is_none());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue