aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/ssl/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'openssl/src/ssl/mod.rs')
-rw-r--r--openssl/src/ssl/mod.rs54
1 files changed, 38 insertions, 16 deletions
diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs
index aa785142..0252b114 100644
--- a/openssl/src/ssl/mod.rs
+++ b/openssl/src/ssl/mod.rs
@@ -566,6 +566,9 @@ impl SslContext {
let ctx = SslContext { ctx: ctx };
+ // this is a bit dubious (?)
+ try!(ctx.set_mode(ffi::SSL_MODE_AUTO_RETRY | ffi::SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER));
+
if method.is_dtls() {
ctx.set_read_ahead(1);
}
@@ -648,8 +651,12 @@ impl SslContext {
}
}
+ fn set_mode(&self, mode: c_long) -> Result<(), SslError> {
+ wrap_ssl_result(unsafe { ffi_extras::SSL_CTX_set_mode(self.ctx, mode) as c_int })
+ }
+
pub fn set_tmp_dh(&self, dh: DH) -> Result<(), SslError> {
- wrap_ssl_result(unsafe { ffi_extras::SSL_CTX_set_tmp_dh(self.ctx, dh.raw()) as i32 })
+ wrap_ssl_result(unsafe { ffi_extras::SSL_CTX_set_tmp_dh(self.ctx, dh.raw()) as c_int })
}
/// Use the default locations of trusted certificates for verification.
@@ -850,7 +857,7 @@ pub struct SslCipher<'a> {
ph: PhantomData<&'a ()>,
}
-impl <'a> SslCipher<'a> {
+impl<'a> SslCipher<'a> {
/// Returns the name of cipher.
pub fn name(&self) -> &'static str {
let name = unsafe {
@@ -874,12 +881,18 @@ impl <'a> SslCipher<'a> {
/// Returns the number of bits used for the cipher.
pub fn bits(&self) -> CipherBits {
unsafe {
- let algo_bits : *mut c_int = ptr::null_mut();
+ let algo_bits: *mut c_int = ptr::null_mut();
let secret_bits = ffi::SSL_CIPHER_get_bits(self.cipher, algo_bits);
if !algo_bits.is_null() {
- CipherBits { secret: secret_bits, algorithm: Some(*algo_bits) }
+ CipherBits {
+ secret: secret_bits,
+ algorithm: Some(*algo_bits),
+ }
} else {
- CipherBits { secret: secret_bits, algorithm: None }
+ CipherBits {
+ secret: secret_bits,
+ algorithm: None,
+ }
}
}
}
@@ -987,7 +1000,9 @@ impl Ssl {
{
unsafe {
let verify = Box::new(verify);
- ffi::SSL_set_ex_data(self.ssl, get_ssl_verify_data_idx::<F>(), mem::transmute(verify));
+ ffi::SSL_set_ex_data(self.ssl,
+ get_ssl_verify_data_idx::<F>(),
+ mem::transmute(verify));
ffi::SSL_set_verify(self.ssl, mode.bits as c_int, Some(ssl_raw_verify::<F>));
}
}
@@ -999,7 +1014,10 @@ impl Ssl {
if ptr.is_null() {
None
} else {
- Some(SslCipher{ cipher: ptr, ph: PhantomData })
+ Some(SslCipher {
+ cipher: ptr,
+ ph: PhantomData,
+ })
}
}
}
@@ -1052,8 +1070,8 @@ impl Ssl {
/// Returns the name of the protocol used for the connection, e.g. "TLSv1.2", "SSLv3", etc.
pub fn version(&self) -> &'static str {
let version = unsafe {
- let ptr = ffi::SSL_get_version(self.ssl);
- CStr::from_ptr(ptr as *const _)
+ let ptr = ffi::SSL_get_version(self.ssl);
+ CStr::from_ptr(ptr as *const _)
};
str::from_utf8(version.to_bytes()).unwrap()
@@ -1224,7 +1242,8 @@ impl<S: Clone + Read + Write> Clone for SslStream<S> {
}
}
-impl<S> fmt::Debug for SslStream<S> where S: fmt::Debug
+impl<S> fmt::Debug for SslStream<S>
+ where S: fmt::Debug
{
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.debug_struct("SslStream")
@@ -1385,7 +1404,8 @@ impl<S> SslStream<S> {
}
}
LibSslError::ErrorZeroReturn => Some(SslError::SslSessionClosed),
- LibSslError::ErrorWantWrite | LibSslError::ErrorWantRead => None,
+ LibSslError::ErrorWantWrite |
+ LibSslError::ErrorWantRead => None,
err => {
Some(SslError::StreamError(io::Error::new(io::ErrorKind::Other,
format!("unexpected error {:?}", err))))
@@ -1401,8 +1421,7 @@ impl<S> SslStream<S> {
}
#[cfg(not(feature = "nightly"))]
- fn check_panic(&mut self) {
- }
+ fn check_panic(&mut self) {}
fn get_bio_error(&mut self) -> io::Error {
let error = unsafe { bio::take_error::<S>(self.ssl.get_raw_rbio()) };
@@ -1513,7 +1532,8 @@ pub enum MaybeSslStream<S>
Normal(S),
}
-impl<S> Read for MaybeSslStream<S> where S: Read + Write
+impl<S> Read for MaybeSslStream<S>
+ where S: Read + Write
{
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
match *self {
@@ -1523,7 +1543,8 @@ impl<S> Read for MaybeSslStream<S> where S: Read + Write
}
}
-impl<S> Write for MaybeSslStream<S> where S: Read + Write
+impl<S> Write for MaybeSslStream<S>
+ where S: Read + Write
{
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
match *self {
@@ -1540,7 +1561,8 @@ impl<S> Write for MaybeSslStream<S> where S: Read + Write
}
}
-impl<S> MaybeSslStream<S> where S: Read + Write
+impl<S> MaybeSslStream<S>
+ where S: Read + Write
{
/// Returns a reference to the underlying stream.
pub fn get_ref(&self) -> &S {