aboutsummaryrefslogtreecommitdiff
path: root/openssl/src
diff options
context:
space:
mode:
authorChris Dawes <[email protected]>2016-05-03 22:17:07 +0100
committerChris Dawes <[email protected]>2016-05-03 22:17:07 +0100
commit6f410a25b2179b11183a56ca0d476a744bff91cd (patch)
tree93f40a4c96eba1e0eae3da7b96c3f791a14da525 /openssl/src
parentadd constructor for private keys from bignums (diff)
downloadrust-openssl-6f410a25b2179b11183a56ca0d476a744bff91cd.tar.xz
rust-openssl-6f410a25b2179b11183a56ca0d476a744bff91cd.zip
take enum instead of ints from openssl header file
Diffstat (limited to 'openssl/src')
-rw-r--r--openssl/src/crypto/rsa.rs28
1 files changed, 22 insertions, 6 deletions
diff --git a/openssl/src/crypto/rsa.rs b/openssl/src/crypto/rsa.rs
index 974f9ad9..ada5f1c1 100644
--- a/openssl/src/crypto/rsa.rs
+++ b/openssl/src/crypto/rsa.rs
@@ -7,6 +7,24 @@ use std::io::{self, Read};
use bn::BigNum;
use bio::MemBio;
+#[derive(Copy, Clone, Debug)]
+pub enum PKCSHashType {
+ SHA256,
+ SHA384,
+ SHA512
+}
+
+/// https://github.com/openssl/openssl/blob/master/include/openssl/obj_mac.h#L2790
+impl Into<i32> for PKCSHashType {
+ fn into(self) -> i32 {
+ match self {
+ PKCSHashType::SHA256 => 672,
+ PKCSHashType::SHA384 => 673,
+ PKCSHashType::SHA512 => 674
+ }
+ }
+}
+
pub struct RSA(*mut ffi::RSA);
impl Drop for RSA {
@@ -91,15 +109,13 @@ impl RSA {
}
}
- pub fn sign(&self, hash_id: i32, message: &[u8]) -> Result<Vec<u8>, SslError> {
- // RSA_sign(t: c_int, m: *const u8, mlen: c_uint, sig: *mut u8, siglen: *mut c_uint, k: *mut RSA) -> c_int
-
+ pub fn sign(&self, hash_id: PKCSHashType, message: &[u8]) -> Result<Vec<u8>, SslError> {
let k_len = try!(self.size());
let mut sig = vec![0;k_len as usize];
let mut sig_len = k_len;
unsafe {
- let result = ffi::RSA_sign(hash_id, message.as_ptr(), message.len() as u32, sig.as_mut_ptr(), &mut sig_len, self.0);
+ let result = ffi::RSA_sign(hash_id.into(), message.as_ptr(), message.len() as u32, sig.as_mut_ptr(), &mut sig_len, self.0);
assert!(sig_len == k_len);
if result == 1 {
@@ -110,9 +126,9 @@ impl RSA {
}
}
- pub fn verify(&self, hash_id: i32, message: &[u8], sig: &[u8]) -> Result<bool, SslError> {
+ pub fn verify(&self, hash_id: PKCSHashType, message: &[u8], sig: &[u8]) -> Result<bool, SslError> {
unsafe {
- let result = ffi::RSA_verify(hash_id, message.as_ptr(), message.len() as u32, sig.as_ptr(), sig.len() as u32, self.0);
+ let result = ffi::RSA_verify(hash_id.into(), message.as_ptr(), message.len() as u32, sig.as_ptr(), sig.len() as u32, self.0);
Ok(result == 1)
}