From 786ee180cd88787849dec390c8946c3de8b6d97c Mon Sep 17 00:00:00 2001 From: Rushil Mehra Date: Tue, 13 Aug 2024 17:35:43 -0700 Subject: [PATCH] Expose X509NameRef::print_ex --- boring/src/x509/mod.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/boring/src/x509/mod.rs b/boring/src/x509/mod.rs index a90a4934..b234bd2b 100644 --- a/boring/src/x509/mod.rs +++ b/boring/src/x509/mod.rs @@ -26,7 +26,7 @@ use crate::asn1::{ Asn1BitStringRef, Asn1IntegerRef, Asn1Object, Asn1ObjectRef, Asn1StringRef, Asn1TimeRef, Asn1Type, }; -use crate::bio::MemBioSlice; +use crate::bio::{MemBio, MemBioSlice}; use crate::conf::ConfRef; use crate::error::ErrorStack; 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 { + 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! { /// Serializes the certificate into a DER-encoded X509 name structure. ///