aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/crypto
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2015-02-24 23:01:57 -0800
committerSteven Fackler <[email protected]>2015-02-24 23:01:57 -0800
commit6991cc6a30c7f2e480145c4d0c5692924d293043 (patch)
tree7077d07e5027dacb26ff86f0b1ed93af2c59f4c4 /openssl/src/crypto
parentSwitch to cargo liblibc (diff)
downloadrust-openssl-6991cc6a30c7f2e480145c4d0c5692924d293043.tar.xz
rust-openssl-6991cc6a30c7f2e480145c4d0c5692924d293043.zip
Convert to new IO.
Diffstat (limited to 'openssl/src/crypto')
-rw-r--r--openssl/src/crypto/hash.rs17
-rw-r--r--openssl/src/crypto/hmac.rs17
-rw-r--r--openssl/src/crypto/pkey.rs8
3 files changed, 27 insertions, 15 deletions
diff --git a/openssl/src/crypto/hash.rs b/openssl/src/crypto/hash.rs
index f81532c9..29e180e5 100644
--- a/openssl/src/crypto/hash.rs
+++ b/openssl/src/crypto/hash.rs
@@ -1,6 +1,7 @@
use libc::c_uint;
use std::iter::repeat;
-use std::old_io::{IoError, Writer};
+use std::io::prelude::*;
+use std::io;
use ffi;
@@ -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";
@@ -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(())
}
}
@@ -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());
diff --git a/openssl/src/crypto/hmac.rs b/openssl/src/crypto/hmac.rs
index 55007ceb..01874aec 100644
--- a/openssl/src/crypto/hmac.rs
+++ b/openssl/src/crypto/hmac.rs
@@ -16,7 +16,8 @@
use libc::{c_int, c_uint};
use std::iter::repeat;
-use std::old_io::{IoError, Writer};
+use std::io;
+use std::io::prelude::*;
use crypto::hash::Type;
use ffi;
@@ -46,10 +47,10 @@ use self::State::*;
/// assert_eq!(spec, res);
/// ```
///
-/// 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::Type;
/// use openssl::crypto::hmac::HMAC;
/// let key = b"Jefe";
@@ -150,10 +151,14 @@ impl HMAC {
}
}
-impl Writer for HMAC {
+impl Write for HMAC {
#[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(())
}
}
@@ -197,7 +202,7 @@ mod tests {
use crypto::hash::Type;
use crypto::hash::Type::*;
use super::{hmac, HMAC};
- use std::old_io::Writer;
+ use std::io::prelude::*;
fn test_hmac(ty: Type, tests: &[(Vec<u8>, Vec<u8>, Vec<u8>)]) {
for &(ref key, ref data, ref res) in tests.iter() {
diff --git a/openssl/src/crypto/pkey.rs b/openssl/src/crypto/pkey.rs
index c20fae4f..ac910e0b 100644
--- a/openssl/src/crypto/pkey.rs
+++ b/openssl/src/crypto/pkey.rs
@@ -1,4 +1,5 @@
use libc::{c_int, c_uint, c_ulong};
+use std::io::prelude::*;
use std::iter::repeat;
use std::mem;
use std::ptr;
@@ -142,15 +143,16 @@ impl PKey {
/// Stores private key as a PEM
// FIXME: also add password and encryption
- pub fn write_pem(&self, writer: &mut Writer/*, password: Option<String>*/) -> Result<(), SslError> {
+ pub fn write_pem<W: Write>(&self, writer: &mut W/*, password: Option<String>*/) -> Result<(), SslError> {
let mut mem_bio = try!(MemBio::new());
unsafe {
try_ssl!(ffi::PEM_write_bio_PrivateKey(mem_bio.get_handle(), self.evp, ptr::null(),
ptr::null_mut(), -1, None, ptr::null_mut()));
}
- let buf = try!(mem_bio.read_to_end().map_err(StreamError));
- writer.write_all(buf.as_slice()).map_err(StreamError)
+ let mut buf = vec![];
+ try!(mem_bio.read_to_end(&mut buf).map_err(StreamError));
+ writer.write_all(&buf).map_err(StreamError)
}
/**