Borrow compression string

This commit is contained in:
Steven Fackler 2016-10-21 21:46:32 -07:00
parent f1c68e3544
commit 9be0aab9ac
1 changed files with 10 additions and 13 deletions

View File

@ -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()) };
fn _compression(&self) -> Option<&str> {
unsafe {
let ptr = ffi::SSL_get_current_compression(self.as_ptr());
if ptr == ptr::null() {
return None;
}
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)
let meth = ffi::SSL_COMP_get_name(ptr);
Some(str::from_utf8(CStr::from_ptr(meth as *const _).to_bytes()).unwrap())
}
}
#[cfg(osslconf = "OPENSSL_NO_COMP")]
fn _compression(&self) -> Option<String> {
fn _compression(&self) -> Option<&str> {
None
}