aboutsummaryrefslogtreecommitdiff
path: root/openssl
diff options
context:
space:
mode:
authorMarco Huenseler <[email protected]>2018-05-28 11:20:18 +0200
committerMarco Huenseler <[email protected]>2018-06-03 15:38:46 +0200
commitf5e6d57c4774c3f58fd03fa2520d8ec915ca1827 (patch)
tree025435294c3538ddc36ead0fbf20bdaf6c662c6c /openssl
parentMake X509NameRef provide an iterator over all X509NameEntries (diff)
downloadrust-openssl-f5e6d57c4774c3f58fd03fa2520d8ec915ca1827.tar.xz
rust-openssl-f5e6d57c4774c3f58fd03fa2520d8ec915ca1827.zip
Provide an Asn1Object getter method for X509NameEntryRef
Diffstat (limited to 'openssl')
-rw-r--r--openssl/src/x509/mod.rs13
-rw-r--r--openssl/src/x509/tests.rs3
2 files changed, 16 insertions, 0 deletions
diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs
index b0519856..697aba6f 100644
--- a/openssl/src/x509/mod.rs
+++ b/openssl/src/x509/mod.rs
@@ -895,6 +895,19 @@ impl X509NameEntryRef {
Asn1StringRef::from_ptr(data)
}
}
+
+ /// Returns the `Asn1Object` value of an `X509NameEntry`.
+ /// This is useful for finding out about the actual `Nid` when iterating over all `X509NameEntries`.
+ ///
+ /// This corresponds to [`X509_NAME_ENTRY_get_object`].
+ ///
+ /// [`X509_NAME_ENTRY_get_object`]: https://www.openssl.org/docs/man1.1.0/crypto/X509_NAME_ENTRY_get_object.html
+ pub fn object(&self) -> &Asn1ObjectRef {
+ unsafe {
+ let object = ffi::X509_NAME_ENTRY_get_object(self.as_ptr());
+ Asn1ObjectRef::from_ptr(object)
+ }
+ }
}
/// A builder used to construct an `X509Req`.
diff --git a/openssl/src/x509/tests.rs b/openssl/src/x509/tests.rs
index 3e2ead9d..bfc50899 100644
--- a/openssl/src/x509/tests.rs
+++ b/openssl/src/x509/tests.rs
@@ -87,12 +87,15 @@ fn test_nameref_iterator() {
let mut all_entries = subject.all_entries();
let email = all_entries.next().unwrap();
+ assert_eq!(email.object().nid().as_raw(), Nid::PKCS9_EMAILADDRESS.as_raw());
assert_eq!(email.data().as_slice(), b"[email protected]");
let cn = all_entries.next().unwrap();
+ assert_eq!(cn.object().nid().as_raw(), Nid::COMMONNAME.as_raw());
assert_eq!(cn.data().as_slice(), b"example.com");
let friendly = all_entries.next().unwrap();
+ assert_eq!(friendly.object().nid().as_raw(), Nid::FRIENDLYNAME.as_raw());
assert_eq!(&**friendly.data().as_utf8().unwrap(), "Example");
if let Some(_) = all_entries.next() {