Expose X509NameRef::print_ex

This commit is contained in:
Rushil Mehra 2024-08-13 17:35:43 -07:00 committed by Rushil Mehra
parent fae2f7fbf1
commit 96981dd6c6
1 changed files with 15 additions and 1 deletions

View File

@ -26,7 +26,7 @@ use crate::asn1::{
Asn1BitStringRef, Asn1IntegerRef, Asn1Object, Asn1ObjectRef, Asn1StringRef, Asn1TimeRef, Asn1BitStringRef, Asn1IntegerRef, Asn1Object, Asn1ObjectRef, Asn1StringRef, Asn1TimeRef,
Asn1Type, Asn1Type,
}; };
use crate::bio::MemBioSlice; use crate::bio::{MemBio, MemBioSlice};
use crate::conf::ConfRef; use crate::conf::ConfRef;
use crate::error::ErrorStack; use crate::error::ErrorStack;
use crate::ex_data::Index; use crate::ex_data::Index;
@ -1044,6 +1044,20 @@ impl X509NameRef {
} }
} }
/// Returns an owned String representing the X509 name configurable via incoming flags.
///
/// This function will return `None` if the underlying string contains invalid utf-8.
#[corresponds(X509_NAME_print_ex)]
pub fn print_ex(&self, flags: i32) -> Option<String> {
unsafe {
let bio = MemBio::new().ok()?;
ffi::X509_NAME_print_ex(bio.as_ptr(), self.as_ptr(), 0, flags as _);
let buf = bio.get_buf().to_vec();
let res = String::from_utf8(buf);
res.ok()
}
}
to_der! { to_der! {
/// Serializes the certificate into a DER-encoded X509 name structure. /// Serializes the certificate into a DER-encoded X509 name structure.
/// ///