aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/crypto
diff options
context:
space:
mode:
authorChris Dawes <[email protected]>2016-05-04 09:00:05 +0100
committerChris Dawes <[email protected]>2016-05-04 09:00:05 +0100
commita5ede6a85101f294333ce7f102cb98d718b53638 (patch)
tree9b46e1c0022dc11260de4a2f7076bc9bb20f5667 /openssl/src/crypto
parenttake enum instead of ints from openssl header file (diff)
downloadrust-openssl-a5ede6a85101f294333ce7f102cb98d718b53638.tar.xz
rust-openssl-a5ede6a85101f294333ce7f102cb98d718b53638.zip
add missing NIDs and use Nid as input to signing
Diffstat (limited to 'openssl/src/crypto')
-rw-r--r--openssl/src/crypto/rsa.rs27
1 files changed, 5 insertions, 22 deletions
diff --git a/openssl/src/crypto/rsa.rs b/openssl/src/crypto/rsa.rs
index ada5f1c1..f9d1dece 100644
--- a/openssl/src/crypto/rsa.rs
+++ b/openssl/src/crypto/rsa.rs
@@ -6,24 +6,7 @@ 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
- }
- }
-}
+use nid::Nid;
pub struct RSA(*mut ffi::RSA);
@@ -109,13 +92,13 @@ impl RSA {
}
}
- pub fn sign(&self, hash_id: PKCSHashType, message: &[u8]) -> Result<Vec<u8>, SslError> {
+ pub fn sign(&self, hash_id: Nid, 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.into(), message.as_ptr(), message.len() as u32, sig.as_mut_ptr(), &mut sig_len, self.0);
+ let result = ffi::RSA_sign(hash_id as i32, message.as_ptr(), message.len() as u32, sig.as_mut_ptr(), &mut sig_len, self.0);
assert!(sig_len == k_len);
if result == 1 {
@@ -126,9 +109,9 @@ impl RSA {
}
}
- pub fn verify(&self, hash_id: PKCSHashType, message: &[u8], sig: &[u8]) -> Result<bool, SslError> {
+ pub fn verify(&self, hash_id: Nid, message: &[u8], sig: &[u8]) -> Result<bool, SslError> {
unsafe {
- let result = ffi::RSA_verify(hash_id.into(), message.as_ptr(), message.len() as u32, sig.as_ptr(), sig.len() as u32, self.0);
+ let result = ffi::RSA_verify(hash_id as i32, message.as_ptr(), message.len() as u32, sig.as_ptr(), sig.len() as u32, self.0);
Ok(result == 1)
}