From 19b7a64b6dd93a2bccfbedd89e9f1db3f6711a83 Mon Sep 17 00:00:00 2001 From: John Tyner Date: Sun, 20 Aug 2023 19:46:03 -0400 Subject: [PATCH 1/3] Add openssl::cipher_ctx::CipherCtx::clone --- openssl-sys/src/handwritten/evp.rs | 2 ++ openssl/src/cipher_ctx.rs | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/openssl-sys/src/handwritten/evp.rs b/openssl-sys/src/handwritten/evp.rs index 9ebe212c42..e8ad6aa2d7 100644 --- a/openssl-sys/src/handwritten/evp.rs +++ b/openssl-sys/src/handwritten/evp.rs @@ -271,6 +271,8 @@ const_ptr_api! { extern "C" { pub fn EVP_CIPHER_CTX_new() -> *mut EVP_CIPHER_CTX; pub fn EVP_CIPHER_CTX_free(ctx: *mut EVP_CIPHER_CTX); + pub fn EVP_CIPHER_CTX_copy(dst: *mut EVP_CIPHER_CTX, src: *const EVP_CIPHER_CTX) -> c_int; + pub fn EVP_MD_CTX_copy_ex(dst: *mut EVP_MD_CTX, src: *const EVP_MD_CTX) -> c_int; #[cfg(ossl111)] pub fn EVP_MD_CTX_reset(ctx: *mut EVP_MD_CTX) -> c_int; diff --git a/openssl/src/cipher_ctx.rs b/openssl/src/cipher_ctx.rs index 56d0d26700..714a0815af 100644 --- a/openssl/src/cipher_ctx.rs +++ b/openssl/src/cipher_ctx.rs @@ -102,6 +102,15 @@ impl CipherCtx { Ok(CipherCtx::from_ptr(ptr)) } } + + #[corresponds(EVP_CIPHER_CTX_copy)] + pub fn clone(&self) -> Result { + let n = CipherCtx::new()?; + unsafe { + cvt(ffi::EVP_CIPHER_CTX_copy(n.as_ptr(), self.as_ptr()))?; + } + Ok(n) + } } impl CipherCtxRef { From f3a35f87ce4d77c827abcf96b34419e955514bbb Mon Sep 17 00:00:00 2001 From: John Tyner Date: Mon, 21 Aug 2023 07:54:49 -0400 Subject: [PATCH 2/3] replace clone() with copy() to better mimic openssl interface --- openssl/src/cipher_ctx.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/openssl/src/cipher_ctx.rs b/openssl/src/cipher_ctx.rs index 714a0815af..25d1060eba 100644 --- a/openssl/src/cipher_ctx.rs +++ b/openssl/src/cipher_ctx.rs @@ -102,18 +102,17 @@ impl CipherCtx { Ok(CipherCtx::from_ptr(ptr)) } } +} +impl CipherCtxRef { #[corresponds(EVP_CIPHER_CTX_copy)] - pub fn clone(&self) -> Result { - let n = CipherCtx::new()?; + pub fn copy(&mut self, src: &CipherCtx) -> Result<(), ErrorStack> { unsafe { - cvt(ffi::EVP_CIPHER_CTX_copy(n.as_ptr(), self.as_ptr()))?; + cvt(ffi::EVP_CIPHER_CTX_copy(self.as_ptr(), src.as_ptr()))?; + Ok(()) } - Ok(n) } -} -impl CipherCtxRef { /// Initializes the context for encryption. /// /// Normally this is called once to set all of the cipher, key, and IV. However, this process can be split up From d2663601fcf41ab9727a0dfa8d3540eb1419fcec Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Mon, 21 Aug 2023 17:54:02 -0700 Subject: [PATCH 3/3] Update openssl/src/cipher_ctx.rs --- openssl/src/cipher_ctx.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openssl/src/cipher_ctx.rs b/openssl/src/cipher_ctx.rs index 25d1060eba..f9031d2976 100644 --- a/openssl/src/cipher_ctx.rs +++ b/openssl/src/cipher_ctx.rs @@ -106,7 +106,7 @@ impl CipherCtx { impl CipherCtxRef { #[corresponds(EVP_CIPHER_CTX_copy)] - pub fn copy(&mut self, src: &CipherCtx) -> Result<(), ErrorStack> { + pub fn copy(&mut self, src: &CipherCtxRef) -> Result<(), ErrorStack> { unsafe { cvt(ffi::EVP_CIPHER_CTX_copy(self.as_ptr(), src.as_ptr()))?; Ok(())