summaryrefslogtreecommitdiff
path: root/openssl
diff options
context:
space:
mode:
authorJoshua Nitschke <JoshuaNitschke@gmail.com>2020-11-12 09:26:23 -0800
committerJoshua Nitschke <JoshuaNitschke@gmail.com>2020-11-29 17:14:56 -0800
commit7d33b4c84be27dccb68ad8b2d9654f5aeb341d60 (patch)
treed5736c31f54bfbdcdd7aafef8c728a04c40bf863 /openssl
parent624effd3a6314ddfa4abbbf3b1eddf414edf8842 (diff)
downloadrust-openssl-7d33b4c84be27dccb68ad8b2d9654f5aeb341d60.zip
Add additional function so that x509 name with specific type can be added
Fixes issue #1370
Diffstat (limited to 'openssl')
-rw-r--r--openssl/src/x509/mod.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs
index 321161a2..d89ba54c 100644
--- a/openssl/src/x509/mod.rs
+++ b/openssl/src/x509/mod.rs
@@ -857,6 +857,28 @@ impl X509NameBuilder {
}
}
+ /// Add a field entry by str with a specific type. (ex: 19 for V_ASN1_PRINTABLESTRING)
+ ///
+ /// This corresponds to [`X509_NAME_add_entry_by_txt`].
+ ///
+ /// [`X509_NAME_add_entry_by_txt`]: https://www.openssl.org/docs/man1.1.0/crypto/X509_NAME_add_entry_by_txt.html
+ pub fn append_entry_by_text_with_type(&mut self, field: &str, value: &str, ty: i32) -> Result<(), ErrorStack> {
+ unsafe {
+ let field = CString::new(field).unwrap();
+ assert!(value.len() <= c_int::max_value() as usize);
+ cvt(ffi::X509_NAME_add_entry_by_txt(
+ self.0.as_ptr(),
+ field.as_ptr() as *mut _,
+ ty,
+ value.as_ptr(),
+ value.len() as c_int,
+ -1,
+ 0,
+ ))
+ .map(|_| ())
+ }
+ }
+
/// Add a field entry by NID.
///
/// This corresponds to [`X509_NAME_add_entry_by_NID`].
@@ -878,6 +900,27 @@ impl X509NameBuilder {
}
}
+ /// Add a field entry by NID with a specific type. (ex: 19 for V_ASN1_PRINTABLESTRING)
+ ///
+ /// This corresponds to [`X509_NAME_add_entry_by_NID`].
+ ///
+ /// [`X509_NAME_add_entry_by_NID`]: https://www.openssl.org/docs/man1.1.0/crypto/X509_NAME_add_entry_by_NID.html
+ pub fn append_entry_by_nid_with_type(&mut self, field: Nid, value: &str, ty: i32) -> Result<(), ErrorStack> {
+ unsafe {
+ assert!(value.len() <= c_int::max_value() as usize);
+ cvt(ffi::X509_NAME_add_entry_by_NID(
+ self.0.as_ptr(),
+ field.as_raw(),
+ ty,
+ value.as_ptr() as *mut _,
+ value.len() as c_int,
+ -1,
+ 0,
+ ))
+ .map(|_| ())
+ }
+ }
+
/// Return an `X509Name`.
pub fn build(self) -> X509Name {
self.0