aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/crypto/pkey.rs
diff options
context:
space:
mode:
Diffstat (limited to 'openssl/src/crypto/pkey.rs')
-rw-r--r--openssl/src/crypto/pkey.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/openssl/src/crypto/pkey.rs b/openssl/src/crypto/pkey.rs
index a2a6f9c1..8b408d29 100644
--- a/openssl/src/crypto/pkey.rs
+++ b/openssl/src/crypto/pkey.rs
@@ -1,4 +1,4 @@
-use libc::{c_void, c_char};
+use libc::{c_void, c_char, c_int};
use std::ptr;
use std::mem;
use ffi;
@@ -26,6 +26,18 @@ impl PKey {
}
}
+ /// Create a new `PKey` containing an HMAC key.
+ pub fn hmac(key: &[u8]) -> Result<PKey, ErrorStack> {
+ unsafe {
+ assert!(key.len() <= c_int::max_value() as usize);
+ let key = try_ssl_null!(ffi::EVP_PKEY_new_mac_key(ffi::EVP_PKEY_HMAC,
+ ptr::null_mut(),
+ key.as_ptr() as *const _,
+ key.len() as c_int));
+ Ok(PKey(key))
+ }
+ }
+
pub unsafe fn from_ptr(handle: *mut ffi::EVP_PKEY) -> PKey {
PKey(handle)
}