Skip to content

Commit 3b9584f

Browse files
committed
Add X509_NAME_hash_ex to X509NameRef
Add the ability to call X509_NAME_hash_ex so that we can also get hashes from issuer names, and not just X509 Certificate subject names.
1 parent 875f91d commit 3b9584f

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

openssl-sys/src/handwritten/x509.rs

+7
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,13 @@ extern "C" {
285285

286286
pub fn X509_NAME_new() -> *mut X509_NAME;
287287
pub fn X509_NAME_cmp(x: *const X509_NAME, y: *const X509_NAME) -> c_int;
288+
#[cfg(ossl300)]
289+
pub fn X509_NAME_hash_ex(
290+
x: *const X509_NAME,
291+
ctx: *mut OSSL_LIB_CTX,
292+
propq: *const c_char,
293+
ok: *mut c_int,
294+
) -> c_ulong;
288295
pub fn X509_NAME_free(x: *mut X509_NAME);
289296

290297
pub fn X509_new() -> *mut X509;

openssl/src/x509/mod.rs

+29
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use crate::conf::ConfRef;
3131
use crate::error::ErrorStack;
3232
use crate::ex_data::Index;
3333
use crate::hash::{DigestBytes, MessageDigest};
34+
use crate::lib_ctx::LibCtxRef;
3435
use crate::nid::Nid;
3536
use crate::pkey::{HasPrivate, HasPublic, PKey, PKeyRef, Public};
3637
use crate::ssl::SslRef;
@@ -1218,6 +1219,34 @@ impl Stackable for X509Name {
12181219
}
12191220

12201221
impl X509NameRef {
1222+
/// Returns the hash of the X509 name
1223+
#[corresponds(X509_NAME_hash)]
1224+
pub fn hash(&self, ctx: Option<LibCtxRef>, propq: Option<&str>) -> Result<u32, ErrorStack> {
1225+
let ctx_ref = ctx.map_or(ptr::null_mut(), |ctx| ctx.as_ptr());
1226+
1227+
let cstr;
1228+
let propq = if let Some(propq) = propq {
1229+
cstr = CString::new(propq).unwrap();
1230+
cstr.as_ptr()
1231+
} else {
1232+
ptr::null()
1233+
};
1234+
1235+
let mut ok: c_int = 0;
1236+
let hash;
1237+
1238+
#[allow(clippy::unnecessary_cast)]
1239+
unsafe {
1240+
hash = ffi::X509_NAME_hash_ex(self.as_ptr(), ctx_ref, propq, &mut ok) as u32;
1241+
}
1242+
1243+
if ok != 1 {
1244+
return Err(ErrorStack::get());
1245+
}
1246+
1247+
Ok(hash)
1248+
}
1249+
12211250
/// Returns the name entries by the nid.
12221251
pub fn entries_by_nid(&self, nid: Nid) -> X509NameEntries<'_> {
12231252
X509NameEntries {

0 commit comments

Comments
 (0)