diff options
| author | Steven Fackler <[email protected]> | 2016-10-21 19:54:30 -0700 |
|---|---|---|
| committer | Steven Fackler <[email protected]> | 2016-10-21 19:54:30 -0700 |
| commit | f0cde389290d7ec20a9650a09096b742c6b9aa1f (patch) | |
| tree | 271e7ff3c5b554594bddb90de00feb61856d2556 /openssl/src | |
| parent | Convert SslCipherRef (diff) | |
| download | rust-openssl-f0cde389290d7ec20a9650a09096b742c6b9aa1f.tar.xz rust-openssl-f0cde389290d7ec20a9650a09096b742c6b9aa1f.zip | |
Borrowed servername
Diffstat (limited to 'openssl/src')
| -rw-r--r-- | openssl/src/ssl/mod.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs index fbb03104..d03b495f 100644 --- a/openssl/src/ssl/mod.rs +++ b/openssl/src/ssl/mod.rs @@ -980,13 +980,15 @@ impl SslRef { } /// Returns the server's name for the current connection - pub fn servername(&self) -> Option<String> { - let name = unsafe { ffi::SSL_get_servername(self.as_ptr(), ffi::TLSEXT_NAMETYPE_host_name) }; - if name == ptr::null() { - return None; - } + pub fn servername(&self) -> Option<&str> { + unsafe { + let name = ffi::SSL_get_servername(self.as_ptr(), ffi::TLSEXT_NAMETYPE_host_name); + if name == ptr::null() { + return None; + } - unsafe { String::from_utf8(CStr::from_ptr(name as *const _).to_bytes().to_vec()).ok() } + Some(str::from_utf8(CStr::from_ptr(name as *const _).to_bytes()).unwrap()) + } } /// Changes the context corresponding to the current connection. |