Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
fde7fbd03b
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "openssl"
|
name = "openssl"
|
||||||
version = "0.2.10"
|
version = "0.2.11"
|
||||||
authors = ["Steven Fackler <sfackler@gmail.com>"]
|
authors = ["Steven Fackler <sfackler@gmail.com>"]
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
description = "OpenSSL bindings"
|
description = "OpenSSL bindings"
|
||||||
|
|
@ -17,4 +17,4 @@ aes_xts = ["openssl-sys/aes_xts"]
|
||||||
|
|
||||||
[dependencies.openssl-sys]
|
[dependencies.openssl-sys]
|
||||||
path = "openssl-sys"
|
path = "openssl-sys"
|
||||||
version = "0.2.10"
|
version = "0.2.11"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "openssl-sys"
|
name = "openssl-sys"
|
||||||
version = "0.2.10"
|
version = "0.2.11"
|
||||||
authors = ["Alex Crichton <alex@alexcrichton.com>",
|
authors = ["Alex Crichton <alex@alexcrichton.com>",
|
||||||
"Steven Fackler <sfackler@gmail.com>"]
|
"Steven Fackler <sfackler@gmail.com>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
|
||||||
|
|
@ -211,14 +211,15 @@ pub fn init() {
|
||||||
static mut INIT: Once = ONCE_INIT;
|
static mut INIT: Once = ONCE_INIT;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
INIT.doit(|| {
|
INIT.call_once(|| {
|
||||||
SSL_library_init();
|
SSL_library_init();
|
||||||
SSL_load_error_strings();
|
SSL_load_error_strings();
|
||||||
|
|
||||||
let num_locks = CRYPTO_num_locks();
|
let num_locks = CRYPTO_num_locks();
|
||||||
let mutexes = box Vec::from_fn(num_locks as uint, |_| MUTEX_INIT);
|
let mutexes = box range(0, num_locks).map(|_| MUTEX_INIT).collect::<Vec<_>>();
|
||||||
MUTEXES = mem::transmute(mutexes);
|
MUTEXES = mem::transmute(mutexes);
|
||||||
let guards: Box<Vec<Option<MutexGuard<()>>>> = box Vec::from_fn(num_locks as uint, |_| None);
|
let guards: Box<Vec<Option<MutexGuard<()>>>> =
|
||||||
|
box range(0, num_locks).map(|_| None).collect();
|
||||||
GUARDS = mem::transmute(guards);
|
GUARDS = mem::transmute(guards);
|
||||||
|
|
||||||
CRYPTO_set_locking_callback(locking_function);
|
CRYPTO_set_locking_callback(locking_function);
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,14 @@
|
||||||
use libc::{c_int, c_ulong, c_void};
|
use libc::{c_int, c_ulong, c_void};
|
||||||
use std::{fmt, ptr};
|
|
||||||
use std::c_str::CString;
|
use std::c_str::CString;
|
||||||
|
use std::cmp::Ordering;
|
||||||
|
use std::{fmt, ptr};
|
||||||
|
|
||||||
use ffi;
|
use ffi;
|
||||||
use ssl::error::SslError;
|
use ssl::error::SslError;
|
||||||
|
|
||||||
pub struct BigNum(*mut ffi::BIGNUM);
|
pub struct BigNum(*mut ffi::BIGNUM);
|
||||||
|
|
||||||
#[deriving(Copy)]
|
#[derive(Copy)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub enum RNGProperty {
|
pub enum RNGProperty {
|
||||||
MsbMaybeZero = -1,
|
MsbMaybeZero = -1,
|
||||||
|
|
@ -371,11 +372,11 @@ impl BigNum {
|
||||||
unsafe {
|
unsafe {
|
||||||
let res = ffi::BN_ucmp(self.raw(), oth.raw()) as i32;
|
let res = ffi::BN_ucmp(self.raw(), oth.raw()) as i32;
|
||||||
if res < 0 {
|
if res < 0 {
|
||||||
Less
|
Ordering::Less
|
||||||
} else if res > 0 {
|
} else if res > 0 {
|
||||||
Greater
|
Ordering::Greater
|
||||||
} else {
|
} else {
|
||||||
Equal
|
Ordering::Equal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -466,11 +467,11 @@ impl PartialOrd for BigNum {
|
||||||
let v = ffi::BN_cmp(self.raw(), oth.raw());
|
let v = ffi::BN_cmp(self.raw(), oth.raw());
|
||||||
let ret =
|
let ret =
|
||||||
if v == 0 {
|
if v == 0 {
|
||||||
Equal
|
Ordering::Equal
|
||||||
} else if v < 0 {
|
} else if v < 0 {
|
||||||
Less
|
Ordering::Less
|
||||||
} else {
|
} else {
|
||||||
Greater
|
Ordering::Greater
|
||||||
};
|
};
|
||||||
Some(ret)
|
Some(ret)
|
||||||
}
|
}
|
||||||
|
|
@ -488,6 +489,7 @@ impl Drop for BigNum {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod unchecked {
|
pub mod unchecked {
|
||||||
|
use std::ops::{Add, Div, Mul, Neg, Rem, Shl, Shr, Sub};
|
||||||
use ffi;
|
use ffi;
|
||||||
use super::{BigNum};
|
use super::{BigNum};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
use libc::c_uint;
|
use libc::c_uint;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
use std::iter::repeat;
|
||||||
|
|
||||||
use ffi;
|
use ffi;
|
||||||
|
|
||||||
#[deriving(Copy)]
|
#[derive(Copy)]
|
||||||
pub enum HashType {
|
pub enum HashType {
|
||||||
MD5,
|
MD5,
|
||||||
SHA1,
|
SHA1,
|
||||||
|
|
@ -101,7 +102,7 @@ impl Hasher {
|
||||||
* initialization and its context for reuse
|
* initialization and its context for reuse
|
||||||
*/
|
*/
|
||||||
pub fn finalize_reuse(self) -> (Vec<u8>, HasherContext) {
|
pub fn finalize_reuse(self) -> (Vec<u8>, HasherContext) {
|
||||||
let mut res = Vec::from_elem(self.len, 0u8);
|
let mut res = repeat(0u8).take(self.len).collect::<Vec<_>>();
|
||||||
unsafe {
|
unsafe {
|
||||||
ffi::EVP_DigestFinal_ex(self.ctx.ptr, res.as_mut_ptr(), ptr::null_mut())
|
ffi::EVP_DigestFinal_ex(self.ctx.ptr, res.as_mut_ptr(), ptr::null_mut())
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use libc::{c_int, c_uint};
|
use libc::{c_int, c_uint};
|
||||||
|
use std::iter::repeat;
|
||||||
|
|
||||||
use crypto::hash;
|
use crypto::hash;
|
||||||
use ffi;
|
use ffi;
|
||||||
|
|
@ -52,7 +53,7 @@ impl HMAC {
|
||||||
|
|
||||||
pub fn finalize(&mut self) -> Vec<u8> {
|
pub fn finalize(&mut self) -> Vec<u8> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut res = Vec::from_elem(self.len, 0u8);
|
let mut res: Vec<u8> = repeat(0).take(self.len).collect();
|
||||||
let mut outlen = 0;
|
let mut outlen = 0;
|
||||||
ffi::HMAC_Final(&mut self.ctx, res.as_mut_ptr(), &mut outlen);
|
ffi::HMAC_Final(&mut self.ctx, res.as_mut_ptr(), &mut outlen);
|
||||||
assert!(self.len == outlen as uint);
|
assert!(self.len == outlen as uint);
|
||||||
|
|
@ -71,31 +72,32 @@ impl Drop for HMAC {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use std::iter::repeat;
|
||||||
use serialize::hex::FromHex;
|
use serialize::hex::FromHex;
|
||||||
use crypto::hash::HashType::{mod, MD5, SHA1, SHA224, SHA256, SHA384, SHA512};
|
use crypto::hash::HashType::{self, MD5, SHA1, SHA224, SHA256, SHA384, SHA512};
|
||||||
use super::HMAC;
|
use super::HMAC;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_hmac_md5() {
|
fn test_hmac_md5() {
|
||||||
// test vectors from RFC 2202
|
// test vectors from RFC 2202
|
||||||
let tests: [(Vec<u8>, Vec<u8>, Vec<u8>); 7] = [
|
let tests: [(Vec<u8>, Vec<u8>, Vec<u8>); 7] = [
|
||||||
(Vec::from_elem(16, 0x0b_u8), b"Hi There".to_vec(),
|
(repeat(0x0b_u8).take(16).collect(), b"Hi There".to_vec(),
|
||||||
"9294727a3638bb1c13f48ef8158bfc9d".from_hex().unwrap()),
|
"9294727a3638bb1c13f48ef8158bfc9d".from_hex().unwrap()),
|
||||||
(b"Jefe".to_vec(),
|
(b"Jefe".to_vec(),
|
||||||
b"what do ya want for nothing?".to_vec(),
|
b"what do ya want for nothing?".to_vec(),
|
||||||
"750c783e6ab0b503eaa86e310a5db738".from_hex().unwrap()),
|
"750c783e6ab0b503eaa86e310a5db738".from_hex().unwrap()),
|
||||||
(Vec::from_elem(16, 0xaa_u8), Vec::from_elem(50, 0xdd_u8),
|
(repeat(0xaa_u8).take(16).collect(), repeat(0xdd_u8).take(50).collect(),
|
||||||
"56be34521d144c88dbb8c733f0e8b3f6".from_hex().unwrap()),
|
"56be34521d144c88dbb8c733f0e8b3f6".from_hex().unwrap()),
|
||||||
("0102030405060708090a0b0c0d0e0f10111213141516171819".from_hex().unwrap(),
|
("0102030405060708090a0b0c0d0e0f10111213141516171819".from_hex().unwrap(),
|
||||||
Vec::from_elem(50, 0xcd_u8),
|
repeat(0xcd_u8).take(50).collect(),
|
||||||
"697eaf0aca3a3aea3a75164746ffaa79".from_hex().unwrap()),
|
"697eaf0aca3a3aea3a75164746ffaa79".from_hex().unwrap()),
|
||||||
(Vec::from_elem(16, 0x0c_u8),
|
(repeat(0x0c_u8).take(16).collect(),
|
||||||
b"Test With Truncation".to_vec(),
|
b"Test With Truncation".to_vec(),
|
||||||
"56461ef2342edc00f9bab995690efd4c".from_hex().unwrap()),
|
"56461ef2342edc00f9bab995690efd4c".from_hex().unwrap()),
|
||||||
(Vec::from_elem(80, 0xaa_u8),
|
(repeat(0xaa_u8).take(80).collect(),
|
||||||
b"Test Using Larger Than Block-Size Key - Hash Key First".to_vec(),
|
b"Test Using Larger Than Block-Size Key - Hash Key First".to_vec(),
|
||||||
"6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd".from_hex().unwrap()),
|
"6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd".from_hex().unwrap()),
|
||||||
(Vec::from_elem(80, 0xaa_u8),
|
(repeat(0xaa_u8).take(80).collect(),
|
||||||
b"Test Using Larger Than Block-Size Key \
|
b"Test Using Larger Than Block-Size Key \
|
||||||
and Larger Than One Block-Size Data".to_vec(),
|
and Larger Than One Block-Size Data".to_vec(),
|
||||||
"6f630fad67cda0ee1fb1f562db3aa53e".from_hex().unwrap())
|
"6f630fad67cda0ee1fb1f562db3aa53e".from_hex().unwrap())
|
||||||
|
|
@ -112,23 +114,23 @@ mod tests {
|
||||||
fn test_hmac_sha1() {
|
fn test_hmac_sha1() {
|
||||||
// test vectors from RFC 2202
|
// test vectors from RFC 2202
|
||||||
let tests: [(Vec<u8>, Vec<u8>, Vec<u8>); 7] = [
|
let tests: [(Vec<u8>, Vec<u8>, Vec<u8>); 7] = [
|
||||||
(Vec::from_elem(20, 0x0b_u8), b"Hi There".to_vec(),
|
(repeat(0x0b_u8).take(20).collect(), b"Hi There".to_vec(),
|
||||||
"b617318655057264e28bc0b6fb378c8ef146be00".from_hex().unwrap()),
|
"b617318655057264e28bc0b6fb378c8ef146be00".from_hex().unwrap()),
|
||||||
(b"Jefe".to_vec(),
|
(b"Jefe".to_vec(),
|
||||||
b"what do ya want for nothing?".to_vec(),
|
b"what do ya want for nothing?".to_vec(),
|
||||||
"effcdf6ae5eb2fa2d27416d5f184df9c259a7c79".from_hex().unwrap()),
|
"effcdf6ae5eb2fa2d27416d5f184df9c259a7c79".from_hex().unwrap()),
|
||||||
(Vec::from_elem(20, 0xaa_u8), Vec::from_elem(50, 0xdd_u8),
|
(repeat(0xaa_u8).take(20).collect(), repeat(0xdd_u8).take(50).collect(),
|
||||||
"125d7342b9ac11cd91a39af48aa17b4f63f175d3".from_hex().unwrap()),
|
"125d7342b9ac11cd91a39af48aa17b4f63f175d3".from_hex().unwrap()),
|
||||||
("0102030405060708090a0b0c0d0e0f10111213141516171819".from_hex().unwrap(),
|
("0102030405060708090a0b0c0d0e0f10111213141516171819".from_hex().unwrap(),
|
||||||
Vec::from_elem(50, 0xcd_u8),
|
repeat(0xcd_u8).take(50).collect(),
|
||||||
"4c9007f4026250c6bc8414f9bf50c86c2d7235da".from_hex().unwrap()),
|
"4c9007f4026250c6bc8414f9bf50c86c2d7235da".from_hex().unwrap()),
|
||||||
(Vec::from_elem(20, 0x0c_u8),
|
(repeat(0x0c_u8).take(20).collect(),
|
||||||
b"Test With Truncation".to_vec(),
|
b"Test With Truncation".to_vec(),
|
||||||
"4c1a03424b55e07fe7f27be1d58bb9324a9a5a04".from_hex().unwrap()),
|
"4c1a03424b55e07fe7f27be1d58bb9324a9a5a04".from_hex().unwrap()),
|
||||||
(Vec::from_elem(80, 0xaa_u8),
|
(repeat(0xaa_u8).take(80).collect(),
|
||||||
b"Test Using Larger Than Block-Size Key - Hash Key First".to_vec(),
|
b"Test Using Larger Than Block-Size Key - Hash Key First".to_vec(),
|
||||||
"aa4ae5e15272d00e95705637ce8a3b55ed402112".from_hex().unwrap()),
|
"aa4ae5e15272d00e95705637ce8a3b55ed402112".from_hex().unwrap()),
|
||||||
(Vec::from_elem(80, 0xaa_u8),
|
(repeat(0xaa_u8).take(80).collect(),
|
||||||
b"Test Using Larger Than Block-Size Key \
|
b"Test Using Larger Than Block-Size Key \
|
||||||
and Larger Than One Block-Size Data".to_vec(),
|
and Larger Than One Block-Size Data".to_vec(),
|
||||||
"e8e99d0f45237d786d6bbaa7965c7808bbff1a91".from_hex().unwrap())
|
"e8e99d0f45237d786d6bbaa7965c7808bbff1a91".from_hex().unwrap())
|
||||||
|
|
@ -144,15 +146,15 @@ mod tests {
|
||||||
fn test_sha2(ty: HashType, results: &[Vec<u8>]) {
|
fn test_sha2(ty: HashType, results: &[Vec<u8>]) {
|
||||||
// test vectors from RFC 4231
|
// test vectors from RFC 4231
|
||||||
let tests: [(Vec<u8>, Vec<u8>); 6] = [
|
let tests: [(Vec<u8>, Vec<u8>); 6] = [
|
||||||
(Vec::from_elem(20, 0x0b_u8), b"Hi There".to_vec()),
|
(repeat(0xb_u8).take(20).collect(), b"Hi There".to_vec()),
|
||||||
(b"Jefe".to_vec(),
|
(b"Jefe".to_vec(),
|
||||||
b"what do ya want for nothing?".to_vec()),
|
b"what do ya want for nothing?".to_vec()),
|
||||||
(Vec::from_elem(20, 0xaa_u8), Vec::from_elem(50, 0xdd_u8)),
|
(repeat(0xaa_u8).take(20).collect(), repeat(0xdd_u8).take(50).collect()),
|
||||||
("0102030405060708090a0b0c0d0e0f10111213141516171819".from_hex().unwrap(),
|
("0102030405060708090a0b0c0d0e0f10111213141516171819".from_hex().unwrap(),
|
||||||
Vec::from_elem(50, 0xcd_u8)),
|
repeat(0xcd_u8).take(50).collect()),
|
||||||
(Vec::from_elem(131, 0xaa_u8),
|
(repeat(0xaa_u8).take(131).collect(),
|
||||||
b"Test Using Larger Than Block-Size Key - Hash Key First".to_vec()),
|
b"Test Using Larger Than Block-Size Key - Hash Key First".to_vec()),
|
||||||
(Vec::from_elem(131, 0xaa_u8),
|
(repeat(0xaa_u8).take(131).collect(),
|
||||||
b"This is a test using a larger than block-size key and a \
|
b"This is a test using a larger than block-size key and a \
|
||||||
larger than block-size data. The key needs to be hashed \
|
larger than block-size data. The key needs to be hashed \
|
||||||
before being used by the HMAC algorithm.".to_vec())
|
before being used by the HMAC algorithm.".to_vec())
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
use libc::{c_int, c_uint};
|
use libc::{c_int, c_uint};
|
||||||
|
use std::iter::repeat;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use bio::{MemBio};
|
use bio::{MemBio};
|
||||||
|
|
@ -6,7 +7,7 @@ use crypto::hash::HashType;
|
||||||
use ffi;
|
use ffi;
|
||||||
use ssl::error::{SslError, StreamError};
|
use ssl::error::{SslError, StreamError};
|
||||||
|
|
||||||
#[deriving(Copy)]
|
#[derive(Copy)]
|
||||||
enum Parts {
|
enum Parts {
|
||||||
Neither,
|
Neither,
|
||||||
Public,
|
Public,
|
||||||
|
|
@ -14,7 +15,7 @@ enum Parts {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents a role an asymmetric key might be appropriate for.
|
/// Represents a role an asymmetric key might be appropriate for.
|
||||||
#[deriving(Copy)]
|
#[derive(Copy)]
|
||||||
pub enum Role {
|
pub enum Role {
|
||||||
Encrypt,
|
Encrypt,
|
||||||
Decrypt,
|
Decrypt,
|
||||||
|
|
@ -23,7 +24,7 @@ pub enum Role {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Type of encryption padding to use.
|
/// Type of encryption padding to use.
|
||||||
#[deriving(Copy)]
|
#[derive(Copy)]
|
||||||
pub enum EncryptionPadding {
|
pub enum EncryptionPadding {
|
||||||
OAEP,
|
OAEP,
|
||||||
PKCS1v15
|
PKCS1v15
|
||||||
|
|
@ -71,7 +72,7 @@ impl PKey {
|
||||||
let rsa = ffi::EVP_PKEY_get1_RSA(self.evp);
|
let rsa = ffi::EVP_PKEY_get1_RSA(self.evp);
|
||||||
let len = f(rsa, ptr::null());
|
let len = f(rsa, ptr::null());
|
||||||
if len < 0 as c_int { return vec!(); }
|
if len < 0 as c_int { return vec!(); }
|
||||||
let mut s = Vec::from_elem(len as uint, 0u8);
|
let mut s = repeat(0u8).take(len as uint).collect::<Vec<_>>();
|
||||||
|
|
||||||
let r = f(rsa, &s.as_mut_ptr());
|
let r = f(rsa, &s.as_mut_ptr());
|
||||||
|
|
||||||
|
|
@ -209,7 +210,7 @@ impl PKey {
|
||||||
|
|
||||||
assert!(s.len() < self.max_data());
|
assert!(s.len() < self.max_data());
|
||||||
|
|
||||||
let mut r = Vec::from_elem(len as uint + 1u, 0u8);
|
let mut r = repeat(0u8).take(len as uint + 1).collect::<Vec<_>>();
|
||||||
|
|
||||||
let rv = ffi::RSA_public_encrypt(
|
let rv = ffi::RSA_public_encrypt(
|
||||||
s.len() as c_uint,
|
s.len() as c_uint,
|
||||||
|
|
@ -234,7 +235,7 @@ impl PKey {
|
||||||
|
|
||||||
assert_eq!(s.len() as c_uint, ffi::RSA_size(rsa));
|
assert_eq!(s.len() as c_uint, ffi::RSA_size(rsa));
|
||||||
|
|
||||||
let mut r = Vec::from_elem(len as uint + 1u, 0u8);
|
let mut r = repeat(0u8).take(len as uint + 1).collect::<Vec<_>>();
|
||||||
|
|
||||||
let rv = ffi::RSA_private_decrypt(
|
let rv = ffi::RSA_private_decrypt(
|
||||||
s.len() as c_uint,
|
s.len() as c_uint,
|
||||||
|
|
@ -279,7 +280,7 @@ impl PKey {
|
||||||
unsafe {
|
unsafe {
|
||||||
let rsa = ffi::EVP_PKEY_get1_RSA(self.evp);
|
let rsa = ffi::EVP_PKEY_get1_RSA(self.evp);
|
||||||
let mut len = ffi::RSA_size(rsa);
|
let mut len = ffi::RSA_size(rsa);
|
||||||
let mut r = Vec::from_elem(len as uint + 1u, 0u8);
|
let mut r = repeat(0u8).take(len as uint + 1).collect::<Vec<_>>();
|
||||||
|
|
||||||
let rv = ffi::RSA_sign(
|
let rv = ffi::RSA_sign(
|
||||||
openssl_hash_nid(hash),
|
openssl_hash_nid(hash),
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,16 @@
|
||||||
|
use std::iter::repeat;
|
||||||
use libc::{c_int};
|
use libc::{c_int};
|
||||||
|
|
||||||
use ffi;
|
use ffi;
|
||||||
|
|
||||||
#[deriving(Copy)]
|
#[derive(Copy)]
|
||||||
pub enum Mode {
|
pub enum Mode {
|
||||||
Encrypt,
|
Encrypt,
|
||||||
Decrypt,
|
Decrypt,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
#[deriving(Copy)]
|
#[derive(Copy)]
|
||||||
pub enum Type {
|
pub enum Type {
|
||||||
AES_128_ECB,
|
AES_128_ECB,
|
||||||
AES_128_CBC,
|
AES_128_CBC,
|
||||||
|
|
@ -109,7 +110,7 @@ impl Crypter {
|
||||||
*/
|
*/
|
||||||
pub fn update(&self, data: &[u8]) -> Vec<u8> {
|
pub fn update(&self, data: &[u8]) -> Vec<u8> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut res = Vec::from_elem(data.len() + self.blocksize, 0u8);
|
let mut res = repeat(0u8).take(data.len() + self.blocksize).collect::<Vec<_>>();
|
||||||
let mut reslen = (data.len() + self.blocksize) as u32;
|
let mut reslen = (data.len() + self.blocksize) as u32;
|
||||||
|
|
||||||
ffi::EVP_CipherUpdate(
|
ffi::EVP_CipherUpdate(
|
||||||
|
|
@ -130,7 +131,7 @@ impl Crypter {
|
||||||
*/
|
*/
|
||||||
pub fn finalize(&self) -> Vec<u8> {
|
pub fn finalize(&self) -> Vec<u8> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut res = Vec::from_elem(self.blocksize, 0u8);
|
let mut res = repeat(0u8).take(self.blocksize).collect::<Vec<_>>();
|
||||||
let mut reslen = self.blocksize as c_int;
|
let mut reslen = self.blocksize as c_int;
|
||||||
|
|
||||||
ffi::EVP_CipherFinal(self.ctx,
|
ffi::EVP_CipherFinal(self.ctx,
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ use std::c_str::CString;
|
||||||
use ffi;
|
use ffi;
|
||||||
|
|
||||||
/// An SSL error
|
/// An SSL error
|
||||||
#[deriving(Show, Clone, PartialEq, Eq)]
|
#[derive(Show, Clone, PartialEq, Eq)]
|
||||||
pub enum SslError {
|
pub enum SslError {
|
||||||
/// The underlying stream reported an error
|
/// The underlying stream reported an error
|
||||||
StreamError(IoError),
|
StreamError(IoError),
|
||||||
|
|
@ -37,7 +37,7 @@ impl error::Error for SslError {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An error from the OpenSSL library
|
/// An error from the OpenSSL library
|
||||||
#[deriving(Show, Clone, PartialEq, Eq)]
|
#[derive(Show, Clone, PartialEq, Eq)]
|
||||||
pub enum OpensslError {
|
pub enum OpensslError {
|
||||||
/// An unknown error
|
/// An unknown error
|
||||||
UnknownError {
|
UnknownError {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
use libc::{c_int, c_void, c_long};
|
use libc::{c_int, c_void, c_long};
|
||||||
|
use std::c_str::ToCStr;
|
||||||
use std::io::{IoResult, IoError, EndOfFile, Stream, Reader, Writer};
|
use std::io::{IoResult, IoError, EndOfFile, Stream, Reader, Writer};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
use std::num::FromPrimitive;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::sync::{Once, ONCE_INIT, Arc};
|
use std::sync::{Once, ONCE_INIT, Arc};
|
||||||
|
|
||||||
|
|
@ -19,7 +21,7 @@ fn init() {
|
||||||
static mut INIT: Once = ONCE_INIT;
|
static mut INIT: Once = ONCE_INIT;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
INIT.doit(|| {
|
INIT.call_once(|| {
|
||||||
ffi::init();
|
ffi::init();
|
||||||
|
|
||||||
let verify_idx = ffi::SSL_CTX_get_ex_new_index(0, ptr::null(), None,
|
let verify_idx = ffi::SSL_CTX_get_ex_new_index(0, ptr::null(), None,
|
||||||
|
|
@ -31,9 +33,9 @@ fn init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determines the SSL method supported
|
/// Determines the SSL method supported
|
||||||
#[deriving(Show, Hash, PartialEq, Eq)]
|
#[derive(Show, Hash, PartialEq, Eq)]
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
#[deriving(Copy)]
|
#[derive(Copy)]
|
||||||
pub enum SslMethod {
|
pub enum SslMethod {
|
||||||
#[cfg(feature = "sslv2")]
|
#[cfg(feature = "sslv2")]
|
||||||
/// Only support the SSLv2 protocol, requires `feature="sslv2"`
|
/// Only support the SSLv2 protocol, requires `feature="sslv2"`
|
||||||
|
|
@ -69,7 +71,7 @@ impl SslMethod {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determines the type of certificate verification used
|
/// Determines the type of certificate verification used
|
||||||
#[deriving(Copy)]
|
#[derive(Copy)]
|
||||||
#[repr(i32)]
|
#[repr(i32)]
|
||||||
pub enum SslVerifyMode {
|
pub enum SslVerifyMode {
|
||||||
/// Verify that the server's certificate is trusted
|
/// Verify that the server's certificate is trusted
|
||||||
|
|
@ -92,7 +94,7 @@ fn get_verify_data_idx<T>() -> c_int {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
INIT.doit(|| {
|
INIT.call_once(|| {
|
||||||
let f: ffi::CRYPTO_EX_free = free_data_box::<T>;
|
let f: ffi::CRYPTO_EX_free = free_data_box::<T>;
|
||||||
let idx = ffi::SSL_CTX_get_ex_new_index(0, ptr::null(), None,
|
let idx = ffi::SSL_CTX_get_ex_new_index(0, ptr::null(), None,
|
||||||
None, Some(f));
|
None, Some(f));
|
||||||
|
|
@ -389,7 +391,7 @@ impl Ssl {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(FromPrimitive, Show)]
|
#[derive(FromPrimitive, Show)]
|
||||||
#[repr(i32)]
|
#[repr(i32)]
|
||||||
enum LibSslError {
|
enum LibSslError {
|
||||||
ErrorNone = ffi::SSL_ERROR_NONE,
|
ErrorNone = ffi::SSL_ERROR_NONE,
|
||||||
|
|
@ -404,7 +406,7 @@ enum LibSslError {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A stream wrapper which handles SSL encryption for an underlying stream.
|
/// A stream wrapper which handles SSL encryption for an underlying stream.
|
||||||
#[deriving(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct SslStream<S> {
|
pub struct SslStream<S> {
|
||||||
stream: S,
|
stream: S,
|
||||||
ssl: Arc<Ssl>,
|
ssl: Arc<Ssl>,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
use libc::{c_int, c_long, c_uint};
|
use libc::{c_int, c_long, c_uint};
|
||||||
|
use std::c_str::ToCStr;
|
||||||
|
use std::cmp::Ordering;
|
||||||
|
use std::iter::repeat;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::num::SignedInt;
|
use std::num::SignedInt;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
@ -15,7 +18,7 @@ use ssl::error::{SslError, StreamError};
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
#[deriving(Copy)]
|
#[derive(Copy)]
|
||||||
#[repr(i32)]
|
#[repr(i32)]
|
||||||
pub enum X509FileType {
|
pub enum X509FileType {
|
||||||
PEM = ffi::X509_FILETYPE_PEM,
|
PEM = ffi::X509_FILETYPE_PEM,
|
||||||
|
|
@ -56,7 +59,7 @@ trait AsStr<'a> {
|
||||||
fn as_str(&self) -> &'a str;
|
fn as_str(&self) -> &'a str;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub enum KeyUsage {
|
pub enum KeyUsage {
|
||||||
DigitalSignature,
|
DigitalSignature,
|
||||||
NonRepudiation,
|
NonRepudiation,
|
||||||
|
|
@ -86,7 +89,7 @@ impl AsStr<'static> for KeyUsage {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[deriving(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub enum ExtKeyUsage {
|
pub enum ExtKeyUsage {
|
||||||
ServerAuth,
|
ServerAuth,
|
||||||
ClientAuth,
|
ClientAuth,
|
||||||
|
|
@ -383,7 +386,7 @@ impl<'ctx> X509<'ctx> {
|
||||||
/// Returns certificate fingerprint calculated using provided hash
|
/// Returns certificate fingerprint calculated using provided hash
|
||||||
pub fn fingerprint(&self, hash_type: HashType) -> Option<Vec<u8>> {
|
pub fn fingerprint(&self, hash_type: HashType) -> Option<Vec<u8>> {
|
||||||
let (evp, len) = evpmd(hash_type);
|
let (evp, len) = evpmd(hash_type);
|
||||||
let v: Vec<u8> = Vec::from_elem(len, 0);
|
let v: Vec<u8> = repeat(0).take(len).collect();
|
||||||
let act_len: c_uint = 0;
|
let act_len: c_uint = 0;
|
||||||
let res = unsafe {
|
let res = unsafe {
|
||||||
ffi::X509_digest(self.handle, evp, mem::transmute(v.as_ptr()),
|
ffi::X509_digest(self.handle, evp, mem::transmute(v.as_ptr()),
|
||||||
|
|
@ -395,9 +398,9 @@ impl<'ctx> X509<'ctx> {
|
||||||
_ => {
|
_ => {
|
||||||
let act_len = act_len as uint;
|
let act_len = act_len as uint;
|
||||||
match len.cmp(&act_len) {
|
match len.cmp(&act_len) {
|
||||||
Greater => None,
|
Ordering::Greater => None,
|
||||||
Equal => Some(v),
|
Ordering::Equal => Some(v),
|
||||||
Less => panic!("Fingerprint buffer was corrupted!")
|
Ordering::Less => panic!("Fingerprint buffer was corrupted!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -432,7 +435,7 @@ pub struct X509Name<'x> {
|
||||||
|
|
||||||
macro_rules! make_validation_error(
|
macro_rules! make_validation_error(
|
||||||
($ok_val:ident, $($name:ident = $val:ident,)+) => (
|
($ok_val:ident, $($name:ident = $val:ident,)+) => (
|
||||||
#[deriving(Copy)]
|
#[derive(Copy)]
|
||||||
pub enum X509ValidationError {
|
pub enum X509ValidationError {
|
||||||
$($name,)+
|
$($name,)+
|
||||||
X509UnknownError(c_int)
|
X509UnknownError(c_int)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue