aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/x509
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2016-10-15 15:23:29 -0700
committerSteven Fackler <[email protected]>2016-10-15 15:23:29 -0700
commitc171be551ac8d22c91cbf550e21215ae2c8b6abc (patch)
tree1a07d9075b2e6e0a2b4dba855f073e27fcc1c5c9 /openssl/src/x509
parentMigrate DSA sign/verify to EVP APIs (diff)
downloadrust-openssl-c171be551ac8d22c91cbf550e21215ae2c8b6abc.tar.xz
rust-openssl-c171be551ac8d22c91cbf550e21215ae2c8b6abc.zip
De-enumify message digests
Diffstat (limited to 'openssl/src/x509')
-rw-r--r--openssl/src/x509/mod.rs23
-rw-r--r--openssl/src/x509/tests.rs6
2 files changed, 13 insertions, 16 deletions
diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs
index 9fed94e2..c429b486 100644
--- a/openssl/src/x509/mod.rs
+++ b/openssl/src/x509/mod.rs
@@ -10,13 +10,10 @@ use std::slice;
use std::collections::HashMap;
use std::marker::PhantomData;
-use HashTypeInternals;
use asn1::Asn1Time;
use asn1::Asn1TimeRef;
-
use bio::{MemBio, MemBioSlice};
-use crypto::hash;
-use crypto::hash::Type as HashType;
+use crypto::hash::MessageDigest;
use crypto::pkey::PKey;
use crypto::rand::rand_bytes;
use ffi;
@@ -129,7 +126,7 @@ impl X509StoreContext {
/// # Example
///
/// ```
-/// use openssl::crypto::hash::Type;
+/// use openssl::crypto::hash::MessageDigest;
/// use openssl::crypto::pkey::PKey;
/// use openssl::crypto::rsa::RSA;
/// use openssl::x509::X509Generator;
@@ -141,7 +138,7 @@ impl X509StoreContext {
/// let gen = X509Generator::new()
/// .set_valid_period(365*2)
/// .add_name("CN".to_owned(), "SuperMegaCorp Inc.".to_owned())
-/// .set_sign_hash(Type::SHA256)
+/// .set_sign_hash(MessageDigest::sha256())
/// .add_extension(Extension::KeyUsage(vec![KeyUsageOption::DigitalSignature]));
///
/// let cert = gen.sign(&pkey).unwrap();
@@ -152,7 +149,7 @@ pub struct X509Generator {
days: u32,
names: Vec<(String, String)>,
extensions: Extensions,
- hash_type: HashType,
+ hash_type: MessageDigest,
}
impl X509Generator {
@@ -168,7 +165,7 @@ impl X509Generator {
days: 365,
names: vec![],
extensions: Extensions::new(),
- hash_type: HashType::SHA1,
+ hash_type: MessageDigest::sha1(),
}
}
@@ -239,7 +236,7 @@ impl X509Generator {
self
}
- pub fn set_sign_hash(mut self, hash_type: hash::Type) -> X509Generator {
+ pub fn set_sign_hash(mut self, hash_type: MessageDigest) -> X509Generator {
self.hash_type = hash_type;
self
}
@@ -358,7 +355,7 @@ impl X509Generator {
&ext.to_string()));
}
- let hash_fn = self.hash_type.evp_md();
+ let hash_fn = self.hash_type.as_ptr();
try_ssl!(ffi::X509_sign(x509.as_ptr(), p_key.as_ptr(), hash_fn));
Ok(x509)
}
@@ -380,7 +377,7 @@ impl X509Generator {
try_ssl!(ffi::X509_REQ_add_extensions(req, exts as *mut _));
}
- let hash_fn = self.hash_type.evp_md();
+ let hash_fn = self.hash_type.as_ptr();
try_ssl!(ffi::X509_REQ_sign(req, p_key.as_ptr(), hash_fn));
Ok(X509Req::new(req))
@@ -438,9 +435,9 @@ impl<'a> X509Ref<'a> {
}
/// Returns certificate fingerprint calculated using provided hash
- pub fn fingerprint(&self, hash_type: hash::Type) -> Result<Vec<u8>, ErrorStack> {
+ pub fn fingerprint(&self, hash_type: MessageDigest) -> Result<Vec<u8>, ErrorStack> {
unsafe {
- let evp = hash_type.evp_md();
+ let evp = hash_type.as_ptr();
let mut len = ffi::EVP_MAX_MD_SIZE;
let mut buf = vec![0u8; len as usize];
try_ssl!(ffi::X509_digest(self.0, evp, buf.as_mut_ptr() as *mut _, &mut len));
diff --git a/openssl/src/x509/tests.rs b/openssl/src/x509/tests.rs
index 07d9e1d4..afb06408 100644
--- a/openssl/src/x509/tests.rs
+++ b/openssl/src/x509/tests.rs
@@ -1,6 +1,6 @@
use serialize::hex::FromHex;
-use crypto::hash::Type::SHA1;
+use crypto::hash::MessageDigest;
use crypto::pkey::PKey;
use crypto::rsa::RSA;
use x509::{X509, X509Generator};
@@ -14,7 +14,7 @@ fn get_generator() -> X509Generator {
X509Generator::new()
.set_valid_period(365 * 2)
.add_name("CN".to_string(), "test_me".to_string())
- .set_sign_hash(SHA1)
+ .set_sign_hash(MessageDigest::sha1())
.add_extension(KeyUsage(vec![DigitalSignature, KeyEncipherment]))
.add_extension(ExtKeyUsage(vec![ClientAuth,
ServerAuth,
@@ -83,7 +83,7 @@ fn test_req_gen() {
fn test_cert_loading() {
let cert = include_bytes!("../../test/cert.pem");
let cert = X509::from_pem(cert).ok().expect("Failed to load PEM");
- let fingerprint = cert.fingerprint(SHA1).unwrap();
+ let fingerprint = cert.fingerprint(MessageDigest::sha1()).unwrap();
let hash_str = "59172d9313e84459bcff27f967e79e6e9217e584";
let hash_vec = hash_str.from_hex().unwrap();