aboutsummaryrefslogtreecommitdiff
path: root/openssl/src
diff options
context:
space:
mode:
authorCorey Farwell <[email protected]>2016-04-30 23:54:29 -0400
committerCorey Farwell <[email protected]>2016-05-01 00:02:10 -0400
commitbf7076b7853c27546ed5ce3d235e20b409682729 (patch)
treeea446fac11339283f17f76d85d23d45118d70c73 /openssl/src
parentAdd X509StoreContext::error_depth (diff)
downloadrust-openssl-bf7076b7853c27546ed5ce3d235e20b409682729.tar.xz
rust-openssl-bf7076b7853c27546ed5ce3d235e20b409682729.zip
Implement `iter` method on `GeneralNames`.
Diffstat (limited to 'openssl/src')
-rw-r--r--openssl/src/x509/mod.rs26
-rw-r--r--openssl/src/x509/tests.rs13
2 files changed, 39 insertions, 0 deletions
diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs
index af1e6ed1..93526d7f 100644
--- a/openssl/src/x509/mod.rs
+++ b/openssl/src/x509/mod.rs
@@ -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> {
diff --git a/openssl/src/x509/tests.rs b/openssl/src/x509/tests.rs
index 5f4d432e..aa41bfc6 100644
--- a/openssl/src/x509/tests.rs
+++ b/openssl/src/x509/tests.rs
@@ -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());
+}