commit
9042a4db2f
|
|
@ -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,
|
||||||
|
|
@ -303,11 +304,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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -382,11 +383,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)
|
||||||
}
|
}
|
||||||
|
|
@ -404,6 +405,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};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use std::io;
|
||||||
|
|
||||||
use ffi;
|
use ffi;
|
||||||
|
|
||||||
#[deriving(Copy)]
|
#[derive(Copy)]
|
||||||
pub enum HashType {
|
pub enum HashType {
|
||||||
MD5,
|
MD5,
|
||||||
SHA1,
|
SHA1,
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ impl Drop for HMAC {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
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]
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,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 +14,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 +23,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
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,14 @@ 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,
|
||||||
|
|
|
||||||
|
|
@ -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};
|
||||||
|
|
||||||
|
|
@ -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
|
||||||
|
|
@ -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,6 @@
|
||||||
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::mem;
|
use std::mem;
|
||||||
use std::num::SignedInt;
|
use std::num::SignedInt;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
@ -15,7 +17,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 +58,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 +88,7 @@ impl AsStr<'static> for KeyUsage {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[deriving(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub enum ExtKeyUsage {
|
pub enum ExtKeyUsage {
|
||||||
ServerAuth,
|
ServerAuth,
|
||||||
ClientAuth,
|
ClientAuth,
|
||||||
|
|
@ -395,9 +397,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 +434,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