Loading openssl/src/bio/mod.rs +2 −3 Original line number Diff line number Diff line Loading @@ -3,7 +3,6 @@ use std::io; use std::io::prelude::*; use std::ptr; use std::cmp; use std::num::Int; use ffi; use ssl::error::{SslError}; Loading Loading @@ -61,7 +60,7 @@ impl MemBio { impl Read for MemBio { fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { let len = cmp::min(<c_int as Int>::max_value() as usize, buf.len()) as c_int; let len = cmp::min(c_int::max_value() as usize, buf.len()) as c_int; let ret = unsafe { ffi::BIO_read(self.bio, buf.as_ptr() as *mut c_void, len) }; Loading @@ -83,7 +82,7 @@ impl Read for MemBio { impl Write for MemBio { fn write(&mut self, buf: &[u8]) -> io::Result<usize> { let len = cmp::min(<c_int as Int>::max_value() as usize, buf.len()) as c_int; let len = cmp::min(c_int::max_value() as usize, buf.len()) as c_int; let ret = unsafe { ffi::BIO_write(self.bio, buf.as_ptr() as *const c_void, len) }; Loading openssl/src/ssl/mod.rs +32 −17 Original line number Diff line number Diff line Loading @@ -8,8 +8,6 @@ use std::io::prelude::*; use std::ffi::AsOsStr; use std::mem; use std::net; use std::num::FromPrimitive; use std::num::Int; use std::path::Path; use std::ptr; use std::sync::{Once, ONCE_INIT, Arc, Mutex}; Loading Loading @@ -549,18 +547,18 @@ impl Ssl { } fn read(&self, buf: &mut [u8]) -> c_int { let len = cmp::min(<c_int as Int>::max_value() as usize, buf.len()) as c_int; let len = cmp::min(c_int::max_value() as usize, buf.len()) as c_int; unsafe { ffi::SSL_read(*self.ssl, buf.as_ptr() as *mut c_void, len) } } fn write(&self, buf: &[u8]) -> c_int { let len = cmp::min(<c_int as Int>::max_value() as usize, buf.len()) as c_int; let len = cmp::min(c_int::max_value() as usize, buf.len()) as c_int; unsafe { ffi::SSL_write(*self.ssl, buf.as_ptr() as *const c_void, len) } } fn get_error(&self, ret: c_int) -> LibSslError { let err = unsafe { ffi::SSL_get_error(*self.ssl, ret) }; match FromPrimitive::from_isize(err as isize) { match LibSslError::from_i32(err as i32) { Some(err) => err, None => unreachable!() } Loading Loading @@ -622,18 +620,35 @@ impl Ssl { } } #[derive(FromPrimitive, Debug)] macro_rules! make_LibSslError { ($($variant:ident = $value:ident),+) => { #[derive(Debug)] #[repr(i32)] enum LibSslError { ErrorNone = ffi::SSL_ERROR_NONE, ErrorSsl = ffi::SSL_ERROR_SSL, ErrorWantRead = ffi::SSL_ERROR_WANT_READ, ErrorWantWrite = ffi::SSL_ERROR_WANT_WRITE, ErrorWantX509Lookup = ffi::SSL_ERROR_WANT_X509_LOOKUP, ErrorSyscall = ffi::SSL_ERROR_SYSCALL, ErrorZeroReturn = ffi::SSL_ERROR_ZERO_RETURN, ErrorWantConnect = ffi::SSL_ERROR_WANT_CONNECT, ErrorWantAccept = ffi::SSL_ERROR_WANT_ACCEPT, $($variant = ffi::$value),+ } impl LibSslError { fn from_i32(val: i32) -> Option<LibSslError> { match val { $(ffi::$value => Some(LibSslError::$variant),)+ _ => None } } } } } make_LibSslError! { ErrorNone = SSL_ERROR_NONE, ErrorSsl = SSL_ERROR_SSL, ErrorWantRead = SSL_ERROR_WANT_READ, ErrorWantWrite = SSL_ERROR_WANT_WRITE, ErrorWantX509Lookup = SSL_ERROR_WANT_X509_LOOKUP, ErrorSyscall = SSL_ERROR_SYSCALL, ErrorZeroReturn = SSL_ERROR_ZERO_RETURN, ErrorWantConnect = SSL_ERROR_WANT_CONNECT, ErrorWantAccept = SSL_ERROR_WANT_ACCEPT } /// A stream wrapper which handles SSL encryption for an underlying stream. Loading openssl/src/x509/mod.rs +3 −4 Original line number Diff line number Diff line use libc::{c_char, c_int, c_long, c_uint}; use libc::{c_char, c_int, c_long, c_ulong, c_uint}; use std::io; use std::io::prelude::*; use std::cmp::Ordering; use std::ffi::CString; use std::iter::repeat; use std::mem; use std::num::SignedInt; use std::ptr; use asn1::{Asn1Time}; Loading Loading @@ -287,8 +286,8 @@ impl X509Generator { // While OpenSSL is actually OK to have negative serials // other libraries (for example, Go crypto) can drop // such certificates as invalid res.abs() // such certificates as invalid, so we clear the high bit ((res as c_ulong) >> 1) as c_long } /// Generates a private key and a signed certificate and returns them Loading Loading
openssl/src/bio/mod.rs +2 −3 Original line number Diff line number Diff line Loading @@ -3,7 +3,6 @@ use std::io; use std::io::prelude::*; use std::ptr; use std::cmp; use std::num::Int; use ffi; use ssl::error::{SslError}; Loading Loading @@ -61,7 +60,7 @@ impl MemBio { impl Read for MemBio { fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { let len = cmp::min(<c_int as Int>::max_value() as usize, buf.len()) as c_int; let len = cmp::min(c_int::max_value() as usize, buf.len()) as c_int; let ret = unsafe { ffi::BIO_read(self.bio, buf.as_ptr() as *mut c_void, len) }; Loading @@ -83,7 +82,7 @@ impl Read for MemBio { impl Write for MemBio { fn write(&mut self, buf: &[u8]) -> io::Result<usize> { let len = cmp::min(<c_int as Int>::max_value() as usize, buf.len()) as c_int; let len = cmp::min(c_int::max_value() as usize, buf.len()) as c_int; let ret = unsafe { ffi::BIO_write(self.bio, buf.as_ptr() as *const c_void, len) }; Loading
openssl/src/ssl/mod.rs +32 −17 Original line number Diff line number Diff line Loading @@ -8,8 +8,6 @@ use std::io::prelude::*; use std::ffi::AsOsStr; use std::mem; use std::net; use std::num::FromPrimitive; use std::num::Int; use std::path::Path; use std::ptr; use std::sync::{Once, ONCE_INIT, Arc, Mutex}; Loading Loading @@ -549,18 +547,18 @@ impl Ssl { } fn read(&self, buf: &mut [u8]) -> c_int { let len = cmp::min(<c_int as Int>::max_value() as usize, buf.len()) as c_int; let len = cmp::min(c_int::max_value() as usize, buf.len()) as c_int; unsafe { ffi::SSL_read(*self.ssl, buf.as_ptr() as *mut c_void, len) } } fn write(&self, buf: &[u8]) -> c_int { let len = cmp::min(<c_int as Int>::max_value() as usize, buf.len()) as c_int; let len = cmp::min(c_int::max_value() as usize, buf.len()) as c_int; unsafe { ffi::SSL_write(*self.ssl, buf.as_ptr() as *const c_void, len) } } fn get_error(&self, ret: c_int) -> LibSslError { let err = unsafe { ffi::SSL_get_error(*self.ssl, ret) }; match FromPrimitive::from_isize(err as isize) { match LibSslError::from_i32(err as i32) { Some(err) => err, None => unreachable!() } Loading Loading @@ -622,18 +620,35 @@ impl Ssl { } } #[derive(FromPrimitive, Debug)] macro_rules! make_LibSslError { ($($variant:ident = $value:ident),+) => { #[derive(Debug)] #[repr(i32)] enum LibSslError { ErrorNone = ffi::SSL_ERROR_NONE, ErrorSsl = ffi::SSL_ERROR_SSL, ErrorWantRead = ffi::SSL_ERROR_WANT_READ, ErrorWantWrite = ffi::SSL_ERROR_WANT_WRITE, ErrorWantX509Lookup = ffi::SSL_ERROR_WANT_X509_LOOKUP, ErrorSyscall = ffi::SSL_ERROR_SYSCALL, ErrorZeroReturn = ffi::SSL_ERROR_ZERO_RETURN, ErrorWantConnect = ffi::SSL_ERROR_WANT_CONNECT, ErrorWantAccept = ffi::SSL_ERROR_WANT_ACCEPT, $($variant = ffi::$value),+ } impl LibSslError { fn from_i32(val: i32) -> Option<LibSslError> { match val { $(ffi::$value => Some(LibSslError::$variant),)+ _ => None } } } } } make_LibSslError! { ErrorNone = SSL_ERROR_NONE, ErrorSsl = SSL_ERROR_SSL, ErrorWantRead = SSL_ERROR_WANT_READ, ErrorWantWrite = SSL_ERROR_WANT_WRITE, ErrorWantX509Lookup = SSL_ERROR_WANT_X509_LOOKUP, ErrorSyscall = SSL_ERROR_SYSCALL, ErrorZeroReturn = SSL_ERROR_ZERO_RETURN, ErrorWantConnect = SSL_ERROR_WANT_CONNECT, ErrorWantAccept = SSL_ERROR_WANT_ACCEPT } /// A stream wrapper which handles SSL encryption for an underlying stream. Loading
openssl/src/x509/mod.rs +3 −4 Original line number Diff line number Diff line use libc::{c_char, c_int, c_long, c_uint}; use libc::{c_char, c_int, c_long, c_ulong, c_uint}; use std::io; use std::io::prelude::*; use std::cmp::Ordering; use std::ffi::CString; use std::iter::repeat; use std::mem; use std::num::SignedInt; use std::ptr; use asn1::{Asn1Time}; Loading Loading @@ -287,8 +286,8 @@ impl X509Generator { // While OpenSSL is actually OK to have negative serials // other libraries (for example, Go crypto) can drop // such certificates as invalid res.abs() // such certificates as invalid, so we clear the high bit ((res as c_ulong) >> 1) as c_long } /// Generates a private key and a signed certificate and returns them Loading