rustup to current master

This commit is contained in:
Robin Gloster 2015-02-12 18:25:45 +01:00
parent 64287197a2
commit fabc1da31e
3 changed files with 31 additions and 31 deletions

View File

@ -7,10 +7,10 @@ use std::env;
use std::default::Default; use std::default::Default;
fn main() { fn main() {
let target = env::var_string("TARGET").unwrap(); let target = env::var("TARGET").unwrap();
if target.contains("android") { if target.contains("android") {
let path = env::var_string("OPENSSL_PATH").ok() let path = env::var("OPENSSL_PATH").ok()
.expect("Android does not provide openssl libraries, please build them yourself \ .expect("Android does not provide openssl libraries, please build them yourself \
(instructions in the README) and provide their location through \ (instructions in the README) and provide their location through \
$OPENSSL_PATH."); $OPENSSL_PATH.");
@ -56,6 +56,6 @@ fn build_old_openssl_shim(is_old: bool) {
&config, &config,
&["src/old_openssl_shim.c"]); &["src/old_openssl_shim.c"]);
let out_dir = env::var_string("OUT_DIR").unwrap(); let out_dir = env::var("OUT_DIR").unwrap();
println!("cargo:rustc-flags=-L native={} -l old_openssl_shim:static", out_dir); println!("cargo:rustc-flags=-L native={} -l old_openssl_shim:static", out_dir);
} }

View File

@ -42,16 +42,16 @@ pub fn init_ssl_cert_env_vars() {
fn put(var: &str, path: Path) { fn put(var: &str, path: Path) {
// Don't stomp over what anyone else has set // Don't stomp over what anyone else has set
match env::var(var) { match env::var(var) {
Some(..) => {} Ok(..) => {}
None => env::set_var(var, &path), Err(..) => env::set_var(var, &path),
} }
} }
} }
pub fn probe() -> ProbeResult { pub fn probe() -> ProbeResult {
let mut result = ProbeResult { let mut result = ProbeResult {
cert_file: env::var_string("SSL_CERT_FILE").ok().map(Path::new), cert_file: env::var("SSL_CERT_FILE").ok().map(Path::new),
cert_dir: env::var_string("SSL_CERT_DIR").ok().map(Path::new), cert_dir: env::var("SSL_CERT_DIR").ok().map(Path::new),
}; };
for certs_dir in find_certs_dirs().iter() { for certs_dir in find_certs_dirs().iter() {
// cert.pem looks to be an openssl 1.0.1 thing, while // cert.pem looks to be an openssl 1.0.1 thing, while

View File

@ -186,7 +186,7 @@ impl fmt::Debug for SslContext {
impl Drop for SslContext { impl Drop for SslContext {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { ffi::SSL_CTX_free(self.ctx.0) } unsafe { ffi::SSL_CTX_free(self.ctx.ptr) }
} }
} }
@ -207,11 +207,11 @@ impl SslContext {
pub fn set_verify(&mut self, mode: SslVerifyMode, pub fn set_verify(&mut self, mode: SslVerifyMode,
verify: Option<VerifyCallback>) { verify: Option<VerifyCallback>) {
unsafe { unsafe {
ffi::SSL_CTX_set_ex_data(self.ctx.0, VERIFY_IDX, ffi::SSL_CTX_set_ex_data(self.ctx.ptr, VERIFY_IDX,
mem::transmute(verify)); mem::transmute(verify));
let f: extern fn(c_int, *mut ffi::X509_STORE_CTX) -> c_int = let f: extern fn(c_int, *mut ffi::X509_STORE_CTX) -> c_int =
raw_verify; raw_verify;
ffi::SSL_CTX_set_verify(self.ctx.0, mode as c_int, Some(f)); ffi::SSL_CTX_set_verify(self.ctx.ptr, mode as c_int, Some(f));
} }
} }
@ -224,20 +224,20 @@ impl SslContext {
data: T) { data: T) {
let data = Box::new(data); let data = Box::new(data);
unsafe { unsafe {
ffi::SSL_CTX_set_ex_data(self.ctx.0, VERIFY_IDX, ffi::SSL_CTX_set_ex_data(self.ctx.ptr, VERIFY_IDX,
mem::transmute(Some(verify))); mem::transmute(Some(verify)));
ffi::SSL_CTX_set_ex_data(self.ctx.0, get_verify_data_idx::<T>(), ffi::SSL_CTX_set_ex_data(self.ctx.ptr, get_verify_data_idx::<T>(),
mem::transmute(data)); mem::transmute(data));
let f: extern fn(c_int, *mut ffi::X509_STORE_CTX) -> c_int = let f: extern fn(c_int, *mut ffi::X509_STORE_CTX) -> c_int =
raw_verify_with_data::<T>; raw_verify_with_data::<T>;
ffi::SSL_CTX_set_verify(self.ctx.0, mode as c_int, Some(f)); ffi::SSL_CTX_set_verify(self.ctx.ptr, mode as c_int, Some(f));
} }
} }
/// Sets verification depth /// Sets verification depth
pub fn set_verify_depth(&mut self, depth: u32) { pub fn set_verify_depth(&mut self, depth: u32) {
unsafe { unsafe {
ffi::SSL_CTX_set_verify_depth(self.ctx.0, depth as c_int); ffi::SSL_CTX_set_verify_depth(self.ctx.ptr, depth as c_int);
} }
} }
@ -247,7 +247,7 @@ impl SslContext {
wrap_ssl_result( wrap_ssl_result(
unsafe { unsafe {
let file = CString::from_slice(file.as_vec()); let file = CString::from_slice(file.as_vec());
ffi::SSL_CTX_load_verify_locations(self.ctx.0, file.as_ptr(), ptr::null()) ffi::SSL_CTX_load_verify_locations(self.ctx.ptr, file.as_ptr(), ptr::null())
}) })
} }
@ -257,7 +257,7 @@ impl SslContext {
wrap_ssl_result( wrap_ssl_result(
unsafe { unsafe {
let file = CString::from_slice(file.as_vec()); let file = CString::from_slice(file.as_vec());
ffi::SSL_CTX_use_certificate_file(self.ctx.0, file.as_ptr(), file_type as c_int) ffi::SSL_CTX_use_certificate_file(self.ctx.ptr, file.as_ptr(), file_type as c_int)
}) })
} }
@ -267,7 +267,7 @@ impl SslContext {
wrap_ssl_result( wrap_ssl_result(
unsafe { unsafe {
let file = CString::from_slice(file.as_vec()); let file = CString::from_slice(file.as_vec());
ffi::SSL_CTX_use_PrivateKey_file(self.ctx.0, file.as_ptr(), file_type as c_int) ffi::SSL_CTX_use_PrivateKey_file(self.ctx.ptr, file.as_ptr(), file_type as c_int)
}) })
} }
@ -275,7 +275,7 @@ impl SslContext {
wrap_ssl_result( wrap_ssl_result(
unsafe { unsafe {
let cipher_list = CString::from_slice(cipher_list.as_bytes()); let cipher_list = CString::from_slice(cipher_list.as_bytes());
ffi::SSL_CTX_set_cipher_list(self.ctx.0, cipher_list.as_ptr()) ffi::SSL_CTX_set_cipher_list(self.ctx.ptr, cipher_list.as_ptr())
}) })
} }
} }
@ -309,13 +309,13 @@ impl fmt::Debug for Ssl {
impl Drop for Ssl { impl Drop for Ssl {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { ffi::SSL_free(self.ssl.0) } unsafe { ffi::SSL_free(self.ssl.ptr) }
} }
} }
impl Ssl { impl Ssl {
pub fn new(ctx: &SslContext) -> Result<Ssl, SslError> { pub fn new(ctx: &SslContext) -> Result<Ssl, SslError> {
let ssl = unsafe { ffi::SSL_new(ctx.ctx.0) }; let ssl = unsafe { ffi::SSL_new(ctx.ctx.ptr) };
if ssl == ptr::null_mut() { if ssl == ptr::null_mut() {
return Err(SslError::get()); return Err(SslError::get());
} }
@ -324,16 +324,16 @@ impl Ssl {
let rbio = try!(MemBio::new()); let rbio = try!(MemBio::new());
let wbio = try!(MemBio::new()); let wbio = try!(MemBio::new());
unsafe { ffi::SSL_set_bio(ssl.ssl.0, rbio.unwrap(), wbio.unwrap()) } unsafe { ffi::SSL_set_bio(ssl.ssl.ptr, rbio.unwrap(), wbio.unwrap()) }
Ok(ssl) Ok(ssl)
} }
fn get_rbio<'a>(&'a self) -> MemBioRef<'a> { fn get_rbio<'a>(&'a self) -> MemBioRef<'a> {
unsafe { self.wrap_bio(ffi::SSL_get_rbio(self.ssl.0)) } unsafe { self.wrap_bio(ffi::SSL_get_rbio(self.ssl.ptr)) }
} }
fn get_wbio<'a>(&'a self) -> MemBioRef<'a> { fn get_wbio<'a>(&'a self) -> MemBioRef<'a> {
unsafe { self.wrap_bio(ffi::SSL_get_wbio(self.ssl.0)) } unsafe { self.wrap_bio(ffi::SSL_get_wbio(self.ssl.ptr)) }
} }
fn wrap_bio<'a>(&'a self, bio: *mut ffi::BIO) -> MemBioRef<'a> { fn wrap_bio<'a>(&'a self, bio: *mut ffi::BIO) -> MemBioRef<'a> {
@ -345,25 +345,25 @@ impl Ssl {
} }
fn connect(&self) -> c_int { fn connect(&self) -> c_int {
unsafe { ffi::SSL_connect(self.ssl.0) } unsafe { ffi::SSL_connect(self.ssl.ptr) }
} }
fn accept(&self) -> c_int { fn accept(&self) -> c_int {
unsafe { ffi::SSL_accept(self.ssl.0) } unsafe { ffi::SSL_accept(self.ssl.ptr) }
} }
fn read(&self, buf: &mut [u8]) -> c_int { fn read(&self, buf: &mut [u8]) -> c_int {
unsafe { ffi::SSL_read(self.ssl.0, buf.as_ptr() as *mut c_void, unsafe { ffi::SSL_read(self.ssl.ptr, buf.as_ptr() as *mut c_void,
buf.len() as c_int) } buf.len() as c_int) }
} }
fn write_all(&self, buf: &[u8]) -> c_int { fn write_all(&self, buf: &[u8]) -> c_int {
unsafe { ffi::SSL_write(self.ssl.0, buf.as_ptr() as *const c_void, unsafe { ffi::SSL_write(self.ssl.ptr, buf.as_ptr() as *const c_void,
buf.len() as c_int) } buf.len() as c_int) }
} }
fn get_error(&self, ret: c_int) -> LibSslError { fn get_error(&self, ret: c_int) -> LibSslError {
let err = unsafe { ffi::SSL_get_error(self.ssl.0, ret) }; let err = unsafe { ffi::SSL_get_error(self.ssl.ptr, ret) };
match FromPrimitive::from_int(err as isize) { match FromPrimitive::from_int(err as isize) {
Some(err) => err, Some(err) => err,
None => unreachable!() None => unreachable!()
@ -378,7 +378,7 @@ impl Ssl {
// SSL_ctrl(s,SSL_CTRL_SET_TLSEXT_HOSTNAME,TLSEXT_NAMETYPE_host_name,(char *)name) // SSL_ctrl(s,SSL_CTRL_SET_TLSEXT_HOSTNAME,TLSEXT_NAMETYPE_host_name,(char *)name)
let hostname = CString::from_slice(hostname.as_bytes()); let hostname = CString::from_slice(hostname.as_bytes());
ffi::SSL_ctrl(self.ssl.0, ffi::SSL_CTRL_SET_TLSEXT_HOSTNAME, ffi::SSL_ctrl(self.ssl.ptr, ffi::SSL_CTRL_SET_TLSEXT_HOSTNAME,
ffi::TLSEXT_NAMETYPE_host_name, ffi::TLSEXT_NAMETYPE_host_name,
hostname.as_ptr() as *mut c_void) hostname.as_ptr() as *mut c_void)
}; };
@ -393,7 +393,7 @@ impl Ssl {
pub fn get_peer_certificate(&self) -> Option<X509> { pub fn get_peer_certificate(&self) -> Option<X509> {
unsafe { unsafe {
let ptr = ffi::SSL_get_peer_certificate(self.ssl.0); let ptr = ffi::SSL_get_peer_certificate(self.ssl.ptr);
if ptr.is_null() { if ptr.is_null() {
None None
} else { } else {
@ -534,7 +534,7 @@ impl<S: Stream> SslStream<S> {
/// either None, indicating no compression is in use, or a string /// either None, indicating no compression is in use, or a string
/// with the compression name. /// with the compression name.
pub fn get_compression(&self) -> Option<String> { pub fn get_compression(&self) -> Option<String> {
let ptr = unsafe { ffi::SSL_get_current_compression(self.ssl.ssl.0) }; let ptr = unsafe { ffi::SSL_get_current_compression(self.ssl.ssl.ptr) };
if ptr == ptr::null() { if ptr == ptr::null() {
return None; return None;
} }