From 09b1fe9a0d3392b266e47fd1808617059e41c1c3 Mon Sep 17 00:00:00 2001 From: Benjamin Saunders Date: Tue, 13 Mar 2018 18:36:18 -0700 Subject: Expose additional cipher and digest accessors --- openssl/src/symm.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'openssl/src/symm.rs') diff --git a/openssl/src/symm.rs b/openssl/src/symm.rs index 6b1d0134..a7068584 100644 --- a/openssl/src/symm.rs +++ b/openssl/src/symm.rs @@ -59,6 +59,7 @@ use ffi; use {cvt, cvt_p}; use error::ErrorStack; +use nid::Nid; #[derive(Copy, Clone)] pub enum Mode { @@ -75,6 +76,16 @@ pub enum Mode { pub struct Cipher(*const ffi::EVP_CIPHER); impl Cipher { + /// Looks up the cipher for a certain nid. + /// + /// This corresponds to [`EVP_get_cipherbynid`] + /// + /// [`EVP_get_cipherbynid`]: https://www.openssl.org/docs/man1.0.2/crypto/EVP_get_cipherbyname.html + pub fn from_nid(nid: Nid) -> Option { + let ptr = unsafe { ffi::EVP_get_cipherbyname(ffi::OBJ_nid2sn(nid.as_raw())) }; + if ptr.is_null() { None } else { Some(Cipher(ptr)) } + } + pub fn aes_128_ecb() -> Cipher { unsafe { Cipher(ffi::EVP_aes_128_ecb()) } } -- cgit v1.2.3