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/ssl/mod.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'openssl/src/ssl/mod.rs') diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs index e2a0f156..f7f46a7f 100644 --- a/openssl/src/ssl/mod.rs +++ b/openssl/src/ssl/mod.rs @@ -96,6 +96,8 @@ use stack::{Stack, StackRef}; use ssl::bio::BioMethod; use ssl::error::InnerError; use ssl::callbacks::*; +use nid::Nid; +use hash::MessageDigest; pub use ssl::connector::{ConnectConfiguration, SslAcceptor, SslAcceptorBuilder, SslConnector, SslConnectorBuilder}; @@ -1814,6 +1816,30 @@ impl SslCipherRef { String::from_utf8(CStr::from_ptr(ptr as *const _).to_bytes().to_vec()).unwrap() } } + + /// Returns the handshake digest of the cipher. + /// + /// Available as of OpenSSL 1.1.1. This corresponds to [`SSL_CIPHER_get_handshake_digest`]. + /// + /// [`SSL_CIPHER_get_handshake_digest`]: https://www.openssl.org/docs/man1.1.1/man3/SSL_CIPHER_get_handshake_digest.html + #[cfg(all(feature = "v111", ossl111))] + pub fn handshake_digest(&self) -> Option { + unsafe { + let ptr = ffi::SSL_CIPHER_get_handshake_digest(self.as_ptr()); + if ptr.is_null() { None } else { Some(MessageDigest::from_ptr(ptr)) } + } + } + + /// Returns the NID corresponding to the cipher. + /// + /// Available as of OpenSSL 1.1.0. This corresponds to [`SSL_CIPHER_get_cipher_nid`] + /// + /// [`SSL_CIPHER_get_cipher_nid`]: https://www.openssl.org/docs/man1.1.0/ssl/SSL_CIPHER_get_cipher_nid.html + #[cfg(any(all(feature = "v110", ossl110), all(feature = "v111", ossl111)))] + pub fn cipher_nid(&self) -> Option { + let n = unsafe { ffi::SSL_CIPHER_get_cipher_nid(self.as_ptr()) }; + if n == 0 { None } else { Some(Nid::from_raw(n)) } + } } foreign_type! { -- cgit v1.2.3