Adjust Nid signature algorithm APIs
This commit is contained in:
parent
c2145384a9
commit
10b2a34529
|
|
@ -1,13 +1,23 @@
|
||||||
//! A collection of numerical identifiers for OpenSSL objects.
|
//! A collection of numerical identifiers for OpenSSL objects.
|
||||||
use ffi;
|
use ffi;
|
||||||
use libc::{c_int,c_char};
|
use libc::{c_char, c_int};
|
||||||
use std::ptr;
|
|
||||||
|
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
use error::ErrorStack;
|
|
||||||
use cvt_p;
|
use cvt_p;
|
||||||
|
use error::ErrorStack;
|
||||||
|
|
||||||
|
/// The digest and public-key algorithms associated with a signature.
|
||||||
|
pub struct SignatureAlgorithms {
|
||||||
|
/// The signature's digest.
|
||||||
|
///
|
||||||
|
/// If the signature does not specify a digest, this will be `NID::UNDEF`.
|
||||||
|
pub digest: Nid,
|
||||||
|
|
||||||
|
/// The signature's public-key.
|
||||||
|
pub pkey: Nid,
|
||||||
|
}
|
||||||
|
|
||||||
/// A numerical identifier for an OpenSSL object.
|
/// A numerical identifier for an OpenSSL object.
|
||||||
///
|
///
|
||||||
|
|
@ -49,14 +59,18 @@ impl Nid {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the `Nid` of the digest algorithm associated with a signature ID.
|
/// Returns the `Nid`s of the digest and public key algorithms associated with a signature ID.
|
||||||
///
|
///
|
||||||
/// This corresponds to `OBJ_find_sigid_algs`.
|
/// This corresponds to `OBJ_find_sigid_algs`.
|
||||||
pub fn digest_algorithm(&self) -> Option<Nid> {
|
pub fn signature_algorithms(&self) -> Option<SignatureAlgorithms> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut digest = 0;
|
let mut digest = 0;
|
||||||
if ffi::OBJ_find_sigid_algs(self.0, &mut digest, ptr::null_mut()) == 1 {
|
let mut pkey = 0;
|
||||||
Some(Nid(digest))
|
if ffi::OBJ_find_sigid_algs(self.0, &mut digest, &mut pkey) == 1 {
|
||||||
|
Some(SignatureAlgorithms {
|
||||||
|
digest: Nid(digest),
|
||||||
|
pkey: Nid(pkey),
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
@ -1041,10 +1055,9 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn signature_digest() {
|
fn signature_digest() {
|
||||||
assert_eq!(
|
let algs = Nid::SHA256WITHRSAENCRYPTION.signature_algorithms().unwrap();
|
||||||
Nid::SHA256WITHRSAENCRYPTION.digest_algorithm(),
|
assert_eq!(algs.digest, Nid::SHA256,);
|
||||||
Some(Nid::SHA256)
|
assert_eq!(algs.pkey, Nid::RSAENCRYPTION);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -1057,11 +1070,26 @@ mod test {
|
||||||
let undefined_nid = Nid::from_raw(118);
|
let undefined_nid = Nid::from_raw(118);
|
||||||
|
|
||||||
assert_eq!(common_name.long_name().unwrap(), "commonName");
|
assert_eq!(common_name.long_name().unwrap(), "commonName");
|
||||||
assert_eq!(organizational_unit_name.long_name().unwrap(), "organizationalUnitName");
|
assert_eq!(
|
||||||
assert_eq!(aes256_cbc_hmac_sha1.long_name().unwrap(), "aes-256-cbc-hmac-sha1");
|
organizational_unit_name.long_name().unwrap(),
|
||||||
assert_eq!(id_cmc_lrapopwitness.long_name().unwrap(), "id-cmc-lraPOPWitness");
|
"organizationalUnitName"
|
||||||
assert_eq!(ms_ctl_sign.long_name().unwrap(), "Microsoft Trust List Signing");
|
);
|
||||||
assert!(undefined_nid.long_name().is_err(), "undefined_nid should not return a valid value");
|
assert_eq!(
|
||||||
|
aes256_cbc_hmac_sha1.long_name().unwrap(),
|
||||||
|
"aes-256-cbc-hmac-sha1"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
id_cmc_lrapopwitness.long_name().unwrap(),
|
||||||
|
"id-cmc-lraPOPWitness"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
ms_ctl_sign.long_name().unwrap(),
|
||||||
|
"Microsoft Trust List Signing"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
undefined_nid.long_name().is_err(),
|
||||||
|
"undefined_nid should not return a valid value"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -1075,9 +1103,18 @@ mod test {
|
||||||
|
|
||||||
assert_eq!(common_name.short_name().unwrap(), "CN");
|
assert_eq!(common_name.short_name().unwrap(), "CN");
|
||||||
assert_eq!(organizational_unit_name.short_name().unwrap(), "OU");
|
assert_eq!(organizational_unit_name.short_name().unwrap(), "OU");
|
||||||
assert_eq!(aes256_cbc_hmac_sha1.short_name().unwrap(), "AES-256-CBC-HMAC-SHA1");
|
assert_eq!(
|
||||||
assert_eq!(id_cmc_lrapopwitness.short_name().unwrap(), "id-cmc-lraPOPWitness");
|
aes256_cbc_hmac_sha1.short_name().unwrap(),
|
||||||
|
"AES-256-CBC-HMAC-SHA1"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
id_cmc_lrapopwitness.short_name().unwrap(),
|
||||||
|
"id-cmc-lraPOPWitness"
|
||||||
|
);
|
||||||
assert_eq!(ms_ctl_sign.short_name().unwrap(), "msCTLSign");
|
assert_eq!(ms_ctl_sign.short_name().unwrap(), "msCTLSign");
|
||||||
assert!(undefined_nid.short_name().is_err(), "undefined_nid should not return a valid value");
|
assert!(
|
||||||
|
undefined_nid.short_name().is_err(),
|
||||||
|
"undefined_nid should not return a valid value"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue