aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/ssl/mod.rs
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2016-10-15 16:10:03 -0700
committerSteven Fackler <[email protected]>2016-10-15 16:10:03 -0700
commitee189885843b2b4f75f180ccc5b66689c3cdd553 (patch)
tree574bb8b4f1375d9354251f6fda6d4ee867750c58 /openssl/src/ssl/mod.rs
parentDe-enumify Cipher (diff)
downloadrust-openssl-ee189885843b2b4f75f180ccc5b66689c3cdd553.tar.xz
rust-openssl-ee189885843b2b4f75f180ccc5b66689c3cdd553.zip
De-enumify SslMethod
Diffstat (limited to 'openssl/src/ssl/mod.rs')
-rw-r--r--openssl/src/ssl/mod.rs73
1 files changed, 45 insertions, 28 deletions
diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs
index 076ac400..73ff0b47 100644
--- a/openssl/src/ssl/mod.rs
+++ b/openssl/src/ssl/mod.rs
@@ -76,13 +76,29 @@ bitflags! {
}
}
-/// Determines the SSL method supported
-#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
-pub enum SslMethod {
- /// Support the TLS protocol
- Tls,
- /// Support DTLS protocol
- Dtls,
+#[derive(Copy, Clone)]
+pub struct SslMethod(*const ffi::SSL_METHOD);
+
+impl SslMethod {
+ /// Support all versions of the TLS protocol.
+ ///
+ /// This corresponds to `TLS_method` on OpenSSL 1.1.0 and `SSLv23_method`
+ /// on OpenSSL 1.0.x.
+ pub fn tls() -> SslMethod {
+ SslMethod(compat::tls_method())
+ }
+
+ /// Support all versions of the DTLS protocol.
+ ///
+ /// This corresponds to `DTLS_method` on OpenSSL 1.1.0 and `DTLSv1_method`
+ /// on OpenSSL 1.0.x.
+ pub fn dtls() -> SslMethod {
+ SslMethod(compat::dtls_method())
+ }
+
+ pub fn as_ptr(&self) -> *const ffi::SSL_METHOD {
+ self.0
+ }
}
/// Determines the type of certificate verification used
@@ -653,15 +669,10 @@ impl SslContext {
init();
let mut ctx = unsafe {
- let method = compat::get_method(method);
- let ctx = try_ssl_null!(ffi::SSL_CTX_new(method));
+ let ctx = try_ssl_null!(ffi::SSL_CTX_new(method.as_ptr()));
SslContext::from_ptr(ctx)
};
- match method {
- SslMethod::Dtls => ctx.set_read_ahead(1),
- _ => {}
- }
// this is a bit dubious (?)
try!(ctx.set_mode(ffi::SSL_MODE_AUTO_RETRY | ffi::SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER));
@@ -1374,8 +1385,6 @@ mod compat {
pub use ffi::{SSL_CTX_get_options, SSL_CTX_set_options};
pub use ffi::{SSL_CTX_clear_options, SSL_CTX_up_ref};
- use super::SslMethod;
-
pub unsafe fn get_new_idx(f: ffi::CRYPTO_EX_free) -> c_int {
ffi::CRYPTO_get_ex_new_index(ffi::CRYPTO_EX_INDEX_SSL_CTX,
0,
@@ -1394,10 +1403,15 @@ mod compat {
Some(f))
}
- pub unsafe fn get_method(method: SslMethod) -> *const ffi::SSL_METHOD {
- match method {
- SslMethod::Tls => ffi::TLS_method(),
- SslMethod::Dtls => ffi::DTLS_method(),
+ pub fn tls_method() -> *const ffi::SSL_METHOD {
+ unsafe {
+ ffi::TLS_method()
+ }
+ }
+
+ pub fn dtls_method() -> *const ffi::SSL_METHOD {
+ unsafe {
+ ffi::DTLS_method()
}
}
}
@@ -1410,8 +1424,6 @@ mod compat {
use ffi;
use libc::{self, c_long, c_ulong, c_int};
- use super::SslMethod;
-
pub unsafe fn SSL_CTX_get_options(ctx: *const ffi::SSL_CTX) -> c_ulong {
ffi::SSL_CTX_ctrl(ctx as *mut _,
ffi::SSL_CTRL_OPTIONS,
@@ -1451,13 +1463,6 @@ mod compat {
Some(f))
}
- pub unsafe fn get_method(method: SslMethod) -> *const ffi::SSL_METHOD {
- match method {
- SslMethod::Tls => ffi::SSLv23_method(),
- SslMethod::Dtls => ffi::DTLSv1_method(),
- }
- }
-
pub unsafe fn SSL_CTX_up_ref(ssl: *mut ffi::SSL_CTX) -> libc::c_int {
ffi::CRYPTO_add_lock(&mut (*ssl).references,
1,
@@ -1466,4 +1471,16 @@ mod compat {
line!() as libc::c_int);
0
}
+
+ pub fn tls_method() -> *const ffi::SSL_METHOD {
+ unsafe {
+ ffi::SSLv23_method()
+ }
+ }
+
+ pub fn dtls_method() -> *const ffi::SSL_METHOD {
+ unsafe {
+ ffi::DTLSv1_method()
+ }
+ }
}