Skip to content

Commit a14f5b4

Browse files
committed
Expose alias on X509 structs
1 parent 3acf2ef commit a14f5b4

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

openssl-sys/src/handwritten/x509.rs

+1
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ extern "C" {
311311
pub fn X509_get_version(x: *const X509) -> c_long;
312312
pub fn X509_set_serialNumber(x: *mut X509, sn: *mut ASN1_INTEGER) -> c_int;
313313
pub fn X509_get_serialNumber(x: *mut X509) -> *mut ASN1_INTEGER;
314+
pub fn X509_alias_get0(x: *mut X509, len: *mut c_int) -> *mut c_uchar;
314315
}
315316
const_ptr_api! {
316317
extern "C" {

openssl/src/pkcs12.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,20 @@ mod test {
304304
let parsed = pkcs12.parse2("mypass").unwrap();
305305

306306
assert_eq!(
307-
hex::encode(parsed.cert.unwrap().digest(MessageDigest::sha1()).unwrap()),
307+
hex::encode(
308+
parsed
309+
.cert
310+
.as_ref()
311+
.unwrap()
312+
.digest(MessageDigest::sha1())
313+
.unwrap()
314+
),
308315
"59172d9313e84459bcff27f967e79e6e9217e584"
309316
);
317+
assert_eq!(
318+
parsed.cert.as_ref().unwrap().alias(),
319+
Some(b"foobar.com" as &[u8])
320+
);
310321

311322
let chain = parsed.ca.unwrap();
312323
assert_eq!(chain.len(), 1);

openssl/src/x509/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,21 @@ impl X509Ref {
649649
}
650650
}
651651

652+
/// Return's this certificate's "alias". This field is populated by
653+
/// OpenSSL in some contexts, such as PKCS12 parsing.
654+
#[corresponds(X509_alias_get0)]
655+
pub fn alias(&self) -> Option<&[u8]> {
656+
unsafe {
657+
let mut len = 0;
658+
let ptr = ffi::X509_alias_get0(self.as_ptr(), &mut len);
659+
if ptr.is_null() {
660+
None
661+
} else {
662+
Some(slice::from_raw_parts(ptr, len as usize))
663+
}
664+
}
665+
}
666+
652667
to_pem! {
653668
/// Serializes the certificate into a PEM-encoded X509 structure.
654669
///

0 commit comments

Comments
 (0)