Skip to content

Commit 6d941f2

Browse files
authored
Merge pull request sfackler#1795 from AndrewScull/X509NameDup
Add X509Name::to_owned()
2 parents 09f672f + 33e9142 commit 6d941f2

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

openssl/src/x509/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,13 @@ impl X509NameRef {
10641064
Ok(cmp.cmp(&0))
10651065
}
10661066

1067+
/// Copies the name to a new `X509Name`.
1068+
#[corresponds(X509_NAME_dup)]
1069+
#[cfg(any(boringssl, ossl110, libressl270))]
1070+
pub fn to_owned(&self) -> Result<X509Name, ErrorStack> {
1071+
unsafe { cvt_p(ffi::X509_NAME_dup(self.as_ptr())).map(|n| X509Name::from_ptr(n)) }
1072+
}
1073+
10671074
to_der! {
10681075
/// Serializes the certificate into a DER-encoded X509 name structure.
10691076
///

openssl/src/x509/tests.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,16 @@ fn test_name_cmp() {
615615
assert_eq!(Ordering::Greater, subject.try_cmp(issuer).unwrap());
616616
}
617617

618+
#[test]
619+
#[cfg(any(boringssl, ossl110, libressl270))]
620+
fn test_name_to_owned() {
621+
let cert = include_bytes!("../../test/cert.pem");
622+
let cert = X509::from_pem(cert).unwrap();
623+
let name = cert.subject_name();
624+
let copied_name = name.to_owned().unwrap();
625+
assert_eq!(Ordering::Equal, name.try_cmp(&copied_name).unwrap());
626+
}
627+
618628
#[test]
619629
#[cfg(any(ossl102, libressl261))]
620630
fn test_verify_param_set_time_fails_verification() {

0 commit comments

Comments
 (0)