From 8449b822854e29213756ad339abbfb833a73216e Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sat, 5 Aug 2023 12:40:24 -0400 Subject: [PATCH] Implement Deref[Mut] for Cipher on older OpenSSLs They don't do anything, but this can be useful when writing code that works with multiple versions of OpenSSL. --- openssl/src/cipher.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/openssl/src/cipher.rs b/openssl/src/cipher.rs index d26b93c261..f81895e513 100644 --- a/openssl/src/cipher.rs +++ b/openssl/src/cipher.rs @@ -12,6 +12,7 @@ use foreign_types::{ForeignTypeRef, Opaque}; use openssl_macros::corresponds; #[cfg(ossl300)] use std::ffi::CString; +use std::ops::{Deref, DerefMut}; #[cfg(ossl300)] use std::ptr; @@ -41,7 +42,6 @@ cfg_if! { cfg_if! { if #[cfg(ossl300)] { use foreign_types::ForeignType; - use std::ops::{Deref, DerefMut}; type Inner = *mut ffi::EVP_CIPHER; @@ -90,6 +90,22 @@ cfg_if! { } } else { enum Inner {} + + impl Deref for Cipher { + type Target = CipherRef; + + #[inline] + fn deref(&self) -> &Self::Target { + match self.0 {} + } + } + + impl DerefMut for Cipher { + #[inline] + fn deref_mut(&mut self) -> &mut Self::Target { + match self.0 {} + } + } } }