diff options
| author | Bastian Köcher <[email protected]> | 2018-03-10 00:26:20 +0100 |
|---|---|---|
| committer | Bastian Köcher <[email protected]> | 2018-03-10 00:27:15 +0100 |
| commit | 7fe3fabf245a1e65ad8441dc8c00f1b3ab28d70d (patch) | |
| tree | f35cec386adc7c4fe0a433ebe0a890e976c275a3 /openssl/src | |
| parent | Adds `RsaPssSaltlen` enum to encode the special values (diff) | |
| download | rust-openssl-7fe3fabf245a1e65ad8441dc8c00f1b3ab28d70d.tar.xz rust-openssl-7fe3fabf245a1e65ad8441dc8c00f1b3ab28d70d.zip | |
Switches to new type wrapper for RsaPssSaltlen
Diffstat (limited to 'openssl/src')
| -rw-r--r-- | openssl/src/pkey.rs | 3 | ||||
| -rw-r--r-- | openssl/src/sign.rs | 35 |
2 files changed, 18 insertions, 20 deletions
diff --git a/openssl/src/pkey.rs b/openssl/src/pkey.rs index 76ecef7c..506c6db7 100644 --- a/openssl/src/pkey.rs +++ b/openssl/src/pkey.rs @@ -178,8 +178,7 @@ impl<T> PKeyRef<T> { } } - /// Returns `Some(Oid)` as the type of this key or `None`, if the Oid is supported by this - /// library. + /// Returns the Oid that represents the type of this key. /// /// This corresponds to [`EVP_PKEY_id`]. /// diff --git a/openssl/src/sign.rs b/openssl/src/sign.rs index 488e7291..d4c36cad 100644 --- a/openssl/src/sign.rs +++ b/openssl/src/sign.rs @@ -80,26 +80,25 @@ use ffi::{EVP_MD_CTX_free, EVP_MD_CTX_new}; use ffi::{EVP_MD_CTX_create as EVP_MD_CTX_new, EVP_MD_CTX_destroy as EVP_MD_CTX_free}; /// Salt lengths that must be used with `set_rsa_pss_saltlen`. -pub enum RsaPssSaltlen { - /// The salt length is set to the digest length. - /// Corresponds to the special value `-1`. - DigestLength, - /// The salt length is set to the maximum permissible value. - /// Corresponds to the special value `-2`. - MaximumLength, - /// Sets the salt length to the given value. - Custom(u32) -} +pub struct RsaPssSaltlen(c_int); impl RsaPssSaltlen { - /// Returns the integer representation of `Oid`. + /// Returns the integer representation of `RsaPssSaltlen`. fn as_raw(&self) -> c_int { - match *self { - RsaPssSaltlen::DigestLength => -1, - RsaPssSaltlen::MaximumLength => -2, - RsaPssSaltlen::Custom(val) => val as c_int, - } + self.0 } + + /// Sets the salt length to the given value. + pub fn custom(val: c_int) -> RsaPssSaltlen { + RsaPssSaltlen(val) + } + + /// The salt length is set to the digest length. + /// Corresponds to the special value `-1`. + pub const DIGEST_LENGTH: RsaPssSaltlen = RsaPssSaltlen(-1); + /// The salt length is set to the maximum permissible value. + /// Corresponds to the special value `-2`. + pub const MAXIMUM_LENGTH: RsaPssSaltlen = RsaPssSaltlen(-2); } /// A type which computes cryptographic signatures of data. @@ -657,14 +656,14 @@ mod test { let mut signer = Signer::new(MessageDigest::sha256(), &pkey).unwrap(); signer.set_rsa_padding(Padding::PKCS1_PSS).unwrap(); assert_eq!(signer.rsa_padding().unwrap(), Padding::PKCS1_PSS); - signer.set_rsa_pss_saltlen(RsaPssSaltlen::DigestLength).unwrap(); + signer.set_rsa_pss_saltlen(RsaPssSaltlen::DIGEST_LENGTH).unwrap(); signer.set_rsa_mgf1_md(MessageDigest::sha256()).unwrap(); signer.update(&Vec::from_hex(INPUT).unwrap()).unwrap(); let signature = signer.sign_to_vec().unwrap(); let mut verifier = Verifier::new(MessageDigest::sha256(), &pkey).unwrap(); verifier.set_rsa_padding(Padding::PKCS1_PSS).unwrap(); - verifier.set_rsa_pss_saltlen(RsaPssSaltlen::DigestLength).unwrap(); + verifier.set_rsa_pss_saltlen(RsaPssSaltlen::DIGEST_LENGTH).unwrap(); verifier.set_rsa_mgf1_md(MessageDigest::sha256()).unwrap(); verifier.update(&Vec::from_hex(INPUT).unwrap()).unwrap(); assert!(verifier.verify(&signature).unwrap()); |