From 58ccea26adccbd4b2d515ea23ea361cd4aeb59dd Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Fri, 22 Feb 2019 12:33:41 -0700 Subject: [PATCH] Fix cipher_name return value --- openssl/src/ssl/mod.rs | 10 ++++------ openssl/src/ssl/test.rs | 4 +++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs index c78b7f66..3731714a 100644 --- a/openssl/src/ssl/mod.rs +++ b/openssl/src/ssl/mod.rs @@ -115,23 +115,21 @@ mod test; /// Returns the OpenSSL name of a cipher corresponding to an RFC-standard cipher name. /// +/// If the cipher has no corresponding OpenSSL name, the string `(NONE)` is returned. +/// /// Requires OpenSSL 1.1.1 or newer. /// /// This corresponds to [`OPENSSL_cipher_name`] /// /// [`OPENSSL_cipher_name`]: https://www.openssl.org/docs/manmaster/man3/SSL_CIPHER_get_name.html #[cfg(ossl111)] -pub fn cipher_name(std_name: &str) -> Option<&'static str> { +pub fn cipher_name(std_name: &str) -> &'static str { unsafe { ffi::init(); let s = CString::new(std_name).unwrap(); let ptr = ffi::OPENSSL_cipher_name(s.as_ptr()); - if ptr.is_null() { - None - } else { - Some(CStr::from_ptr(ptr).to_str().unwrap()) - } + CStr::from_ptr(ptr).to_str().unwrap() } } diff --git a/openssl/src/ssl/test.rs b/openssl/src/ssl/test.rs index 09ea04e9..2b515af4 100644 --- a/openssl/src/ssl/test.rs +++ b/openssl/src/ssl/test.rs @@ -1844,6 +1844,8 @@ fn client_hello() { fn openssl_cipher_name() { assert_eq!( super::cipher_name("TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384"), - Some("ECDHE-RSA-AES256-SHA384") + "ECDHE-RSA-AES256-SHA384", ); + + assert_eq!(super::cipher_name("asdf"), "(NONE)"); }