Loading openssl-sys/Cargo.toml +3 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,9 @@ tlsv1_1 = [] sslv2 = [] aes_xts = [] [dependencies] libc = "0.1" [build-dependencies] pkg-config = "0.3" gcc = "0.3" Loading openssl-sys/src/lib.rs +1 −1 Original line number Diff line number Diff line #![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)] #![allow(dead_code)] #![feature(core, old_io, libc, old_path, std_misc, env)] #![feature(core, old_io, old_path, std_misc, env)] #![doc(html_root_url="https://sfackler.github.io/rust-openssl/doc/openssl-sys")] extern crate libc; Loading openssl/Cargo.toml +3 −0 Original line number Diff line number Diff line Loading @@ -19,5 +19,8 @@ aes_xts = ["openssl-sys/aes_xts"] path = "../openssl-sys" version = "0.4.3" [dependencies] libc = "0.1" [dev-dependencies] rustc-serialize = "0.2" openssl/src/bio/mod.rs +28 −30 Original line number Diff line number Diff line use libc::{c_void, c_int}; use std::old_io::{EndOfFile, IoResult, IoError, OtherIoError}; use std::old_io::{Reader, Writer}; 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 @@ -57,49 +59,45 @@ impl MemBio { } } impl Reader for MemBio { fn read(&mut self, buf: &mut [u8]) -> IoResult<usize> { 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 ret = unsafe { ffi::BIO_read(self.bio, buf.as_ptr() as *mut c_void, buf.len() as c_int) ffi::BIO_read(self.bio, buf.as_ptr() as *mut c_void, len) }; if ret <= 0 { let is_eof = unsafe { ffi::BIO_eof(self.bio) }; let err = if is_eof { IoError { kind: EndOfFile, desc: "MemBio EOF", detail: None } if is_eof { Ok(0) } else { IoError { kind: OtherIoError, desc: "MemBio read error", detail: Some(format!("{:?}", SslError::get())) Err(io::Error::new(io::ErrorKind::Other, "MemBio read error", Some(format!("{:?}", SslError::get())))) } }; Err(err) } else { Ok(ret as usize) } } } impl Writer for MemBio { fn write_all(&mut self, buf: &[u8]) -> IoResult<()> { 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 ret = unsafe { ffi::BIO_write(self.bio, buf.as_ptr() as *const c_void, buf.len() as c_int) ffi::BIO_write(self.bio, buf.as_ptr() as *const c_void, len) }; if buf.len() != ret as usize { Err(IoError { kind: OtherIoError, desc: "MemBio write error", detail: Some(format!("{:?}", SslError::get())) }) if ret < 0 { Err(io::Error::new(io::ErrorKind::Other, "MemBio write error", Some(format!("{:?}", SslError::get())))) } else { Ok(()) Ok(ret as usize) } } fn flush(&mut self) -> io::Result<()> { Ok(()) } } openssl/src/crypto/hash.rs +11 −6 Original line number Diff line number Diff line use libc::c_uint; use std::iter::repeat; use std::old_io::{IoError, Writer}; use std::io::prelude::*; use std::io; use ffi; Loading Loading @@ -73,10 +74,10 @@ use self::State::*; /// assert_eq!(res, spec); /// ``` /// /// Use the `Writer` trait to supply the input in chunks. /// Use the `Write` trait to supply the input in chunks. /// /// ``` /// use std::old_io::Writer; /// use std::io::prelude::*; /// use openssl::crypto::hash::{Hasher, Type}; /// let data = [b"\x42\xF4", b"\x97\xE0"]; /// let spec = b"\x7c\x43\x0f\x17\x8a\xef\xdf\x14\x87\xfe\xe7\x14\x4e\x96\x41\xe2"; Loading Loading @@ -168,10 +169,14 @@ impl Hasher { } } impl Writer for Hasher { impl Write for Hasher { #[inline] fn write_all(&mut self, buf: &[u8]) -> Result<(), IoError> { fn write(&mut self, buf: &[u8]) -> io::Result<usize> { self.update(buf); Ok(buf.len()) } fn flush(&mut self) -> io::Result<()> { Ok(()) } } Loading Loading @@ -213,7 +218,7 @@ pub fn hash(t: Type, data: &[u8]) -> Vec<u8> { mod tests { use serialize::hex::{FromHex, ToHex}; use super::{hash, Hasher, Type}; use std::old_io::Writer; use std::io::prelude::*; fn hash_test(hashtype: Type, hashtest: &(&str, &str)) { let res = hash(hashtype, &*hashtest.0.from_hex().unwrap()); Loading Loading
openssl-sys/Cargo.toml +3 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,9 @@ tlsv1_1 = [] sslv2 = [] aes_xts = [] [dependencies] libc = "0.1" [build-dependencies] pkg-config = "0.3" gcc = "0.3" Loading
openssl-sys/src/lib.rs +1 −1 Original line number Diff line number Diff line #![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)] #![allow(dead_code)] #![feature(core, old_io, libc, old_path, std_misc, env)] #![feature(core, old_io, old_path, std_misc, env)] #![doc(html_root_url="https://sfackler.github.io/rust-openssl/doc/openssl-sys")] extern crate libc; Loading
openssl/Cargo.toml +3 −0 Original line number Diff line number Diff line Loading @@ -19,5 +19,8 @@ aes_xts = ["openssl-sys/aes_xts"] path = "../openssl-sys" version = "0.4.3" [dependencies] libc = "0.1" [dev-dependencies] rustc-serialize = "0.2"
openssl/src/bio/mod.rs +28 −30 Original line number Diff line number Diff line use libc::{c_void, c_int}; use std::old_io::{EndOfFile, IoResult, IoError, OtherIoError}; use std::old_io::{Reader, Writer}; 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 @@ -57,49 +59,45 @@ impl MemBio { } } impl Reader for MemBio { fn read(&mut self, buf: &mut [u8]) -> IoResult<usize> { 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 ret = unsafe { ffi::BIO_read(self.bio, buf.as_ptr() as *mut c_void, buf.len() as c_int) ffi::BIO_read(self.bio, buf.as_ptr() as *mut c_void, len) }; if ret <= 0 { let is_eof = unsafe { ffi::BIO_eof(self.bio) }; let err = if is_eof { IoError { kind: EndOfFile, desc: "MemBio EOF", detail: None } if is_eof { Ok(0) } else { IoError { kind: OtherIoError, desc: "MemBio read error", detail: Some(format!("{:?}", SslError::get())) Err(io::Error::new(io::ErrorKind::Other, "MemBio read error", Some(format!("{:?}", SslError::get())))) } }; Err(err) } else { Ok(ret as usize) } } } impl Writer for MemBio { fn write_all(&mut self, buf: &[u8]) -> IoResult<()> { 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 ret = unsafe { ffi::BIO_write(self.bio, buf.as_ptr() as *const c_void, buf.len() as c_int) ffi::BIO_write(self.bio, buf.as_ptr() as *const c_void, len) }; if buf.len() != ret as usize { Err(IoError { kind: OtherIoError, desc: "MemBio write error", detail: Some(format!("{:?}", SslError::get())) }) if ret < 0 { Err(io::Error::new(io::ErrorKind::Other, "MemBio write error", Some(format!("{:?}", SslError::get())))) } else { Ok(()) Ok(ret as usize) } } fn flush(&mut self) -> io::Result<()> { Ok(()) } }
openssl/src/crypto/hash.rs +11 −6 Original line number Diff line number Diff line use libc::c_uint; use std::iter::repeat; use std::old_io::{IoError, Writer}; use std::io::prelude::*; use std::io; use ffi; Loading Loading @@ -73,10 +74,10 @@ use self::State::*; /// assert_eq!(res, spec); /// ``` /// /// Use the `Writer` trait to supply the input in chunks. /// Use the `Write` trait to supply the input in chunks. /// /// ``` /// use std::old_io::Writer; /// use std::io::prelude::*; /// use openssl::crypto::hash::{Hasher, Type}; /// let data = [b"\x42\xF4", b"\x97\xE0"]; /// let spec = b"\x7c\x43\x0f\x17\x8a\xef\xdf\x14\x87\xfe\xe7\x14\x4e\x96\x41\xe2"; Loading Loading @@ -168,10 +169,14 @@ impl Hasher { } } impl Writer for Hasher { impl Write for Hasher { #[inline] fn write_all(&mut self, buf: &[u8]) -> Result<(), IoError> { fn write(&mut self, buf: &[u8]) -> io::Result<usize> { self.update(buf); Ok(buf.len()) } fn flush(&mut self) -> io::Result<()> { Ok(()) } } Loading Loading @@ -213,7 +218,7 @@ pub fn hash(t: Type, data: &[u8]) -> Vec<u8> { mod tests { use serialize::hex::{FromHex, ToHex}; use super::{hash, Hasher, Type}; use std::old_io::Writer; use std::io::prelude::*; fn hash_test(hashtype: Type, hashtest: &(&str, &str)) { let res = hash(hashtype, &*hashtest.0.from_hex().unwrap()); Loading