diff options
| author | Steven Fackler <[email protected]> | 2016-10-21 21:46:32 -0700 |
|---|---|---|
| committer | Steven Fackler <[email protected]> | 2016-10-21 21:46:32 -0700 |
| commit | 9be0aab9acaa98c2419832ac396063bdfb9995fd (patch) | |
| tree | 3fd0a7077a897d105c2b68debe9a084f64c9d714 | |
| parent | Rename SslContextOptions (diff) | |
| download | rust-openssl-9be0aab9acaa98c2419832ac396063bdfb9995fd.tar.xz rust-openssl-9be0aab9acaa98c2419832ac396063bdfb9995fd.zip | |
Borrow compression string
| -rw-r--r-- | openssl/src/ssl/mod.rs | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs index c703d5fc..963f252c 100644 --- a/openssl/src/ssl/mod.rs +++ b/openssl/src/ssl/mod.rs @@ -955,27 +955,24 @@ impl SslRef { /// /// The result will be either None, indicating no compression is in use, or /// a string with the compression name. - pub fn compression(&self) -> Option<String> { + pub fn compression(&self) -> Option<&str> { self._compression() } #[cfg(not(osslconf = "OPENSSL_NO_COMP"))] - fn _compression(&self) -> Option<String> { - let ptr = unsafe { ffi::SSL_get_current_compression(self.as_ptr()) }; - if ptr == ptr::null() { - return None; + fn _compression(&self) -> Option<&str> { + unsafe { + let ptr = ffi::SSL_get_current_compression(self.as_ptr()); + if ptr == ptr::null() { + return None; + } + let meth = ffi::SSL_COMP_get_name(ptr); + Some(str::from_utf8(CStr::from_ptr(meth as *const _).to_bytes()).unwrap()) } - - let meth = unsafe { ffi::SSL_COMP_get_name(ptr) }; - let s = unsafe { - String::from_utf8(CStr::from_ptr(meth as *const _).to_bytes().to_vec()).unwrap() - }; - - Some(s) } #[cfg(osslconf = "OPENSSL_NO_COMP")] - fn _compression(&self) -> Option<String> { + fn _compression(&self) -> Option<&str> { None } |