@@ -31,6 +31,8 @@ use crate::conf::ConfRef;
31
31
use crate :: error:: ErrorStack ;
32
32
use crate :: ex_data:: Index ;
33
33
use crate :: hash:: { DigestBytes , MessageDigest } ;
34
+ #[ cfg( ossl300) ]
35
+ use crate :: lib_ctx:: LibCtxRef ;
34
36
use crate :: nid:: Nid ;
35
37
use crate :: pkey:: { HasPrivate , HasPublic , PKey , PKeyRef , Public } ;
36
38
use crate :: ssl:: SslRef ;
@@ -1218,6 +1220,51 @@ impl Stackable for X509Name {
1218
1220
}
1219
1221
1220
1222
impl X509NameRef {
1223
+ /// Returns the hash of the X509 name
1224
+ #[ cfg( ossl300) ]
1225
+ #[ corresponds( X509_NAME_hash_ex ) ]
1226
+ pub fn hash_ex ( & self , ctx : Option < LibCtxRef > , propq : Option < & str > ) -> Result < u32 , ErrorStack > {
1227
+ let ctx_ref = ctx. map_or ( ptr:: null_mut ( ) , |ctx| ctx. as_ptr ( ) ) ;
1228
+
1229
+ let cstr;
1230
+ let propq = if let Some ( propq) = propq {
1231
+ cstr = CString :: new ( propq) . unwrap ( ) ;
1232
+ cstr. as_ptr ( )
1233
+ } else {
1234
+ ptr:: null ( )
1235
+ } ;
1236
+
1237
+ let mut ok: c_int = 0 ;
1238
+ let hash;
1239
+
1240
+ #[ allow( clippy:: unnecessary_cast) ]
1241
+ unsafe {
1242
+ hash = ffi:: X509_NAME_hash_ex ( self . as_ptr ( ) , ctx_ref, propq, & mut ok) as u32 ;
1243
+ }
1244
+
1245
+ if ok != 1 {
1246
+ return Err ( ErrorStack :: get ( ) ) ;
1247
+ }
1248
+
1249
+ Ok ( hash)
1250
+ }
1251
+
1252
+ /// Returns the hash of the X509 name
1253
+ #[ cfg( ossl300) ]
1254
+ #[ corresponds( X509_NAME_hash ) ]
1255
+ pub fn hash ( & self ) -> u32 {
1256
+ self . hash_ex ( None , None ) . unwrap_or ( 0 )
1257
+ }
1258
+
1259
+ #[ cfg( not( ossl300) ) ]
1260
+ #[ corresponds( X509_NAME_hash ) ]
1261
+ pub fn hash ( & self ) -> u32 {
1262
+ #[ allow( clippy:: unnecessary_cast) ]
1263
+ unsafe {
1264
+ ffi:: X509_NAME_hash ( self . as_ptr ( ) ) as u32
1265
+ }
1266
+ }
1267
+
1221
1268
/// Returns the name entries by the nid.
1222
1269
pub fn entries_by_nid ( & self , nid : Nid ) -> X509NameEntries < ' _ > {
1223
1270
X509NameEntries {
0 commit comments