Add SslRef::set_alpn_protos

This commit is contained in:
Steven Fackler 2018-06-04 20:19:27 -07:00
parent 2c89ef5228
commit cdc90c7e9d
1 changed files with 26 additions and 0 deletions

View File

@ -2178,6 +2178,32 @@ impl SslRef {
unsafe { cvt(ffi::SSL_set_ecdh_auto(self.as_ptr(), onoff as c_int)).map(|_| ()) }
}
/// Like [`SslContextBuilder::set_alpn_protos`].
///
/// Requires OpenSSL 1.0.2 or LibreSSL 2.6.1 or newer.
///
/// This corresponds to [`SSL_set_alpn_protos`].
///
/// [`SslContextBuilder::set_alpn_protos`]: struct.SslContextBuilder.html#method.set_alpn_protos
/// [`SSL_set_alpn_protos`]: https://www.openssl.org/docs/man1.1.0/ssl/SSL_set_alpn_protos.html
#[cfg(any(ossl102, libressl261))]
pub fn set_alpn_protos(&mut self, protocols: &[u8]) -> Result<(), ErrorStack> {
unsafe {
assert!(protocols.len() <= c_uint::max_value() as usize);
let r = ffi::SSL_set_alpn_protos(
self.as_ptr(),
protocols.as_ptr(),
protocols.len() as c_uint,
);
// fun fact, SSL_set_alpn_protos has a reversed return code D:
if r == 0 {
Ok(())
} else {
Err(ErrorStack::get())
}
}
}
/// Returns the current cipher if the session is active.
///
/// This corresponds to [`SSL_get_current_cipher`].