aboutsummaryrefslogtreecommitdiff
path: root/openssl/src
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2018-01-15 10:41:08 -0800
committerGitHub <[email protected]>2018-01-15 10:41:08 -0800
commit0d91e775cac1d314a0d93ec6455b4b6d38a4bfa7 (patch)
treed6a258e4d0db3f8e3c8c6d9b1654c35aeb8bdafb /openssl/src
parentRelease openssl v0.10.2 (diff)
parentadd support for rfc822Name (email) and uniformResourceIdentifier (uri) to Gen... (diff)
downloadrust-openssl-0d91e775cac1d314a0d93ec6455b4b6d38a4bfa7.tar.xz
rust-openssl-0d91e775cac1d314a0d93ec6455b4b6d38a4bfa7.zip
Merge pull request #827 from ian-p-cooke/master
add email and uri to GeneralName
Diffstat (limited to 'openssl/src')
-rw-r--r--openssl/src/x509/mod.rs23
-rw-r--r--openssl/src/x509/tests.rs16
2 files changed, 32 insertions, 7 deletions
diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs
index 7c897e31..f3a8b8e6 100644
--- a/openssl/src/x509/mod.rs
+++ b/openssl/src/x509/mod.rs
@@ -1090,10 +1090,10 @@ foreign_type_and_impl_send_sync! {
}
impl GeneralNameRef {
- /// Returns the contents of this `GeneralName` if it is a `dNSName`.
- pub fn dnsname(&self) -> Option<&str> {
+
+ fn ia5_string(&self, ffi_type: c_int) -> Option<&str> {
unsafe {
- if (*self.as_ptr()).type_ != ffi::GEN_DNS {
+ if (*self.as_ptr()).type_ != ffi_type {
return None;
}
@@ -1101,13 +1101,28 @@ impl GeneralNameRef {
let len = ffi::ASN1_STRING_length((*self.as_ptr()).d as *mut _);
let slice = slice::from_raw_parts(ptr as *const u8, len as usize);
- // dNSNames are stated to be ASCII (specifically IA5). Hopefully
+ // IA5Strings are stated to be ASCII (specifically IA5). Hopefully
// OpenSSL checks that when loading a certificate but if not we'll
// use this instead of from_utf8_unchecked just in case.
str::from_utf8(slice).ok()
}
}
+ /// Returns the contents of this `GeneralName` if it is an `rfc822Name`.
+ pub fn email(&self) -> Option<&str> {
+ self.ia5_string(ffi::GEN_EMAIL)
+ }
+
+ /// Returns the contents of this `GeneralName` if it is a `dNSName`.
+ pub fn dnsname(&self) -> Option<&str> {
+ self.ia5_string(ffi::GEN_DNS)
+ }
+
+ /// Returns the contents of this `GeneralName` if it is an `uniformResourceIdentifier`.
+ pub fn uri(&self) -> Option<&str> {
+ self.ia5_string(ffi::GEN_URI)
+ }
+
/// Returns the contents of this `GeneralName` if it is an `iPAddress`.
pub fn ipaddress(&self) -> Option<&[u8]> {
unsafe {
diff --git a/openssl/src/x509/tests.rs b/openssl/src/x509/tests.rs
index 2d9348e8..6f6b430a 100644
--- a/openssl/src/x509/tests.rs
+++ b/openssl/src/x509/tests.rs
@@ -92,13 +92,15 @@ fn test_subject_alt_name() {
let cert = X509::from_pem(cert).unwrap();
let subject_alt_names = cert.subject_alt_names().unwrap();
- assert_eq!(3, subject_alt_names.len());
- assert_eq!(Some("foobar.com"), subject_alt_names[0].dnsname());
+ assert_eq!(5, subject_alt_names.len());
+ assert_eq!(Some("example.com"), subject_alt_names[0].dnsname());
assert_eq!(subject_alt_names[1].ipaddress(), Some(&[127, 0, 0, 1][..]));
assert_eq!(
subject_alt_names[2].ipaddress(),
Some(&b"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x01"[..])
);
+ assert_eq!(Some("[email protected]"), subject_alt_names[3].email());
+ assert_eq!(Some("http://www.example.com"), subject_alt_names[4].uri());
}
#[test]
@@ -110,7 +112,7 @@ fn test_subject_alt_name_iter() {
let mut subject_alt_names_iter = subject_alt_names.iter();
assert_eq!(
subject_alt_names_iter.next().unwrap().dnsname(),
- Some("foobar.com")
+ Some("example.com")
);
assert_eq!(
subject_alt_names_iter.next().unwrap().ipaddress(),
@@ -120,6 +122,14 @@ fn test_subject_alt_name_iter() {
subject_alt_names_iter.next().unwrap().ipaddress(),
Some(&b"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x01"[..])
);
+ assert_eq!(
+ subject_alt_names_iter.next().unwrap().email(),
+ );
+ assert_eq!(
+ subject_alt_names_iter.next().unwrap().uri(),
+ Some("http://www.example.com")
+ );
assert!(subject_alt_names_iter.next().is_none());
}