De-~[] ssl

This commit is contained in:
Steven Fackler 2014-03-15 16:28:53 -07:00
parent fd5da25f67
commit a881f7d008
2 changed files with 11 additions and 10 deletions

View File

@ -1,5 +1,6 @@
use std::libc::c_ulong; use std::libc::c_ulong;
use std::io::IoError; use std::io::IoError;
use std::vec_ng::Vec;
use ssl::ffi; use ssl::ffi;
@ -11,7 +12,7 @@ pub enum SslError {
/// The SSL session has been closed by the other end /// The SSL session has been closed by the other end
SslSessionClosed, SslSessionClosed,
/// An error in the OpenSSL library /// An error in the OpenSSL library
OpenSslErrors(~[OpensslError]) OpenSslErrors(Vec<OpensslError>)
} }
/// An error from the OpenSSL library /// An error from the OpenSSL library
@ -44,7 +45,7 @@ impl SslError {
/// Creates a new `OpenSslErrors` with the current contents of the error /// Creates a new `OpenSslErrors` with the current contents of the error
/// stack. /// stack.
pub fn get() -> SslError { pub fn get() -> SslError {
let mut errs = ~[]; let mut errs = vec!();
loop { loop {
match unsafe { ffi::ERR_get_error() } { match unsafe { ffi::ERR_get_error() } {
0 => break, 0 => break,

View File

@ -4,7 +4,7 @@ use std::libc::{c_int, c_void, c_char};
use std::ptr; use std::ptr;
use std::io::{IoResult, IoError, OtherIoError, Stream, Reader, Writer}; use std::io::{IoResult, IoError, OtherIoError, Stream, Reader, Writer};
use std::unstable::mutex::NativeMutex; use std::unstable::mutex::NativeMutex;
use std::vec; use std::vec_ng::Vec;
use ssl::error::{SslError, SslSessionClosed, StreamError}; use ssl::error::{SslError, SslSessionClosed, StreamError};
@ -14,7 +14,7 @@ mod ffi;
mod tests; mod tests;
static mut VERIFY_IDX: c_int = -1; static mut VERIFY_IDX: c_int = -1;
static mut MUTEXES: *mut ~[NativeMutex] = 0 as *mut ~[NativeMutex]; static mut MUTEXES: *mut Vec<NativeMutex> = 0 as *mut Vec<NativeMutex>;
macro_rules! try_ssl( macro_rules! try_ssl(
($e:expr) => ( ($e:expr) => (
@ -37,7 +37,7 @@ fn init() {
VERIFY_IDX = verify_idx; VERIFY_IDX = verify_idx;
let num_locks = ffi::CRYPTO_num_locks(); let num_locks = ffi::CRYPTO_num_locks();
let mutexes = ~vec::from_fn(num_locks as uint, |_| NativeMutex::new()); let mutexes = ~Vec::from_fn(num_locks as uint, |_| NativeMutex::new());
MUTEXES = cast::transmute(mutexes); MUTEXES = cast::transmute(mutexes);
ffi::CRYPTO_set_locking_callback(locking_function); ffi::CRYPTO_set_locking_callback(locking_function);
@ -90,7 +90,7 @@ pub enum SslVerifyMode {
extern "C" fn locking_function(mode: c_int, n: c_int, _file: *c_char, extern "C" fn locking_function(mode: c_int, n: c_int, _file: *c_char,
_line: c_int) { _line: c_int) {
unsafe { unsafe {
let mutex = &mut (*MUTEXES)[n as uint]; let mutex = (*MUTEXES).get_mut(n as uint);
if mode & ffi::CRYPTO_LOCK != 0 { if mode & ffi::CRYPTO_LOCK != 0 {
mutex.lock_noguard(); mutex.lock_noguard();
@ -446,7 +446,7 @@ impl MemBio {
pub struct SslStream<S> { pub struct SslStream<S> {
priv stream: S, priv stream: S,
priv ssl: Ssl, priv ssl: Ssl,
priv buf: ~[u8] priv buf: Vec<u8>
} }
impl<S: Stream> SslStream<S> { impl<S: Stream> SslStream<S> {
@ -462,7 +462,7 @@ impl<S: Stream> SslStream<S> {
stream: stream, stream: stream,
ssl: ssl, ssl: ssl,
// Maximum TLS record size is 16k // Maximum TLS record size is 16k
buf: vec::from_elem(16 * 1024, 0u8) buf: Vec::from_elem(16 * 1024, 0u8)
}; };
match ssl.in_retry_wrapper(|ssl| { ssl.connect() }) { match ssl.in_retry_wrapper(|ssl| { ssl.connect() }) {
@ -490,7 +490,7 @@ impl<S: Stream> SslStream<S> {
match self.ssl.get_error(ret) { match self.ssl.get_error(ret) {
ErrorWantRead => { ErrorWantRead => {
try_ssl!(self.flush()); try_ssl!(self.flush());
let len = try_ssl!(self.stream.read(self.buf)); let len = try_ssl!(self.stream.read(self.buf.as_mut_slice()));
self.ssl.get_rbio().write(self.buf.slice_to(len)); self.ssl.get_rbio().write(self.buf.slice_to(len));
} }
ErrorWantWrite => { try_ssl!(self.flush()) } ErrorWantWrite => { try_ssl!(self.flush()) }
@ -503,7 +503,7 @@ impl<S: Stream> SslStream<S> {
fn write_through(&mut self) -> IoResult<()> { fn write_through(&mut self) -> IoResult<()> {
loop { loop {
match self.ssl.get_wbio().read(self.buf) { match self.ssl.get_wbio().read(self.buf.as_mut_slice()) {
Some(len) => try!(self.stream.write(self.buf.slice_to(len))), Some(len) => try!(self.stream.write(self.buf.slice_to(len))),
None => break None => break
}; };