From 6587737c77c96db28ace83997eff3fa8ae280067 Mon Sep 17 00:00:00 2001 From: ljy9810 Date: Mon, 14 Apr 2025 10:23:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E7=A4=BE=E5=8C=BApr=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Drust-openssl=20=E6=BC=8F=E6=B4=9E=20RUSTSEC-2?= =?UTF-8?q?025-0022?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ljy9810 --- openssl/src/cipher.rs | 14 +++++++++++++- openssl/src/lib.rs | 6 +++--- openssl/src/md.rs | 14 +++++++++++++- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/openssl/src/cipher.rs b/openssl/src/cipher.rs index f81895e..270f653 100644 --- a/openssl/src/cipher.rs +++ b/openssl/src/cipher.rs @@ -146,7 +146,7 @@ impl Cipher { let ptr = cvt_p(ffi::EVP_CIPHER_fetch( ctx.map_or(ptr::null_mut(), ForeignTypeRef::as_ptr), algorithm.as_ptr(), - properties.map_or(ptr::null_mut(), |s| s.as_ptr()), + properties.as_ref().map_or(ptr::null_mut(), |s| s.as_ptr()), ))?; Ok(Cipher::from_ptr(ptr)) @@ -534,3 +534,15 @@ impl CipherRef { unsafe { EVP_CIPHER_block_size(self.as_ptr()) as usize } } } + +#[cfg(test)] +mod test { + #[cfg(ossl300)] + use super::Cipher; + + #[test] + #[cfg(ossl300)] + fn test_cipher_fetch_properties() { + assert!(Cipher::fetch(None, "AES-128-GCM", Some("provider=gibberish")).is_err()); + } +} \ No newline at end of file diff --git a/openssl/src/lib.rs b/openssl/src/lib.rs index 28b73f3..d4120e9 100644 --- a/openssl/src/lib.rs +++ b/openssl/src/lib.rs @@ -56,12 +56,12 @@ //! override the automatic detection logic. //! //! * `OPENSSL_DIR` - If specified, the directory of an OpenSSL installation. The directory should contain `lib` and -//! `include` subdirectories containing the libraries and headers respectively. +//! `include` subdirectories containing the libraries and headers respectively. //! * `OPENSSL_LIB_DIR` and `OPENSSL_INCLUDE_DIR` - If specified, the directories containing the OpenSSL libraries and -//! headers respectively. This can be used if the OpenSSL installation is split in a nonstandard directory layout. +//! headers respectively. This can be used if the OpenSSL installation is split in a nonstandard directory layout. //! * `OPENSSL_STATIC` - If set, the crate will statically link to OpenSSL rather than dynamically link. //! * `OPENSSL_LIBS` - If set, a `:`-separated list of library names to link to (e.g. `ssl:crypto`). This can be used -//! if nonstandard library names were used for whatever reason. +//! if nonstandard library names were used for whatever reason. //! * `OPENSSL_NO_VENDOR` - If set, always find OpenSSL in the system, even if the `vendored` feature is enabled. //! //! Additionally, these variables can be prefixed with the upper-cased target architecture (e.g. diff --git a/openssl/src/md.rs b/openssl/src/md.rs index 4ade8e8..a08b35a 100644 --- a/openssl/src/md.rs +++ b/openssl/src/md.rs @@ -107,7 +107,7 @@ impl Md { let ptr = cvt_p(ffi::EVP_MD_fetch( ctx.map_or(ptr::null_mut(), ForeignTypeRef::as_ptr), algorithm.as_ptr(), - properties.map_or(ptr::null_mut(), |s| s.as_ptr()), + properties.as_ref().map_or(ptr::null_mut(), |s| s.as_ptr()), ))?; Ok(Md::from_ptr(ptr)) @@ -233,3 +233,15 @@ impl MdRef { unsafe { Nid::from_raw(ffi::EVP_MD_type(self.as_ptr())) } } } + +#[cfg(test)] +mod test { + #[cfg(ossl300)] + use super::Md; + + #[test] + #[cfg(ossl300)] + fn test_md_fetch_properties() { + assert!(Md::fetch(None, "SHA-256", Some("provider=gibberish")).is_err()); + } +} \ No newline at end of file -- Gitee