Merge pull request #1249 from coolreader18/more-ssl-method

Add SslMethod::tls_{client,server}
This commit is contained in:
Steven Fackler 2020-03-25 20:57:23 -04:00 committed by GitHub
commit ef369f827e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 2 deletions

View File

@ -1089,6 +1089,10 @@ cfg_if! {
pub fn TLS_method() -> *const SSL_METHOD; pub fn TLS_method() -> *const SSL_METHOD;
pub fn DTLS_method() -> *const SSL_METHOD; pub fn DTLS_method() -> *const SSL_METHOD;
pub fn TLS_server_method() -> *const SSL_METHOD;
pub fn TLS_client_method() -> *const SSL_METHOD;
} }
} else { } else {
extern "C" { extern "C" {
@ -1097,6 +1101,10 @@ cfg_if! {
pub fn SSLv23_method() -> *const SSL_METHOD; pub fn SSLv23_method() -> *const SSL_METHOD;
pub fn SSLv23_client_method() -> *const SSL_METHOD;
pub fn SSLv23_server_method() -> *const SSL_METHOD;
pub fn TLSv1_method() -> *const SSL_METHOD; pub fn TLSv1_method() -> *const SSL_METHOD;
pub fn TLSv1_1_method() -> *const SSL_METHOD; pub fn TLSv1_1_method() -> *const SSL_METHOD;

View File

@ -323,6 +323,22 @@ impl SslMethod {
unsafe { SslMethod(DTLS_method()) } unsafe { SslMethod(DTLS_method()) }
} }
/// Support all versions of the TLS protocol, explicitly as a client.
///
/// This corresponds to `TLS_client_method` on OpenSSL 1.1.0 and
/// `SSLv23_client_method` on OpenSSL 1.0.x.
pub fn tls_client() -> SslMethod {
unsafe { SslMethod(TLS_client_method()) }
}
/// Support all versions of the TLS protocol, explicitly as a server.
///
/// This corresponds to `TLS_server_method` on OpenSSL 1.1.0 and
/// `SSLv23_server_method` on OpenSSL 1.0.x.
pub fn tls_server() -> SslMethod {
unsafe { SslMethod(TLS_server_method()) }
}
/// Constructs an `SslMethod` from a pointer to the underlying OpenSSL value. /// Constructs an `SslMethod` from a pointer to the underlying OpenSSL value.
pub unsafe fn from_ptr(ptr: *const ffi::SSL_METHOD) -> SslMethod { pub unsafe fn from_ptr(ptr: *const ffi::SSL_METHOD) -> SslMethod {
SslMethod(ptr) SslMethod(ptr)
@ -3899,9 +3915,12 @@ cfg_if! {
cfg_if! { cfg_if! {
if #[cfg(any(ossl110, libressl291))] { if #[cfg(any(ossl110, libressl291))] {
use ffi::{TLS_method, DTLS_method}; use ffi::{TLS_method, DTLS_method, TLS_client_method, TLS_server_method};
} else { } else {
use ffi::{SSLv23_method as TLS_method, DTLSv1_method as DTLS_method}; use ffi::{
SSLv23_method as TLS_method, DTLSv1_method as DTLS_method, SSLv23_client_method as TLS_client_method,
SSLv23_server_method as TLS_server_method,
};
} }
} }
cfg_if! { cfg_if! {