This commit is contained in:
Steven Fackler 2016-10-30 16:37:45 -07:00
parent 7869651407
commit f75f82e466
23 changed files with 459 additions and 620 deletions

View File

@ -64,9 +64,7 @@ impl Deref for Asn1Time {
type Target = Asn1TimeRef;
fn deref(&self) -> &Asn1TimeRef {
unsafe {
Asn1TimeRef::from_ptr(self.0)
}
unsafe { Asn1TimeRef::from_ptr(self.0) }
}
}

View File

@ -22,9 +22,8 @@ impl<'a> MemBioSlice<'a> {
ffi::init();
assert!(buf.len() <= c_int::max_value() as usize);
let bio = unsafe {
try!(cvt_p(BIO_new_mem_buf(buf.as_ptr() as *const _, buf.len() as c_int)))
};
let bio =
unsafe { try!(cvt_p(BIO_new_mem_buf(buf.as_ptr() as *const _, buf.len() as c_int))) };
Ok(MemBioSlice(bio, PhantomData))
}
@ -48,9 +47,7 @@ impl MemBio {
pub fn new() -> Result<MemBio, ErrorStack> {
ffi::init();
let bio = unsafe {
try!(cvt_p(ffi::BIO_new(ffi::BIO_s_mem())))
};
let bio = unsafe { try!(cvt_p(ffi::BIO_new(ffi::BIO_s_mem()))) };
Ok(MemBio(bio))
}

View File

@ -37,9 +37,7 @@ impl Drop for BnCtx {
impl BnCtx {
/// Returns a new `BnCtx`.
pub fn new() -> Result<BnCtx, ErrorStack> {
unsafe {
cvt_p(ffi::BN_CTX_new()).map(BnCtx)
}
unsafe { cvt_p(ffi::BN_CTX_new()).map(BnCtx) }
}
pub fn as_ptr(&self) -> *mut ffi::BN_CTX {
@ -52,9 +50,7 @@ impl BnCtx {
a: &BigNumRef,
b: &BigNumRef)
-> Result<(), ErrorStack> {
unsafe {
cvt(ffi::BN_mul(r.as_ptr(), a.as_ptr(), b.as_ptr(), self.as_ptr())).map(|_| ())
}
unsafe { cvt(ffi::BN_mul(r.as_ptr(), a.as_ptr(), b.as_ptr(), self.as_ptr())).map(|_| ()) }
}
/// Places the result of `a / b` in `dv` and `a mod b` in `rem`.
@ -76,19 +72,16 @@ impl BnCtx {
/// Places the result of `a²` in `r`.
pub fn sqr(&mut self, r: &mut BigNumRef, a: &BigNumRef) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::BN_sqr(r.as_ptr(), a.as_ptr(), self.as_ptr())).map(|_| ())
}
unsafe { cvt(ffi::BN_sqr(r.as_ptr(), a.as_ptr(), self.as_ptr())).map(|_| ()) }
}
/// Places the result of `a mod m` in `r`.
pub fn nnmod(&mut self,
r: &mut BigNumRef,
a: &BigNumRef,
m: &BigNumRef) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::BN_nnmod(r.as_ptr(), a.as_ptr(), m.as_ptr(), self.0)).map(|_| ())
}
m: &BigNumRef)
-> Result<(), ErrorStack> {
unsafe { cvt(ffi::BN_nnmod(r.as_ptr(), a.as_ptr(), m.as_ptr(), self.0)).map(|_| ()) }
}
/// Places the result of `(a + b) mod m` in `r`.
@ -131,20 +124,18 @@ impl BnCtx {
pub fn mod_sqr(&mut self,
r: &mut BigNumRef,
a: &BigNumRef,
m: &BigNumRef) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::BN_mod_sqr(r.as_ptr(), a.as_ptr(), m.as_ptr(), self.0)).map(|_| ())
}
m: &BigNumRef)
-> Result<(), ErrorStack> {
unsafe { cvt(ffi::BN_mod_sqr(r.as_ptr(), a.as_ptr(), m.as_ptr(), self.0)).map(|_| ()) }
}
/// Places the result of `a^p` in `r`.
pub fn exp(&mut self,
r: &mut BigNumRef,
a: &BigNumRef,
p: &BigNumRef) -> Result<(), ErrorStack> {
unsafe{
cvt(ffi::BN_exp(r.as_ptr(), a.as_ptr(), p.as_ptr(), self.0)).map(|_| ())
}
p: &BigNumRef)
-> Result<(), ErrorStack> {
unsafe { cvt(ffi::BN_exp(r.as_ptr(), a.as_ptr(), p.as_ptr(), self.0)).map(|_| ()) }
}
/// Places the result of `a^p mod m` in `r`.
@ -152,7 +143,8 @@ impl BnCtx {
r: &mut BigNumRef,
a: &BigNumRef,
p: &BigNumRef,
m: &BigNumRef) -> Result<(), ErrorStack> {
m: &BigNumRef)
-> Result<(), ErrorStack> {
unsafe {
cvt(ffi::BN_mod_exp(r.as_ptr(), a.as_ptr(), p.as_ptr(), m.as_ptr(), self.0)).map(|_| ())
}
@ -162,9 +154,11 @@ impl BnCtx {
pub fn mod_inverse(&mut self,
r: &mut BigNumRef,
a: &BigNumRef,
n: &BigNumRef) -> Result<(), ErrorStack> {
n: &BigNumRef)
-> Result<(), ErrorStack> {
unsafe {
cvt_p(ffi::BN_mod_inverse(r.as_ptr(), a.as_ptr(), n.as_ptr(), self.as_ptr())).map(|_| ())
cvt_p(ffi::BN_mod_inverse(r.as_ptr(), a.as_ptr(), n.as_ptr(), self.as_ptr()))
.map(|_| ())
}
}
@ -172,10 +166,9 @@ impl BnCtx {
pub fn gcd(&mut self,
r: &mut BigNumRef,
a: &BigNumRef,
b: &BigNumRef) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::BN_gcd(r.as_ptr(), a.as_ptr(), b.as_ptr(), self.as_ptr())).map(|_| ())
}
b: &BigNumRef)
-> Result<(), ErrorStack> {
unsafe { cvt(ffi::BN_gcd(r.as_ptr(), a.as_ptr(), b.as_ptr(), self.as_ptr())).map(|_| ()) }
}
/// Checks whether `p` is prime.
@ -185,7 +178,8 @@ impl BnCtx {
/// Returns `true` if `p` is prime with an error probability of less than `0.25 ^ checks`.
pub fn is_prime(&mut self, p: &BigNumRef, checks: i32) -> Result<bool, ErrorStack> {
unsafe {
cvt_n(ffi::BN_is_prime_ex(p.as_ptr(), checks.into(), self.as_ptr(), ptr::null_mut())).map(|r| r != 0)
cvt_n(ffi::BN_is_prime_ex(p.as_ptr(), checks.into(), self.as_ptr(), ptr::null_mut()))
.map(|r| r != 0)
}
}
@ -201,7 +195,8 @@ impl BnCtx {
pub fn is_prime_fasttest(&mut self,
p: &BigNumRef,
checks: i32,
do_trial_division: bool) -> Result<bool, ErrorStack> {
do_trial_division: bool)
-> Result<bool, ErrorStack> {
unsafe {
cvt_n(ffi::BN_is_prime_fasttest_ex(p.as_ptr(),
checks.into(),
@ -236,7 +231,8 @@ impl BnCtx {
odd: bool)
-> Result<(), ErrorStack> {
unsafe {
cvt(ffi::BN_pseudo_rand(r.as_ptr(), bits.into(), prop as c_int, odd as c_int)).map(|_| ())
cvt(ffi::BN_pseudo_rand(r.as_ptr(), bits.into(), prop as c_int, odd as c_int))
.map(|_| ())
}
}
}
@ -259,23 +255,17 @@ impl BigNumRef {
/// Adds a `u32` to `self`.
pub fn add_word(&mut self, w: u32) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::BN_add_word(self.as_ptr(), w as ffi::BN_ULONG)).map(|_| ())
}
unsafe { cvt(ffi::BN_add_word(self.as_ptr(), w as ffi::BN_ULONG)).map(|_| ()) }
}
/// Subtracts a `u32` from `self`.
pub fn sub_word(&mut self, w: u32) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::BN_sub_word(self.as_ptr(), w as ffi::BN_ULONG)).map(|_| ())
}
unsafe { cvt(ffi::BN_sub_word(self.as_ptr(), w as ffi::BN_ULONG)).map(|_| ()) }
}
/// Multiplies a `u32` by `self`.
pub fn mul_word(&mut self, w: u32) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::BN_mul_word(self.as_ptr(), w as ffi::BN_ULONG)).map(|_| ())
}
unsafe { cvt(ffi::BN_mul_word(self.as_ptr(), w as ffi::BN_ULONG)).map(|_| ()) }
}
/// Divides `self` by a `u32`, returning the remainder.
@ -305,105 +295,77 @@ impl BigNumRef {
/// Places a cryptographically-secure pseudo-random number nonnegative
/// number less than `self` in `rnd`.
pub fn rand_in_range(&self, rnd: &mut BigNumRef) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::BN_rand_range(self.as_ptr(), rnd.as_ptr())).map(|_| ())
}
unsafe { cvt(ffi::BN_rand_range(self.as_ptr(), rnd.as_ptr())).map(|_| ()) }
}
/// The cryptographically weak counterpart to `rand_in_range`.
pub fn pseudo_rand_in_range(&self, rnd: &mut BigNumRef) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::BN_pseudo_rand_range(self.as_ptr(), rnd.as_ptr())).map(|_| ())
}
unsafe { cvt(ffi::BN_pseudo_rand_range(self.as_ptr(), rnd.as_ptr())).map(|_| ()) }
}
/// Sets bit `n`. Equivalent to `self |= (1 << n)`.
///
/// When setting a bit outside of `self`, it is expanded.
pub fn set_bit(&mut self, n: i32) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::BN_set_bit(self.as_ptr(), n.into())).map(|_| ())
}
unsafe { cvt(ffi::BN_set_bit(self.as_ptr(), n.into())).map(|_| ()) }
}
/// Clears bit `n`, setting it to 0. Equivalent to `self &= ~(1 << n)`.
///
/// When clearing a bit outside of `self`, an error is returned.
pub fn clear_bit(&mut self, n: i32) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::BN_clear_bit(self.as_ptr(), n.into())).map(|_| ())
}
unsafe { cvt(ffi::BN_clear_bit(self.as_ptr(), n.into())).map(|_| ()) }
}
/// Returns `true` if the `n`th bit of `self` is set to 1, `false` otherwise.
pub fn is_bit_set(&self, n: i32) -> bool {
unsafe {
ffi::BN_is_bit_set(self.as_ptr(), n.into()) == 1
}
unsafe { ffi::BN_is_bit_set(self.as_ptr(), n.into()) == 1 }
}
/// Truncates `self` to the lowest `n` bits.
///
/// An error occurs if `self` is already shorter than `n` bits.
pub fn mask_bits(&mut self, n: i32) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::BN_mask_bits(self.as_ptr(), n.into())).map(|_| ())
}
unsafe { cvt(ffi::BN_mask_bits(self.as_ptr(), n.into())).map(|_| ()) }
}
/// Places `self << 1` in `r`.
pub fn lshift1(&self, r: &mut BigNumRef) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::BN_lshift1(r.as_ptr(), self.as_ptr())).map(|_| ())
}
unsafe { cvt(ffi::BN_lshift1(r.as_ptr(), self.as_ptr())).map(|_| ()) }
}
/// Places `self >> 1` in `r`.
pub fn rshift1(&self, r: &mut BigNumRef) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::BN_rshift1(r.as_ptr(), self.as_ptr())).map(|_| ())
}
unsafe { cvt(ffi::BN_rshift1(r.as_ptr(), self.as_ptr())).map(|_| ()) }
}
/// Places `self + b` in `r`.
pub fn add(&self, r: &mut BigNumRef, b: &BigNumRef) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::BN_add(r.as_ptr(), self.as_ptr(), b.as_ptr())).map(|_| ())
}
unsafe { cvt(ffi::BN_add(r.as_ptr(), self.as_ptr(), b.as_ptr())).map(|_| ()) }
}
/// Places `self - b` in `r`.
pub fn sub(&self, r: &mut BigNumRef, b: &BigNumRef) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::BN_sub(r.as_ptr(), self.as_ptr(), b.as_ptr())).map(|_| ())
}
unsafe { cvt(ffi::BN_sub(r.as_ptr(), self.as_ptr(), b.as_ptr())).map(|_| ()) }
}
/// Places `self << n` in `r`.
pub fn lshift(&self, r: &mut BigNumRef, b: i32) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::BN_lshift(r.as_ptr(), self.as_ptr(), b.into())).map(|_| ())
}
unsafe { cvt(ffi::BN_lshift(r.as_ptr(), self.as_ptr(), b.into())).map(|_| ()) }
}
/// Places `self >> n` in `r`.
pub fn rshift(&self, r: &mut BigNumRef, n: i32) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::BN_rshift(r.as_ptr(), self.as_ptr(), n.into())).map(|_| ())
}
unsafe { cvt(ffi::BN_rshift(r.as_ptr(), self.as_ptr(), n.into())).map(|_| ()) }
}
pub fn to_owned(&self) -> Result<BigNum, ErrorStack> {
unsafe {
cvt_p(ffi::BN_dup(self.as_ptr())).map(|b| BigNum::from_ptr(b))
}
unsafe { cvt_p(ffi::BN_dup(self.as_ptr())).map(|b| BigNum::from_ptr(b)) }
}
/// Sets the sign of `self`.
pub fn set_negative(&mut self, negative: bool) {
unsafe {
ffi::BN_set_negative(self.as_ptr(), negative as c_int)
}
unsafe { ffi::BN_set_negative(self.as_ptr(), negative as c_int) }
}
/// Compare the absolute values of `self` and `oth`.
@ -417,9 +379,7 @@ impl BigNumRef {
/// assert_eq!(s.ucmp(&o), Ordering::Equal);
/// ```
pub fn ucmp(&self, oth: &BigNumRef) -> Ordering {
unsafe {
ffi::BN_ucmp(self.as_ptr(), oth.as_ptr()).cmp(&0)
}
unsafe { ffi::BN_ucmp(self.as_ptr(), oth.as_ptr()).cmp(&0) }
}
pub fn is_negative(&self) -> bool {
@ -592,7 +552,9 @@ impl BigNum {
impl Drop for BigNum {
fn drop(&mut self) {
unsafe { ffi::BN_clear_free(self.as_ptr()); }
unsafe {
ffi::BN_clear_free(self.as_ptr());
}
}
}
@ -600,17 +562,13 @@ impl Deref for BigNum {
type Target = BigNumRef;
fn deref(&self) -> &BigNumRef {
unsafe {
BigNumRef::from_ptr(self.0)
}
unsafe { BigNumRef::from_ptr(self.0) }
}
}
impl DerefMut for BigNum {
fn deref_mut(&mut self) -> &mut BigNumRef {
unsafe {
BigNumRef::from_ptr_mut(self.0)
}
unsafe { BigNumRef::from_ptr_mut(self.0) }
}
}

View File

@ -50,33 +50,25 @@ impl Dh {
/// Requires the `v102` or `v110` features and OpenSSL 1.0.2 or OpenSSL 1.1.0.
#[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))]
pub fn get_1024_160() -> Result<Dh, ErrorStack> {
unsafe {
cvt_p(ffi::DH_get_1024_160()).map(Dh)
}
unsafe { cvt_p(ffi::DH_get_1024_160()).map(Dh) }
}
/// Requires the `v102` or `v110` features and OpenSSL 1.0.2 or OpenSSL 1.1.0.
#[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))]
pub fn get_2048_224() -> Result<Dh, ErrorStack> {
unsafe {
cvt_p(ffi::DH_get_2048_224()).map(Dh)
}
unsafe { cvt_p(ffi::DH_get_2048_224()).map(Dh) }
}
/// Requires the `v102` or `v110` features and OpenSSL 1.0.2 or OpenSSL 1.1.0.
#[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))]
pub fn get_2048_256() -> Result<Dh, ErrorStack> {
unsafe {
cvt_p(ffi::DH_get_2048_256()).map(Dh)
}
unsafe { cvt_p(ffi::DH_get_2048_256()).map(Dh) }
}
}
impl Drop for Dh {
fn drop(&mut self) {
unsafe {
ffi::DH_free(self.0)
}
unsafe { ffi::DH_free(self.0) }
}
}
@ -84,9 +76,7 @@ impl Deref for Dh {
type Target = DhRef;
fn deref(&self) -> &DhRef {
unsafe {
DhRef::from_ptr(self.0)
}
unsafe { DhRef::from_ptr(self.0) }
}
}
@ -104,7 +94,8 @@ mod compat {
pub unsafe fn DH_set0_pqg(dh: *mut ffi::DH,
p: *mut ffi::BIGNUM,
q: *mut ffi::BIGNUM,
g: *mut ffi::BIGNUM) -> c_int {
g: *mut ffi::BIGNUM)
-> c_int {
(*dh).p = p;
(*dh).q = q;
(*dh).g = g;

View File

@ -105,8 +105,7 @@ impl Dsa {
}
/// Writes an DSA private key as unencrypted PEM formatted data
pub fn private_key_to_pem(&self) -> Result<Vec<u8>, ErrorStack>
{
pub fn private_key_to_pem(&self) -> Result<Vec<u8>, ErrorStack> {
assert!(self.has_private_key());
let mem_bio = try!(MemBio::new());
@ -120,8 +119,7 @@ impl Dsa {
}
/// Reads an DSA public key from PEM formatted data.
pub fn public_key_from_pem(buf: &[u8]) -> Result<Dsa, ErrorStack>
{
pub fn public_key_from_pem(buf: &[u8]) -> Result<Dsa, ErrorStack> {
ffi::init();
let mem_bio = try!(MemBioSlice::new(buf));
@ -258,7 +256,8 @@ mod test {
password[4] = b's' as c_char;
password[5] = b's' as c_char;
6
}).unwrap();
})
.unwrap();
assert!(password_queried);
}

View File

@ -30,9 +30,7 @@ impl Drop for EcKey {
impl EcKey {
pub fn new_by_curve_name(nid: Nid) -> Result<EcKey, ErrorStack> {
unsafe {
cvt_p(ffi::EC_KEY_new_by_curve_name(nid.as_raw())).map(EcKey)
}
unsafe { cvt_p(ffi::EC_KEY_new_by_curve_name(nid.as_raw())).map(EcKey) }
}
pub unsafe fn from_ptr(ptr: *mut ffi::EC_KEY) -> EcKey {
@ -44,9 +42,7 @@ impl Deref for EcKey {
type Target = EcKeyRef;
fn deref(&self) -> &EcKeyRef {
unsafe {
EcKeyRef::from_ptr(self.0)
}
unsafe { EcKeyRef::from_ptr(self.0) }
}
}

View File

@ -15,45 +15,31 @@ pub struct MessageDigest(*const ffi::EVP_MD);
impl MessageDigest {
pub fn md5() -> MessageDigest {
unsafe {
MessageDigest(ffi::EVP_md5())
}
unsafe { MessageDigest(ffi::EVP_md5()) }
}
pub fn sha1() -> MessageDigest {
unsafe {
MessageDigest(ffi::EVP_sha1())
}
unsafe { MessageDigest(ffi::EVP_sha1()) }
}
pub fn sha224() -> MessageDigest {
unsafe {
MessageDigest(ffi::EVP_sha224())
}
unsafe { MessageDigest(ffi::EVP_sha224()) }
}
pub fn sha256() -> MessageDigest {
unsafe {
MessageDigest(ffi::EVP_sha256())
}
unsafe { MessageDigest(ffi::EVP_sha256()) }
}
pub fn sha384() -> MessageDigest {
unsafe {
MessageDigest(ffi::EVP_sha384())
}
unsafe { MessageDigest(ffi::EVP_sha384()) }
}
pub fn sha512() -> MessageDigest {
unsafe {
MessageDigest(ffi::EVP_sha512())
}
unsafe { MessageDigest(ffi::EVP_sha512()) }
}
pub fn ripemd160() -> MessageDigest {
unsafe {
MessageDigest(ffi::EVP_ripemd160())
}
unsafe { MessageDigest(ffi::EVP_ripemd160()) }
}
pub fn as_ptr(&self) -> *const ffi::EVP_MD {
@ -136,7 +122,9 @@ impl Hasher {
}
Finalized => (),
}
unsafe { try!(cvt(ffi::EVP_DigestInit_ex(self.ctx, self.md, 0 as *mut _))); }
unsafe {
try!(cvt(ffi::EVP_DigestInit_ex(self.ctx, self.md, 0 as *mut _)));
}
self.state = Reset;
Ok(())
}
@ -239,32 +227,20 @@ mod tests {
// Test vectors from http://www.nsrl.nist.gov/testdata/
#[allow(non_upper_case_globals)]
const md5_tests: [(&'static str, &'static str); 13] = [("",
"d41d8cd98f00b204e9800998ecf8427e"),
("7F",
"83acb6e67e50e31db6ed341dd2de1595"),
("EC9C",
"0b07f0d4ca797d8ac58874f887cb0b68"),
("FEE57A",
"e0d583171eb06d56198fc0ef22173907"),
("42F497E0",
"7c430f178aefdf1487fee7144e9641e2"),
("C53B777F1C",
"75ef141d64cb37ec423da2d9d440c925"),
("89D5B576327B",
"ebbaf15eb0ed784c6faa9dc32831bf33"),
("5D4CCE781EB190",
"ce175c4b08172019f05e6b5279889f2c"),
("81901FE94932D7B9",
"cd4d2f62b8cdb3a0cf968a735a239281"),
("C9FFDEE7788EFB4EC9",
"e0841a231ab698db30c6c0f3f246c014"),
("66AC4B7EBA95E53DC10B",
"a3b3cea71910d9af56742aa0bb2fe329"),
("A510CD18F7A56852EB0319",
"577e216843dd11573574d3fb209b97d8"),
("AAED18DBE8938C19ED734A8D",
"6f80fb775f27e0a4ce5c2f42fc72c5f1")];
const md5_tests: [(&'static str, &'static str); 13] =
[("", "d41d8cd98f00b204e9800998ecf8427e"),
("7F", "83acb6e67e50e31db6ed341dd2de1595"),
("EC9C", "0b07f0d4ca797d8ac58874f887cb0b68"),
("FEE57A", "e0d583171eb06d56198fc0ef22173907"),
("42F497E0", "7c430f178aefdf1487fee7144e9641e2"),
("C53B777F1C", "75ef141d64cb37ec423da2d9d440c925"),
("89D5B576327B", "ebbaf15eb0ed784c6faa9dc32831bf33"),
("5D4CCE781EB190", "ce175c4b08172019f05e6b5279889f2c"),
("81901FE94932D7B9", "cd4d2f62b8cdb3a0cf968a735a239281"),
("C9FFDEE7788EFB4EC9", "e0841a231ab698db30c6c0f3f246c014"),
("66AC4B7EBA95E53DC10B", "a3b3cea71910d9af56742aa0bb2fe329"),
("A510CD18F7A56852EB0319", "577e216843dd11573574d3fb209b97d8"),
("AAED18DBE8938C19ED734A8D", "6f80fb775f27e0a4ce5c2f42fc72c5f1")];
#[test]
fn test_md5() {

View File

@ -63,9 +63,5 @@ pub fn cvt(r: c_int) -> Result<c_int, ErrorStack> {
}
pub fn cvt_n(r: c_int) -> Result<c_int, ErrorStack> {
if r < 0 {
Err(ErrorStack::get())
} else {
Ok(r)
}
if r < 0 { Err(ErrorStack::get()) } else { Ok(r) }
}

View File

@ -254,8 +254,10 @@ pub const SDSICERTIFICATE: Nid = Nid(ffi::NID_sdsiCertificate);
pub const X509CRL: Nid = Nid(ffi::NID_x509Crl);
pub const PBE_WITHSHA1AND128BITRC4: Nid = Nid(ffi::NID_pbe_WithSHA1And128BitRC4);
pub const PBE_WITHSHA1AND40BITRC4: Nid = Nid(ffi::NID_pbe_WithSHA1And40BitRC4);
pub const PBE_WITHSHA1AND3_KEY_TRIPLEDES_CBC: Nid = Nid(ffi::NID_pbe_WithSHA1And3_Key_TripleDES_CBC);
pub const PBE_WITHSHA1AND2_KEY_TRIPLEDES_CBC: Nid = Nid(ffi::NID_pbe_WithSHA1And2_Key_TripleDES_CBC);
pub const PBE_WITHSHA1AND3_KEY_TRIPLEDES_CBC: Nid =
Nid(ffi::NID_pbe_WithSHA1And3_Key_TripleDES_CBC);
pub const PBE_WITHSHA1AND2_KEY_TRIPLEDES_CBC: Nid =
Nid(ffi::NID_pbe_WithSHA1And2_Key_TripleDES_CBC);
pub const PBE_WITHSHA1AND128BITRC2_CBC: Nid = Nid(ffi::NID_pbe_WithSHA1And128BitRC2_CBC);
pub const PBE_WITHSHA1AND40BITRC2_CBC: Nid = Nid(ffi::NID_pbe_WithSHA1And40BitRC2_CBC);
pub const KEYBAG: Nid = Nid(ffi::NID_keyBag);
@ -847,7 +849,8 @@ pub const IPSEC4: Nid = Nid(ffi::NID_ipsec4);
pub const WHIRLPOOL: Nid = Nid(ffi::NID_whirlpool);
pub const CRYPTOPRO: Nid = Nid(ffi::NID_cryptopro);
pub const CRYPTOCOM: Nid = Nid(ffi::NID_cryptocom);
pub const ID_GOSTR3411_94_WITH_GOSTR3410_2001: Nid = Nid(ffi::NID_id_GostR3411_94_with_GostR3410_2001);
pub const ID_GOSTR3411_94_WITH_GOSTR3410_2001: Nid =
Nid(ffi::NID_id_GostR3411_94_with_GostR3410_2001);
pub const ID_GOSTR3411_94_WITH_GOSTR3410_94: Nid = Nid(ffi::NID_id_GostR3411_94_with_GostR3410_94);
pub const ID_GOSTR3411_94: Nid = Nid(ffi::NID_id_GostR3411_94);
pub const ID_HMACGOSTR3411_94: Nid = Nid(ffi::NID_id_HMACGostR3411_94);
@ -859,32 +862,52 @@ pub const ID_GOST28147_89_MAC: Nid = Nid(ffi::NID_id_Gost28147_89_MAC);
pub const ID_GOSTR3411_94_PRF: Nid = Nid(ffi::NID_id_GostR3411_94_prf);
pub const ID_GOSTR3410_2001DH: Nid = Nid(ffi::NID_id_GostR3410_2001DH);
pub const ID_GOSTR3410_94DH: Nid = Nid(ffi::NID_id_GostR3410_94DH);
pub const ID_GOST28147_89_CRYPTOPRO_KEYMESHING: Nid = Nid(ffi::NID_id_Gost28147_89_CryptoPro_KeyMeshing);
pub const ID_GOST28147_89_CRYPTOPRO_KEYMESHING: Nid =
Nid(ffi::NID_id_Gost28147_89_CryptoPro_KeyMeshing);
pub const ID_GOST28147_89_NONE_KEYMESHING: Nid = Nid(ffi::NID_id_Gost28147_89_None_KeyMeshing);
pub const ID_GOSTR3411_94_TESTPARAMSET: Nid = Nid(ffi::NID_id_GostR3411_94_TestParamSet);
pub const ID_GOSTR3411_94_CRYPTOPROPARAMSET: Nid = Nid(ffi::NID_id_GostR3411_94_CryptoProParamSet);
pub const ID_GOST28147_89_TESTPARAMSET: Nid = Nid(ffi::NID_id_Gost28147_89_TestParamSet);
pub const ID_GOST28147_89_CRYPTOPRO_A_PARAMSET: Nid = Nid(ffi::NID_id_Gost28147_89_CryptoPro_A_ParamSet);
pub const ID_GOST28147_89_CRYPTOPRO_B_PARAMSET: Nid = Nid(ffi::NID_id_Gost28147_89_CryptoPro_B_ParamSet);
pub const ID_GOST28147_89_CRYPTOPRO_C_PARAMSET: Nid = Nid(ffi::NID_id_Gost28147_89_CryptoPro_C_ParamSet);
pub const ID_GOST28147_89_CRYPTOPRO_D_PARAMSET: Nid = Nid(ffi::NID_id_Gost28147_89_CryptoPro_D_ParamSet);
pub const ID_GOST28147_89_CRYPTOPRO_OSCAR_1_1_PARAMSET: Nid = Nid(ffi::NID_id_Gost28147_89_CryptoPro_Oscar_1_1_ParamSet);
pub const ID_GOST28147_89_CRYPTOPRO_OSCAR_1_0_PARAMSET: Nid = Nid(ffi::NID_id_Gost28147_89_CryptoPro_Oscar_1_0_ParamSet);
pub const ID_GOST28147_89_CRYPTOPRO_RIC_1_PARAMSET: Nid = Nid(ffi::NID_id_Gost28147_89_CryptoPro_RIC_1_ParamSet);
pub const ID_GOST28147_89_CRYPTOPRO_A_PARAMSET: Nid =
Nid(ffi::NID_id_Gost28147_89_CryptoPro_A_ParamSet);
pub const ID_GOST28147_89_CRYPTOPRO_B_PARAMSET: Nid =
Nid(ffi::NID_id_Gost28147_89_CryptoPro_B_ParamSet);
pub const ID_GOST28147_89_CRYPTOPRO_C_PARAMSET: Nid =
Nid(ffi::NID_id_Gost28147_89_CryptoPro_C_ParamSet);
pub const ID_GOST28147_89_CRYPTOPRO_D_PARAMSET: Nid =
Nid(ffi::NID_id_Gost28147_89_CryptoPro_D_ParamSet);
pub const ID_GOST28147_89_CRYPTOPRO_OSCAR_1_1_PARAMSET: Nid =
Nid(ffi::NID_id_Gost28147_89_CryptoPro_Oscar_1_1_ParamSet);
pub const ID_GOST28147_89_CRYPTOPRO_OSCAR_1_0_PARAMSET: Nid =
Nid(ffi::NID_id_Gost28147_89_CryptoPro_Oscar_1_0_ParamSet);
pub const ID_GOST28147_89_CRYPTOPRO_RIC_1_PARAMSET: Nid =
Nid(ffi::NID_id_Gost28147_89_CryptoPro_RIC_1_ParamSet);
pub const ID_GOSTR3410_94_TESTPARAMSET: Nid = Nid(ffi::NID_id_GostR3410_94_TestParamSet);
pub const ID_GOSTR3410_94_CRYPTOPRO_A_PARAMSET: Nid = Nid(ffi::NID_id_GostR3410_94_CryptoPro_A_ParamSet);
pub const ID_GOSTR3410_94_CRYPTOPRO_B_PARAMSET: Nid = Nid(ffi::NID_id_GostR3410_94_CryptoPro_B_ParamSet);
pub const ID_GOSTR3410_94_CRYPTOPRO_C_PARAMSET: Nid = Nid(ffi::NID_id_GostR3410_94_CryptoPro_C_ParamSet);
pub const ID_GOSTR3410_94_CRYPTOPRO_D_PARAMSET: Nid = Nid(ffi::NID_id_GostR3410_94_CryptoPro_D_ParamSet);
pub const ID_GOSTR3410_94_CRYPTOPRO_XCHA_PARAMSET: Nid = Nid(ffi::NID_id_GostR3410_94_CryptoPro_XchA_ParamSet);
pub const ID_GOSTR3410_94_CRYPTOPRO_XCHB_PARAMSET: Nid = Nid(ffi::NID_id_GostR3410_94_CryptoPro_XchB_ParamSet);
pub const ID_GOSTR3410_94_CRYPTOPRO_XCHC_PARAMSET: Nid = Nid(ffi::NID_id_GostR3410_94_CryptoPro_XchC_ParamSet);
pub const ID_GOSTR3410_94_CRYPTOPRO_A_PARAMSET: Nid =
Nid(ffi::NID_id_GostR3410_94_CryptoPro_A_ParamSet);
pub const ID_GOSTR3410_94_CRYPTOPRO_B_PARAMSET: Nid =
Nid(ffi::NID_id_GostR3410_94_CryptoPro_B_ParamSet);
pub const ID_GOSTR3410_94_CRYPTOPRO_C_PARAMSET: Nid =
Nid(ffi::NID_id_GostR3410_94_CryptoPro_C_ParamSet);
pub const ID_GOSTR3410_94_CRYPTOPRO_D_PARAMSET: Nid =
Nid(ffi::NID_id_GostR3410_94_CryptoPro_D_ParamSet);
pub const ID_GOSTR3410_94_CRYPTOPRO_XCHA_PARAMSET: Nid =
Nid(ffi::NID_id_GostR3410_94_CryptoPro_XchA_ParamSet);
pub const ID_GOSTR3410_94_CRYPTOPRO_XCHB_PARAMSET: Nid =
Nid(ffi::NID_id_GostR3410_94_CryptoPro_XchB_ParamSet);
pub const ID_GOSTR3410_94_CRYPTOPRO_XCHC_PARAMSET: Nid =
Nid(ffi::NID_id_GostR3410_94_CryptoPro_XchC_ParamSet);
pub const ID_GOSTR3410_2001_TESTPARAMSET: Nid = Nid(ffi::NID_id_GostR3410_2001_TestParamSet);
pub const ID_GOSTR3410_2001_CRYPTOPRO_A_PARAMSET: Nid = Nid(ffi::NID_id_GostR3410_2001_CryptoPro_A_ParamSet);
pub const ID_GOSTR3410_2001_CRYPTOPRO_B_PARAMSET: Nid = Nid(ffi::NID_id_GostR3410_2001_CryptoPro_B_ParamSet);
pub const ID_GOSTR3410_2001_CRYPTOPRO_C_PARAMSET: Nid = Nid(ffi::NID_id_GostR3410_2001_CryptoPro_C_ParamSet);
pub const ID_GOSTR3410_2001_CRYPTOPRO_XCHA_PARAMSET: Nid = Nid(ffi::NID_id_GostR3410_2001_CryptoPro_XchA_ParamSet);
pub const ID_GOSTR3410_2001_CRYPTOPRO_XCHB_PARAMSET: Nid = Nid(ffi::NID_id_GostR3410_2001_CryptoPro_XchB_ParamSet);
pub const ID_GOSTR3410_2001_CRYPTOPRO_A_PARAMSET: Nid =
Nid(ffi::NID_id_GostR3410_2001_CryptoPro_A_ParamSet);
pub const ID_GOSTR3410_2001_CRYPTOPRO_B_PARAMSET: Nid =
Nid(ffi::NID_id_GostR3410_2001_CryptoPro_B_ParamSet);
pub const ID_GOSTR3410_2001_CRYPTOPRO_C_PARAMSET: Nid =
Nid(ffi::NID_id_GostR3410_2001_CryptoPro_C_ParamSet);
pub const ID_GOSTR3410_2001_CRYPTOPRO_XCHA_PARAMSET: Nid =
Nid(ffi::NID_id_GostR3410_2001_CryptoPro_XchA_ParamSet);
pub const ID_GOSTR3410_2001_CRYPTOPRO_XCHB_PARAMSET: Nid =
Nid(ffi::NID_id_GostR3410_2001_CryptoPro_XchB_ParamSet);
pub const ID_GOSTR3410_94_A: Nid = Nid(ffi::NID_id_GostR3410_94_a);
pub const ID_GOSTR3410_94_ABIS: Nid = Nid(ffi::NID_id_GostR3410_94_aBis);
pub const ID_GOSTR3410_94_B: Nid = Nid(ffi::NID_id_GostR3410_94_b);
@ -892,8 +915,10 @@ pub const ID_GOSTR3410_94_BBIS: Nid = Nid(ffi::NID_id_GostR3410_94_bBis);
pub const ID_GOST28147_89_CC: Nid = Nid(ffi::NID_id_Gost28147_89_cc);
pub const ID_GOSTR3410_94_CC: Nid = Nid(ffi::NID_id_GostR3410_94_cc);
pub const ID_GOSTR3410_2001_CC: Nid = Nid(ffi::NID_id_GostR3410_2001_cc);
pub const ID_GOSTR3411_94_WITH_GOSTR3410_94_CC: Nid = Nid(ffi::NID_id_GostR3411_94_with_GostR3410_94_cc);
pub const ID_GOSTR3411_94_WITH_GOSTR3410_2001_CC: Nid = Nid(ffi::NID_id_GostR3411_94_with_GostR3410_2001_cc);
pub const ID_GOSTR3411_94_WITH_GOSTR3410_94_CC: Nid =
Nid(ffi::NID_id_GostR3411_94_with_GostR3410_94_cc);
pub const ID_GOSTR3411_94_WITH_GOSTR3410_2001_CC: Nid =
Nid(ffi::NID_id_GostR3411_94_with_GostR3410_2001_cc);
pub const ID_GOSTR3410_2001_PARAMSET_CC: Nid = Nid(ffi::NID_id_GostR3410_2001_ParamSet_cc);
pub const CAMELLIA_128_CBC: Nid = Nid(ffi::NID_camellia_128_cbc);
pub const CAMELLIA_192_CBC: Nid = Nid(ffi::NID_camellia_192_cbc);
@ -927,4 +952,3 @@ pub const RC4_HMAC_MD5: Nid = Nid(ffi::NID_rc4_hmac_md5);
pub const AES_128_CBC_HMAC_SHA1: Nid = Nid(ffi::NID_aes_128_cbc_hmac_sha1);
pub const AES_192_CBC_HMAC_SHA1: Nid = Nid(ffi::NID_aes_192_cbc_hmac_sha1);
pub const AES_256_CBC_HMAC_SHA1: Nid = Nid(ffi::NID_aes_256_cbc_hmac_sha1);

View File

@ -16,7 +16,9 @@ pub struct Pkcs12(*mut ffi::PKCS12);
impl Drop for Pkcs12 {
fn drop(&mut self) {
unsafe { ffi::PKCS12_free(self.0); }
unsafe {
ffi::PKCS12_free(self.0);
}
}
}
@ -88,8 +90,7 @@ mod compat {
(*stack).num
}
pub unsafe fn OPENSSL_sk_value(stack: *const ffi::_STACK, idx: c_int)
-> *mut c_void {
pub unsafe fn OPENSSL_sk_value(stack: *const ffi::_STACK, idx: c_int) -> *mut c_void {
*(*stack).data.offset(idx as isize) as *mut c_void
}
}

View File

@ -112,7 +112,12 @@ mod tests {
&[0x55_u8, 0xac_u8, 0x04_u8, 0x6e_u8, 0x56_u8, 0xe3_u8, 0x08_u8, 0x9f_u8,
0xec_u8, 0x16_u8, 0x91_u8, 0xc2_u8, 0x25_u8, 0x44_u8, 0xb6_u8, 0x05_u8][..]);
super::pbkdf2_hmac(b"Password", b"NaCl", 80000, MessageDigest::sha256(), &mut buf).unwrap();
super::pbkdf2_hmac(b"Password",
b"NaCl",
80000,
MessageDigest::sha256(),
&mut buf)
.unwrap();
assert_eq!(buf,
&[0x4d_u8, 0xdc_u8, 0xd8_u8, 0xf6_u8, 0x0b_u8, 0x98_u8, 0xbe_u8, 0x21_u8,
0x83_u8, 0x0c_u8, 0xee_u8, 0x5e_u8, 0xf2_u8, 0x27_u8, 0x01_u8, 0xf9_u8][..]);
@ -135,7 +140,12 @@ mod tests {
0x60_u8, 0x60_u8, 0xa0_u8, 0x9f_u8, 0x76_u8, 0x41_u8, 0x5e_u8, 0x9f_u8,
0x71_u8, 0xea_u8, 0x47_u8, 0xf9_u8, 0xe9_u8, 0x06_u8, 0x43_u8, 0x06_u8][..]);
super::pbkdf2_hmac(b"pass\0word", b"sa\0lt", 1, MessageDigest::sha512(), &mut buf).unwrap();
super::pbkdf2_hmac(b"pass\0word",
b"sa\0lt",
1,
MessageDigest::sha512(),
&mut buf)
.unwrap();
assert_eq!(&buf[..],
&[0x71_u8, 0xa0_u8, 0xec_u8, 0x84_u8, 0x2a_u8, 0xbd_u8, 0x5c_u8, 0x67_u8,
0x8b_u8, 0xcf_u8, 0xd1_u8, 0x45_u8, 0xf0_u8, 0x9d_u8, 0x83_u8, 0x52_u8,
@ -150,7 +160,8 @@ mod tests {
b"salt\0\0\0",
50,
MessageDigest::sha512(),
&mut buf).unwrap();
&mut buf)
.unwrap();
assert_eq!(&buf[..],
&[0x01_u8, 0x68_u8, 0x71_u8, 0xa4_u8, 0xc4_u8, 0xb7_u8, 0x5f_u8, 0x96_u8,
0x85_u8, 0x7f_u8, 0xd2_u8, 0xb9_u8, 0xf8_u8, 0xca_u8, 0x28_u8, 0x02_u8,

View File

@ -178,9 +178,7 @@ impl Deref for PKey {
type Target = PKeyRef;
fn deref(&self) -> &PKeyRef {
unsafe {
PKeyRef::from_ptr(self.0)
}
unsafe { PKeyRef::from_ptr(self.0) }
}
}

View File

@ -338,23 +338,19 @@ mod compat {
[p, q]
}
pub unsafe fn set_key(r: *mut RSA,
n: *mut BIGNUM,
e: *mut BIGNUM,
d: *mut BIGNUM) -> c_int {
pub unsafe fn set_key(r: *mut RSA, n: *mut BIGNUM, e: *mut BIGNUM, d: *mut BIGNUM) -> c_int {
ffi::RSA_set0_key(r, n, e, d)
}
pub unsafe fn set_factors(r: *mut RSA,
p: *mut BIGNUM,
q: *mut BIGNUM) -> c_int {
pub unsafe fn set_factors(r: *mut RSA, p: *mut BIGNUM, q: *mut BIGNUM) -> c_int {
ffi::RSA_set0_factors(r, p, q)
}
pub unsafe fn set_crt_params(r: *mut RSA,
dmp1: *mut BIGNUM,
dmq1: *mut BIGNUM,
iqmp: *mut BIGNUM) -> c_int {
iqmp: *mut BIGNUM)
-> c_int {
ffi::RSA_set0_crt_params(r, dmp1, dmq1, iqmp)
}
}
@ -372,19 +368,14 @@ mod compat {
[(*r).p, (*r).q]
}
pub unsafe fn set_key(r: *mut RSA,
n: *mut BIGNUM,
e: *mut BIGNUM,
d: *mut BIGNUM) -> c_int {
pub unsafe fn set_key(r: *mut RSA, n: *mut BIGNUM, e: *mut BIGNUM, d: *mut BIGNUM) -> c_int {
(*r).n = n;
(*r).e = e;
(*r).d = d;
1 // TODO: is this right? should it be 0? what's success?
}
pub unsafe fn set_factors(r: *mut RSA,
p: *mut BIGNUM,
q: *mut BIGNUM) -> c_int {
pub unsafe fn set_factors(r: *mut RSA, p: *mut BIGNUM, q: *mut BIGNUM) -> c_int {
(*r).p = p;
(*r).q = q;
1 // TODO: is this right? should it be 0? what's success?
@ -393,7 +384,8 @@ mod compat {
pub unsafe fn set_crt_params(r: *mut RSA,
dmp1: *mut BIGNUM,
dmq1: *mut BIGNUM,
iqmp: *mut BIGNUM) -> c_int {
iqmp: *mut BIGNUM)
-> c_int {
(*r).dmp1 = dmp1;
(*r).dmq1 = dmq1;
(*r).iqmp = iqmp;
@ -421,7 +413,8 @@ mod test {
password[4] = b's' as c_char;
password[5] = b's' as c_char;
6
}).unwrap();
})
.unwrap();
assert!(password_queried);
}

View File

@ -166,9 +166,7 @@ impl<'a> Verifier<'a> {
pub fn finish(&self, signature: &[u8]) -> Result<bool, ErrorStack> {
unsafe {
let r = EVP_DigestVerifyFinal(self.0,
signature.as_ptr() as *const _,
signature.len());
let r = EVP_DigestVerifyFinal(self.0, signature.as_ptr() as *const _, signature.len());
match r {
1 => Ok(true),
0 => {
@ -199,7 +197,8 @@ use ffi::EVP_DigestVerifyFinal;
#[allow(bad_style)]
unsafe fn EVP_DigestVerifyFinal(ctx: *mut ffi::EVP_MD_CTX,
sigret: *const ::libc::c_uchar,
siglen: ::libc::size_t) -> ::libc::c_int {
siglen: ::libc::size_t)
-> ::libc::c_int {
ffi::EVP_DigestVerifyFinal(ctx, sigret as *mut _, siglen)
}
@ -218,25 +217,25 @@ mod test {
&[101, 121, 74, 104, 98, 71, 99, 105, 79, 105, 74, 83, 85, 122, 73, 49, 78, 105, 74, 57,
46, 101, 121, 74, 112, 99, 51, 77, 105, 79, 105, 74, 113, 98, 50, 85, 105, 76, 65, 48,
75, 73, 67, 74, 108, 101, 72, 65, 105, 79, 106, 69, 122, 77, 68, 65, 52, 77, 84, 107,
122, 79, 68, 65, 115, 68, 81, 111, 103, 73, 109, 104, 48, 100, 72, 65, 54, 76, 121,
57, 108, 101, 71, 70, 116, 99, 71, 120, 108, 76, 109, 78, 118, 98, 83, 57, 112, 99,
49, 57, 121, 98, 50, 57, 48, 73, 106, 112, 48, 99, 110, 86, 108, 102, 81];
122, 79, 68, 65, 115, 68, 81, 111, 103, 73, 109, 104, 48, 100, 72, 65, 54, 76, 121, 57,
108, 101, 71, 70, 116, 99, 71, 120, 108, 76, 109, 78, 118, 98, 83, 57, 112, 99, 49, 57,
121, 98, 50, 57, 48, 73, 106, 112, 48, 99, 110, 86, 108, 102, 81];
static SIGNATURE: &'static [u8] =
&[112, 46, 33, 137, 67, 232, 143, 209, 30, 181, 216, 45, 191, 120, 69, 243, 65, 6, 174,
27, 129, 255, 247, 115, 17, 22, 173, 209, 113, 125, 131, 101, 109, 66, 10, 253, 60,
150, 238, 221, 115, 162, 102, 62, 81, 102, 104, 123, 0, 11, 135, 34, 110, 1, 135, 237,
16, 115, 249, 69, 229, 130, 173, 252, 239, 22, 216, 90, 121, 142, 232, 198, 109, 219,
61, 184, 151, 91, 23, 208, 148, 2, 190, 237, 213, 217, 217, 112, 7, 16, 141, 178, 129,
96, 213, 248, 4, 12, 167, 68, 87, 98, 184, 31, 190, 127, 249, 217, 46, 10, 231, 111,
36, 242, 91, 51, 187, 230, 244, 74, 230, 30, 177, 4, 10, 203, 32, 4, 77, 62, 249, 18,
142, 212, 1, 48, 121, 91, 212, 189, 59, 65, 238, 202, 208, 102, 171, 101, 25, 129,
253, 228, 141, 247, 127, 55, 45, 195, 139, 159, 175, 221, 59, 239, 177, 139, 93, 163,
204, 60, 46, 176, 47, 158, 58, 65, 214, 18, 202, 173, 21, 145, 18, 115, 160, 95, 35,
185, 232, 56, 250, 175, 132, 157, 105, 132, 41, 239, 90, 30, 136, 121, 130, 54, 195,
212, 14, 96, 69, 34, 165, 68, 200, 242, 122, 122, 45, 184, 6, 99, 209, 108, 247, 202,
234, 86, 222, 64, 92, 178, 33, 90, 69, 178, 194, 85, 102, 181, 90, 193, 167, 72, 160,
112, 223, 200, 163, 42, 70, 149, 67, 208, 25, 238, 251, 71];
27, 129, 255, 247, 115, 17, 22, 173, 209, 113, 125, 131, 101, 109, 66, 10, 253, 60, 150,
238, 221, 115, 162, 102, 62, 81, 102, 104, 123, 0, 11, 135, 34, 110, 1, 135, 237, 16,
115, 249, 69, 229, 130, 173, 252, 239, 22, 216, 90, 121, 142, 232, 198, 109, 219, 61,
184, 151, 91, 23, 208, 148, 2, 190, 237, 213, 217, 217, 112, 7, 16, 141, 178, 129, 96,
213, 248, 4, 12, 167, 68, 87, 98, 184, 31, 190, 127, 249, 217, 46, 10, 231, 111, 36,
242, 91, 51, 187, 230, 244, 74, 230, 30, 177, 4, 10, 203, 32, 4, 77, 62, 249, 18, 142,
212, 1, 48, 121, 91, 212, 189, 59, 65, 238, 202, 208, 102, 171, 101, 25, 129, 253, 228,
141, 247, 127, 55, 45, 195, 139, 159, 175, 221, 59, 239, 177, 139, 93, 163, 204, 60, 46,
176, 47, 158, 58, 65, 214, 18, 202, 173, 21, 145, 18, 115, 160, 95, 35, 185, 232, 56,
250, 175, 132, 157, 105, 132, 41, 239, 90, 30, 136, 121, 130, 54, 195, 212, 14, 96, 69,
34, 165, 68, 200, 242, 122, 122, 45, 184, 6, 99, 209, 108, 247, 202, 234, 86, 222, 64,
92, 178, 33, 90, 69, 178, 194, 85, 102, 181, 90, 193, 167, 72, 160, 112, 223, 200, 163,
42, 70, 149, 67, 208, 25, 238, 251, 71];
#[test]
fn rsa_sign() {
@ -320,7 +319,7 @@ mod test {
verifier.update(&input).unwrap();
match verifier.finish(&sig) {
Ok(true) => panic!("unexpected success"),
Ok(false) | Err(_) => {},
Ok(false) | Err(_) => {}
}
}

View File

@ -1,6 +1,6 @@
use libc::{c_char, c_int, c_long, c_void, strlen};
use ffi::{BIO, BIO_CTRL_FLUSH, BIO_new, BIO_clear_retry_flags,
BIO_set_retry_read, BIO_set_retry_write};
use ffi::{BIO, BIO_CTRL_FLUSH, BIO_new, BIO_clear_retry_flags, BIO_set_retry_read,
BIO_set_retry_write};
use std::any::Any;
use std::io;
use std::io::prelude::*;
@ -76,7 +76,7 @@ fn catch_unwind<F, T>(f: F) -> Result<T, Box<Any + Send>>
::std::panic::catch_unwind(::std::panic::AssertUnwindSafe(f))
}
unsafe extern fn bwrite<S: Write>(bio: *mut BIO, buf: *const c_char, len: c_int) -> c_int {
unsafe extern "C" fn bwrite<S: Write>(bio: *mut BIO, buf: *const c_char, len: c_int) -> c_int {
BIO_clear_retry_flags(bio);
let state = state::<S>(bio);
@ -98,7 +98,7 @@ unsafe extern fn bwrite<S: Write>(bio: *mut BIO, buf: *const c_char, len: c_int)
}
}
unsafe extern fn bread<S: Read>(bio: *mut BIO, buf: *mut c_char, len: c_int) -> c_int {
unsafe extern "C" fn bread<S: Read>(bio: *mut BIO, buf: *mut c_char, len: c_int) -> c_int {
BIO_clear_retry_flags(bio);
let state = state::<S>(bio);
@ -128,11 +128,11 @@ fn retriable_error(err: &io::Error) -> bool {
}
}
unsafe extern fn bputs<S: Write>(bio: *mut BIO, s: *const c_char) -> c_int {
unsafe extern "C" fn bputs<S: Write>(bio: *mut BIO, s: *const c_char) -> c_int {
bwrite::<S>(bio, s, strlen(s) as c_int)
}
unsafe extern fn ctrl<S: Write>(bio: *mut BIO,
unsafe extern "C" fn ctrl<S: Write>(bio: *mut BIO,
cmd: c_int,
_num: c_long,
_ptr: *mut c_void)
@ -156,7 +156,7 @@ unsafe extern fn ctrl<S: Write>(bio: *mut BIO,
}
}
unsafe extern fn create(bio: *mut BIO) -> c_int {
unsafe extern "C" fn create(bio: *mut BIO) -> c_int {
compat::BIO_set_init(bio, 0);
compat::BIO_set_num(bio, 0);
compat::BIO_set_data(bio, ptr::null_mut());
@ -164,7 +164,7 @@ unsafe extern fn create(bio: *mut BIO) -> c_int {
1
}
unsafe extern fn destroy<S>(bio: *mut BIO) -> c_int {
unsafe extern "C" fn destroy<S>(bio: *mut BIO) -> c_int {
if bio.is_null() {
return 0;
}
@ -193,8 +193,7 @@ mod compat {
impl BIO_METHOD {
pub fn new<S: Read + Write>() -> BIO_METHOD {
unsafe {
let ptr = ffi::BIO_meth_new(ffi::BIO_TYPE_NONE,
b"rust\0".as_ptr() as *const _);
let ptr = ffi::BIO_meth_new(ffi::BIO_TYPE_NONE, b"rust\0".as_ptr() as *const _);
assert!(!ptr.is_null());
let ret = BIO_METHOD(ptr);
assert!(ffi::BIO_meth_set_write(ptr, super::bwrite::<S>) != 0);
@ -203,7 +202,7 @@ mod compat {
assert!(ffi::BIO_meth_set_ctrl(ptr, super::ctrl::<S>) != 0);
assert!(ffi::BIO_meth_set_create(ptr, super::create) != 0);
assert!(ffi::BIO_meth_set_destroy(ptr, super::destroy::<S>) != 0);
return ret
return ret;
}
}

View File

@ -238,7 +238,8 @@ fn setup_verify(ssl: &mut Ssl, domain: &str) -> Result<(), ErrorStack> {
#[cfg(not(any(ossl102, ossl110)))]
fn setup_verify(ssl: &mut Ssl, domain: &str) -> Result<(), ErrorStack> {
let domain = domain.to_owned();
ssl.set_verify_callback(SSL_VERIFY_PEER, move |p, x| verify::verify_callback(&domain, p, x));
ssl.set_verify_callback(SSL_VERIFY_PEER,
move |p, x| verify::verify_callback(&domain, p, x));
Ok(())
}

View File

@ -221,7 +221,7 @@ lazy_static! {
static ref ALPN_PROTOS_IDX: c_int = get_new_idx::<Vec<u8>>();
}
unsafe extern fn free_data_box<T>(_parent: *mut c_void,
unsafe extern "C" fn free_data_box<T>(_parent: *mut c_void,
ptr: *mut c_void,
_ad: *mut ffi::CRYPTO_EX_DATA,
_idx: c_int,
@ -250,7 +250,7 @@ fn get_new_ssl_idx<T>() -> c_int {
}
}
extern fn raw_verify<F>(preverify_ok: c_int, x509_ctx: *mut ffi::X509_STORE_CTX) -> c_int
extern "C" fn raw_verify<F>(preverify_ok: c_int, x509_ctx: *mut ffi::X509_STORE_CTX) -> c_int
where F: Fn(bool, &X509StoreContextRef) -> bool + Any + 'static + Sync + Send
{
unsafe {
@ -266,14 +266,13 @@ extern fn raw_verify<F>(preverify_ok: c_int, x509_ctx: *mut ffi::X509_STORE_CTX)
}
}
extern fn ssl_raw_verify<F>(preverify_ok: c_int, x509_ctx: *mut ffi::X509_STORE_CTX) -> c_int
extern "C" fn ssl_raw_verify<F>(preverify_ok: c_int, x509_ctx: *mut ffi::X509_STORE_CTX) -> c_int
where F: Fn(bool, &X509StoreContextRef) -> bool + Any + 'static + Sync + Send
{
unsafe {
let idx = ffi::SSL_get_ex_data_X509_STORE_CTX_idx();
let ssl = ffi::X509_STORE_CTX_get_ex_data(x509_ctx, idx);
let verify = ffi::SSL_get_ex_data(ssl as *const _,
get_ssl_verify_data_idx::<F>());
let verify = ffi::SSL_get_ex_data(ssl as *const _, get_ssl_verify_data_idx::<F>());
let verify: &F = &*(verify as *mut F);
let ctx = X509StoreContextRef::from_ptr(x509_ctx);
@ -282,7 +281,7 @@ extern fn ssl_raw_verify<F>(preverify_ok: c_int, x509_ctx: *mut ffi::X509_STORE_
}
}
extern fn raw_sni<F>(ssl: *mut ffi::SSL, al: *mut c_int, _arg: *mut c_void) -> c_int
extern "C" fn raw_sni<F>(ssl: *mut ffi::SSL, al: *mut c_int, _arg: *mut c_void) -> c_int
where F: Fn(&mut SslRef) -> Result<(), SniError> + Any + 'static + Sync + Send
{
unsafe {
@ -338,7 +337,7 @@ unsafe fn select_proto_using(ssl: *mut ffi::SSL,
/// supported by the server. It achieves this by delegating to the `SSL_select_next_proto`
/// function. The list of protocols supported by the client is found in the extra data of the
/// OpenSSL context.
extern fn raw_next_proto_select_cb(ssl: *mut ffi::SSL,
extern "C" fn raw_next_proto_select_cb(ssl: *mut ffi::SSL,
out: *mut *mut c_uchar,
outlen: *mut c_uchar,
inbuf: *const c_uchar,
@ -349,7 +348,7 @@ extern fn raw_next_proto_select_cb(ssl: *mut ffi::SSL,
}
#[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))]
extern fn raw_alpn_select_cb(ssl: *mut ffi::SSL,
extern "C" fn raw_alpn_select_cb(ssl: *mut ffi::SSL,
out: *mut *const c_uchar,
outlen: *mut c_uchar,
inbuf: *const c_uchar,
@ -366,7 +365,7 @@ extern fn raw_alpn_select_cb(ssl: *mut ffi::SSL,
/// that it supports.
/// The list of supported protocols is found in the extra data of the OpenSSL
/// context.
extern fn raw_next_protos_advertise_cb(ssl: *mut ffi::SSL,
extern "C" fn raw_next_protos_advertise_cb(ssl: *mut ffi::SSL,
out: *mut *const c_uchar,
outlen: *mut c_uint,
_arg: *mut c_void)
@ -458,7 +457,9 @@ impl SslContextBuilder {
{
unsafe {
let verify = Box::new(verify);
ffi::SSL_CTX_set_ex_data(self.as_ptr(), get_verify_data_idx::<F>(), mem::transmute(verify));
ffi::SSL_CTX_set_ex_data(self.as_ptr(),
get_verify_data_idx::<F>(),
mem::transmute(verify));
ffi::SSL_CTX_set_verify(self.as_ptr(), mode.bits as c_int, Some(raw_verify::<F>));
}
}
@ -475,8 +476,8 @@ impl SslContextBuilder {
ffi::SSL_CTX_set_ex_data(self.as_ptr(),
get_verify_data_idx::<F>(),
mem::transmute(callback));
let f: extern fn(_, _, _) -> _ = raw_sni::<F>;
let f: extern fn() = mem::transmute(f);
let f: extern "C" fn(_, _, _) -> _ = raw_sni::<F>;
let f: extern "C" fn() = mem::transmute(f);
ffi::SSL_CTX_set_tlsext_servername_callback(self.as_ptr(), Some(f));
}
}
@ -495,21 +496,15 @@ impl SslContextBuilder {
}
fn set_mode(&mut self, mode: c_long) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::SSL_CTX_set_mode(self.as_ptr(), mode) as c_int).map(|_| ())
}
unsafe { cvt(ffi::SSL_CTX_set_mode(self.as_ptr(), mode) as c_int).map(|_| ()) }
}
pub fn set_tmp_dh(&mut self, dh: &DhRef) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::SSL_CTX_set_tmp_dh(self.as_ptr(), dh.as_ptr()) as c_int).map(|_| ())
}
unsafe { cvt(ffi::SSL_CTX_set_tmp_dh(self.as_ptr(), dh.as_ptr()) as c_int).map(|_| ()) }
}
pub fn set_tmp_ecdh(&mut self, key: &EcKeyRef) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::SSL_CTX_set_tmp_ecdh(self.as_ptr(), key.as_ptr()) as c_int).map(|_| ())
}
unsafe { cvt(ffi::SSL_CTX_set_tmp_ecdh(self.as_ptr(), key.as_ptr()) as c_int).map(|_| ()) }
}
/// Use the default locations of trusted certificates for verification.
@ -518,9 +513,7 @@ impl SslContextBuilder {
/// environment variables if present, or defaults specified at OpenSSL
/// build time otherwise.
pub fn set_default_verify_paths(&mut self) -> Result<(), ErrorStack> {
unsafe{
cvt(ffi::SSL_CTX_set_default_verify_paths(self.as_ptr())).map(|_| ())
}
unsafe { cvt(ffi::SSL_CTX_set_default_verify_paths(self.as_ptr())).map(|_| ()) }
}
#[allow(non_snake_case)]
@ -568,21 +561,19 @@ impl SslContextBuilder {
}
/// Specifies the file that contains certificate chain
pub fn set_certificate_chain_file<P: AsRef<Path>>(&mut self, file: P)
pub fn set_certificate_chain_file<P: AsRef<Path>>(&mut self,
file: P)
-> Result<(), ErrorStack> {
let file = CString::new(file.as_ref().as_os_str().to_str().unwrap()).unwrap();
unsafe {
cvt(ffi::SSL_CTX_use_certificate_chain_file(self.as_ptr(),
file.as_ptr() as *const _))
cvt(ffi::SSL_CTX_use_certificate_chain_file(self.as_ptr(), file.as_ptr() as *const _))
.map(|_| ())
}
}
/// Specifies the certificate
pub fn set_certificate(&mut self, cert: &X509Ref) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::SSL_CTX_use_certificate(self.as_ptr(), cert.as_ptr())).map(|_| ())
}
unsafe { cvt(ffi::SSL_CTX_use_certificate(self.as_ptr(), cert.as_ptr())).map(|_| ()) }
}
/// Adds a certificate to the certificate chain presented together with the
@ -611,9 +602,7 @@ impl SslContextBuilder {
/// Specifies the private key
pub fn set_private_key(&mut self, key: &PKeyRef) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::SSL_CTX_use_PrivateKey(self.as_ptr(), key.as_ptr())).map(|_| ())
}
unsafe { cvt(ffi::SSL_CTX_use_PrivateKey(self.as_ptr(), key.as_ptr())).map(|_| ()) }
}
pub fn set_cipher_list(&mut self, cipher_list: &str) -> Result<(), ErrorStack> {
@ -636,9 +625,7 @@ impl SslContextBuilder {
#[cfg(ossl102)]
fn _set_ecdh_auto(&mut self, onoff: bool) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::SSL_CTX_set_ecdh_auto(self.as_ptr(), onoff as c_int)).map(|_| ())
}
unsafe { cvt(ffi::SSL_CTX_set_ecdh_auto(self.as_ptr(), onoff as c_int)).map(|_| ()) }
}
pub fn set_options(&mut self, option: SslOptions) -> SslOptions {
@ -724,9 +711,7 @@ impl SslContextBuilder {
/// Checks consistency between the private key and certificate.
pub fn check_private_key(&self) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::SSL_CTX_check_private_key(self.as_ptr())).map(|_| ())
}
unsafe { cvt(ffi::SSL_CTX_check_private_key(self.as_ptr())).map(|_| ()) }
}
pub fn build(self) -> SslContext {
@ -785,17 +770,13 @@ impl Deref for SslContext {
type Target = SslContextRef;
fn deref(&self) -> &SslContextRef {
unsafe {
SslContextRef::from_ptr(self.0)
}
unsafe { SslContextRef::from_ptr(self.0) }
}
}
impl DerefMut for SslContext {
fn deref_mut(&mut self) -> &mut SslContextRef {
unsafe {
SslContextRef::from_ptr_mut(self.0)
}
unsafe { SslContextRef::from_ptr_mut(self.0) }
}
}
@ -1099,9 +1080,7 @@ impl SslRef {
/// Changes the context corresponding to the current connection.
pub fn set_ssl_context(&mut self, ctx: &SslContextRef) -> Result<(), ErrorStack> {
unsafe {
cvt_p(ffi::SSL_set_SSL_CTX(self.as_ptr(), ctx.as_ptr())).map(|_| ())
}
unsafe { cvt_p(ffi::SSL_set_SSL_CTX(self.as_ptr(), ctx.as_ptr())).map(|_| ()) }
}
/// Returns the context corresponding to the current connection
@ -1122,16 +1101,12 @@ impl SslRef {
#[cfg(any(ossl102, ossl110))]
fn _param_mut(&mut self) -> &mut X509VerifyParamRef {
unsafe {
X509VerifyParamRef::from_ptr_mut(ffi::SSL_get0_param(self.as_ptr()))
}
unsafe { X509VerifyParamRef::from_ptr_mut(ffi::SSL_get0_param(self.as_ptr())) }
}
/// Returns the result of X509 certificate verification.
pub fn verify_result(&self) -> Option<X509VerifyError> {
unsafe {
X509VerifyError::from_raw(ffi::SSL_get_verify_result(self.as_ptr()))
}
unsafe { X509VerifyError::from_raw(ffi::SSL_get_verify_result(self.as_ptr())) }
}
}
@ -1161,17 +1136,13 @@ impl Deref for Ssl {
type Target = SslRef;
fn deref(&self) -> &SslRef {
unsafe {
SslRef::from_ptr(self.0)
}
unsafe { SslRef::from_ptr(self.0) }
}
}
impl DerefMut for Ssl {
fn deref_mut(&mut self) -> &mut SslRef {
unsafe {
SslRef::from_ptr_mut(self.0)
}
unsafe { SslRef::from_ptr_mut(self.0) }
}
}
@ -1275,7 +1246,8 @@ impl<S: Any + fmt::Debug> stderror::Error for HandshakeError<S> {
fn cause(&self) -> Option<&stderror::Error> {
match *self {
HandshakeError::SetupFailure(ref e) => Some(e),
HandshakeError::Failure(ref s) | HandshakeError::Interrupted(ref s) => Some(s.error()),
HandshakeError::Failure(ref s) |
HandshakeError::Interrupted(ref s) => Some(s.error()),
}
}
}
@ -1285,7 +1257,8 @@ impl<S: Any + fmt::Debug> fmt::Display for HandshakeError<S> {
try!(f.write_str(stderror::Error::description(self)));
match *self {
HandshakeError::SetupFailure(ref e) => try!(write!(f, ": {}", e)),
HandshakeError::Failure(ref s) | HandshakeError::Interrupted(ref s) => {
HandshakeError::Failure(ref s) |
HandshakeError::Interrupted(ref s) => {
try!(write!(f, ": {}", s.error()));
if let Some(err) = s.ssl().verify_result() {
try!(write!(f, ": {}", err));
@ -1577,15 +1550,11 @@ mod compat {
}
pub fn tls_method() -> *const ffi::SSL_METHOD {
unsafe {
ffi::TLS_method()
}
unsafe { ffi::TLS_method() }
}
pub fn dtls_method() -> *const ffi::SSL_METHOD {
unsafe {
ffi::DTLS_method()
}
unsafe { ffi::DTLS_method() }
}
}
@ -1598,22 +1567,17 @@ mod compat {
use libc::{self, c_long, c_ulong, c_int};
pub unsafe fn SSL_CTX_get_options(ctx: *const ffi::SSL_CTX) -> c_ulong {
ffi::SSL_CTX_ctrl(ctx as *mut _,
ffi::SSL_CTRL_OPTIONS,
0,
ptr::null_mut()) as c_ulong
ffi::SSL_CTX_ctrl(ctx as *mut _, ffi::SSL_CTRL_OPTIONS, 0, ptr::null_mut()) as c_ulong
}
pub unsafe fn SSL_CTX_set_options(ctx: *const ffi::SSL_CTX,
op: c_ulong) -> c_ulong {
pub unsafe fn SSL_CTX_set_options(ctx: *const ffi::SSL_CTX, op: c_ulong) -> c_ulong {
ffi::SSL_CTX_ctrl(ctx as *mut _,
ffi::SSL_CTRL_OPTIONS,
op as c_long,
ptr::null_mut()) as c_ulong
}
pub unsafe fn SSL_CTX_clear_options(ctx: *const ffi::SSL_CTX,
op: c_ulong) -> c_ulong {
pub unsafe fn SSL_CTX_clear_options(ctx: *const ffi::SSL_CTX, op: c_ulong) -> c_ulong {
ffi::SSL_CTX_ctrl(ctx as *mut _,
ffi::SSL_CTRL_CLEAR_OPTIONS,
op as c_long,
@ -1621,19 +1585,11 @@ mod compat {
}
pub unsafe fn get_new_idx(f: ffi::CRYPTO_EX_free) -> c_int {
ffi::SSL_CTX_get_ex_new_index(0,
ptr::null_mut(),
None,
None,
Some(f))
ffi::SSL_CTX_get_ex_new_index(0, ptr::null_mut(), None, None, Some(f))
}
pub unsafe fn get_new_ssl_idx(f: ffi::CRYPTO_EX_free) -> c_int {
ffi::SSL_get_ex_new_index(0,
ptr::null_mut(),
None,
None,
Some(f))
ffi::SSL_get_ex_new_index(0, ptr::null_mut(), None, None, Some(f))
}
pub unsafe fn SSL_CTX_up_ref(ssl: *mut ffi::SSL_CTX) -> libc::c_int {
@ -1646,14 +1602,10 @@ mod compat {
}
pub fn tls_method() -> *const ffi::SSL_METHOD {
unsafe {
ffi::SSLv23_method()
}
unsafe { ffi::SSLv23_method() }
}
pub fn dtls_method() -> *const ffi::SSL_METHOD {
unsafe {
ffi::DTLSv1_method()
}
unsafe { ffi::DTLSv1_method() }
}
}

View File

@ -75,7 +75,11 @@ impl Server {
if let Some(mut input) = input {
thread::spawn(move || input(stdin));
}
(Server { p: child, _temp: td }, addr)
(Server {
p: child,
_temp: td,
},
addr)
}
fn new_tcp(args: &[&str]) -> (Server, TcpStream) {
@ -815,8 +819,7 @@ fn wait_io(stream: &TcpStream, read: bool, timeout_ms: u32) -> bool {
}
}
fn handshake(res: Result<SslStream<TcpStream>, HandshakeError<TcpStream>>)
-> SslStream<TcpStream> {
fn handshake(res: Result<SslStream<TcpStream>, HandshakeError<TcpStream>>) -> SslStream<TcpStream> {
match res {
Ok(s) => s,
Err(HandshakeError::Interrupted(s)) => {
@ -1112,8 +1115,10 @@ fn connector_client_server_mozilla_intermediate() {
let t = thread::spawn(move || {
let key = PKey::private_key_from_pem(KEY).unwrap();
let cert = X509::from_pem(CERT).unwrap();
let connector = ServerConnectorBuilder::mozilla_intermediate(
SslMethod::tls(), &key, &cert, None::<X509>)
let connector = ServerConnectorBuilder::mozilla_intermediate(SslMethod::tls(),
&key,
&cert,
None::<X509>)
.unwrap()
.build();
let stream = listener.accept().unwrap().0;
@ -1144,8 +1149,8 @@ fn connector_client_server_mozilla_modern() {
let t = thread::spawn(move || {
let key = PKey::private_key_from_pem(KEY).unwrap();
let cert = X509::from_pem(CERT).unwrap();
let connector = ServerConnectorBuilder::mozilla_modern(
SslMethod::tls(), &key, &cert, None::<X509>)
let connector =
ServerConnectorBuilder::mozilla_modern(SslMethod::tls(), &key, &cert, None::<X509>)
.unwrap()
.build();
let stream = listener.accept().unwrap().0;

View File

@ -17,117 +17,79 @@ pub struct Cipher(*const ffi::EVP_CIPHER);
impl Cipher {
pub fn aes_128_ecb() -> Cipher {
unsafe {
Cipher(ffi::EVP_aes_128_ecb())
}
unsafe { Cipher(ffi::EVP_aes_128_ecb()) }
}
pub fn aes_128_cbc() -> Cipher {
unsafe {
Cipher(ffi::EVP_aes_128_cbc())
}
unsafe { Cipher(ffi::EVP_aes_128_cbc()) }
}
pub fn aes_128_xts() -> Cipher {
unsafe {
Cipher(ffi::EVP_aes_128_xts())
}
unsafe { Cipher(ffi::EVP_aes_128_xts()) }
}
pub fn aes_128_ctr() -> Cipher {
unsafe {
Cipher(ffi::EVP_aes_128_ctr())
}
unsafe { Cipher(ffi::EVP_aes_128_ctr()) }
}
pub fn aes_128_cfb1() -> Cipher {
unsafe {
Cipher(ffi::EVP_aes_128_cfb1())
}
unsafe { Cipher(ffi::EVP_aes_128_cfb1()) }
}
pub fn aes_128_cfb128() -> Cipher {
unsafe {
Cipher(ffi::EVP_aes_128_cfb128())
}
unsafe { Cipher(ffi::EVP_aes_128_cfb128()) }
}
pub fn aes_128_cfb8() -> Cipher {
unsafe {
Cipher(ffi::EVP_aes_128_cfb8())
}
unsafe { Cipher(ffi::EVP_aes_128_cfb8()) }
}
pub fn aes_128_gcm() -> Cipher {
unsafe {
Cipher(ffi::EVP_aes_128_gcm())
}
unsafe { Cipher(ffi::EVP_aes_128_gcm()) }
}
pub fn aes_256_ecb() -> Cipher {
unsafe {
Cipher(ffi::EVP_aes_256_ecb())
}
unsafe { Cipher(ffi::EVP_aes_256_ecb()) }
}
pub fn aes_256_cbc() -> Cipher {
unsafe {
Cipher(ffi::EVP_aes_256_cbc())
}
unsafe { Cipher(ffi::EVP_aes_256_cbc()) }
}
pub fn aes_256_xts() -> Cipher {
unsafe {
Cipher(ffi::EVP_aes_256_xts())
}
unsafe { Cipher(ffi::EVP_aes_256_xts()) }
}
pub fn aes_256_ctr() -> Cipher {
unsafe {
Cipher(ffi::EVP_aes_256_ctr())
}
unsafe { Cipher(ffi::EVP_aes_256_ctr()) }
}
pub fn aes_256_cfb1() -> Cipher {
unsafe {
Cipher(ffi::EVP_aes_256_cfb1())
}
unsafe { Cipher(ffi::EVP_aes_256_cfb1()) }
}
pub fn aes_256_cfb128() -> Cipher {
unsafe {
Cipher(ffi::EVP_aes_256_cfb128())
}
unsafe { Cipher(ffi::EVP_aes_256_cfb128()) }
}
pub fn aes_256_cfb8() -> Cipher {
unsafe {
Cipher(ffi::EVP_aes_256_cfb8())
}
unsafe { Cipher(ffi::EVP_aes_256_cfb8()) }
}
pub fn aes_256_gcm() -> Cipher {
unsafe {
Cipher(ffi::EVP_aes_256_gcm())
}
unsafe { Cipher(ffi::EVP_aes_256_gcm()) }
}
pub fn des_cbc() -> Cipher {
unsafe {
Cipher(ffi::EVP_des_cbc())
}
unsafe { Cipher(ffi::EVP_des_cbc()) }
}
pub fn des_ecb() -> Cipher {
unsafe {
Cipher(ffi::EVP_des_ecb())
}
unsafe { Cipher(ffi::EVP_des_ecb()) }
}
pub fn rc4() -> Cipher {
unsafe {
Cipher(ffi::EVP_rc4())
}
unsafe { Cipher(ffi::EVP_rc4()) }
}
pub unsafe fn from_ptr(ptr: *const ffi::EVP_CIPHER) -> Cipher {
@ -140,9 +102,7 @@ impl Cipher {
/// Returns the length of keys used with this cipher.
pub fn key_len(&self) -> usize {
unsafe {
EVP_CIPHER_key_length(self.0) as usize
}
unsafe { EVP_CIPHER_key_length(self.0) as usize }
}
/// Returns the length of the IV used with this cipher, or `None` if the
@ -150,11 +110,7 @@ impl Cipher {
pub fn iv_len(&self) -> Option<usize> {
unsafe {
let len = EVP_CIPHER_iv_length(self.0) as usize;
if len == 0 {
None
} else {
Some(len)
}
if len == 0 { None } else { Some(len) }
}
}
@ -164,9 +120,7 @@ impl Cipher {
///
/// Stream ciphers such as RC4 have a block size of 1.
pub fn block_size(&self) -> usize {
unsafe {
EVP_CIPHER_block_size(self.0) as usize
}
unsafe { EVP_CIPHER_block_size(self.0) as usize }
}
}
@ -183,7 +137,11 @@ impl Crypter {
///
/// Panics if an IV is required by the cipher but not provided, or if the
/// IV's length does not match the expected length (see `Cipher::iv_len`).
pub fn new(t: Cipher, mode: Mode, key: &[u8], iv: Option<&[u8]>) -> Result<Crypter, ErrorStack> {
pub fn new(t: Cipher,
mode: Mode,
key: &[u8],
iv: Option<&[u8]>)
-> Result<Crypter, ErrorStack> {
ffi::init();
unsafe {
@ -233,7 +191,9 @@ impl Crypter {
/// If padding is disabled, total amount of data encrypted/decrypted must
/// be a multiple of the cipher's block size.
pub fn pad(&mut self, padding: bool) {
unsafe { ffi::EVP_CIPHER_CTX_set_padding(self.ctx, padding as c_int); }
unsafe {
ffi::EVP_CIPHER_CTX_set_padding(self.ctx, padding as c_int);
}
}
/// Feeds data from `input` through the cipher, writing encrypted/decrypted
@ -375,7 +335,8 @@ mod tests {
let mut c = super::Crypter::new(super::Cipher::aes_256_ecb(),
super::Mode::Encrypt,
&k0,
None).unwrap();
None)
.unwrap();
c.pad(false);
let mut r0 = vec![0; c0.len() + super::Cipher::aes_256_ecb().block_size()];
let count = c.update(&p0, &mut r0).unwrap();
@ -386,7 +347,8 @@ mod tests {
let mut c = super::Crypter::new(super::Cipher::aes_256_ecb(),
super::Mode::Decrypt,
&k0,
None).unwrap();
None)
.unwrap();
c.pad(false);
let mut p1 = vec![0; r0.len() + super::Cipher::aes_256_ecb().block_size()];
let count = c.update(&r0, &mut p1).unwrap();
@ -409,7 +371,8 @@ mod tests {
let mut cr = super::Crypter::new(super::Cipher::aes_256_cbc(),
super::Mode::Decrypt,
&data,
Some(&iv)).unwrap();
Some(&iv))
.unwrap();
cr.pad(false);
let mut unciphered_data = vec![0; data.len() + super::Cipher::aes_256_cbc().block_size()];
let count = cr.update(&ciphered_data, &mut unciphered_data).unwrap();

View File

@ -36,12 +36,13 @@ impl<F> Drop for CallbackState<F> {
/// Password callback function, passed to private key loading functions.
///
/// `cb_state` is expected to be a pointer to a `CallbackState`.
pub unsafe extern fn invoke_passwd_cb<F>(buf: *mut c_char,
pub unsafe extern "C" fn invoke_passwd_cb<F>(buf: *mut c_char,
size: c_int,
_rwflag: c_int,
cb_state: *mut c_void)
-> c_int
where F: FnOnce(&mut [c_char]) -> usize {
where F: FnOnce(&mut [c_char]) -> usize
{
let callback = &mut *(cb_state as *mut CallbackState<F>);
let result = panic::catch_unwind(AssertUnwindSafe(|| {

View File

@ -14,15 +14,10 @@
use std::ffi::CStr;
#[cfg(ossl10x)]
use ffi::{
SSLEAY_VERSION as OPENSSL_VERSION,
SSLEAY_CFLAGS as OPENSSL_CFLAGS,
SSLEAY_BUILT_ON as OPENSSL_BUILT_ON,
SSLEAY_PLATFORM as OPENSSL_PLATFORM,
SSLEAY_DIR as OPENSSL_DIR,
SSLeay as OpenSSL_version_num,
SSLeay_version as OpenSSL_version,
};
use ffi::{SSLEAY_VERSION as OPENSSL_VERSION, SSLEAY_CFLAGS as OPENSSL_CFLAGS,
SSLEAY_BUILT_ON as OPENSSL_BUILT_ON, SSLEAY_PLATFORM as OPENSSL_PLATFORM,
SSLEAY_DIR as OPENSSL_DIR, SSLeay as OpenSSL_version_num,
SSLeay_version as OpenSSL_version};
#[cfg(ossl110)]
use ffi::{OPENSSL_VERSION, OPENSSL_CFLAGS};

View File

@ -26,17 +26,10 @@ use nid::Nid;
use opaque::Opaque;
#[cfg(ossl10x)]
use ffi::{
X509_set_notBefore,
X509_set_notAfter,
ASN1_STRING_data,
};
use ffi::{X509_set_notBefore, X509_set_notAfter, ASN1_STRING_data};
#[cfg(ossl110)]
use ffi::{
X509_set1_notBefore as X509_set_notBefore,
X509_set1_notAfter as X509_set_notAfter,
ASN1_STRING_get0_data as ASN1_STRING_data,
};
use ffi::{X509_set1_notBefore as X509_set_notBefore, X509_set1_notAfter as X509_set_notAfter,
ASN1_STRING_get0_data as ASN1_STRING_data};
#[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))]
pub mod verify;
@ -68,9 +61,7 @@ impl X509StoreContextRef {
}
pub fn error(&self) -> Option<X509VerifyError> {
unsafe {
X509VerifyError::from_raw(ffi::X509_STORE_CTX_get_error(self.as_ptr()) as c_long)
}
unsafe { X509VerifyError::from_raw(ffi::X509_STORE_CTX_get_error(self.as_ptr()) as c_long) }
}
pub fn current_cert(&self) -> Option<&X509Ref> {
@ -386,9 +377,7 @@ impl X509Ref {
return None;
}
Some(GeneralNames {
stack: stack as *mut _,
})
Some(GeneralNames { stack: stack as *mut _ })
}
}
@ -495,9 +484,7 @@ impl Deref for X509 {
type Target = X509Ref;
fn deref(&self) -> &X509Ref {
unsafe {
X509Ref::from_ptr(self.0)
}
unsafe { X509Ref::from_ptr(self.0) }
}
}
@ -749,8 +736,8 @@ impl Drop for GeneralNames {
fn drop(&mut self) {
unsafe {
// This transmute is dubious but it's what openssl itself does...
let free: unsafe extern fn(*mut ffi::GENERAL_NAME) = ffi::GENERAL_NAME_free;
let free: unsafe extern fn(*mut c_void) = mem::transmute(free);
let free: unsafe extern "C" fn(*mut ffi::GENERAL_NAME) = ffi::GENERAL_NAME_free;
let free: unsafe extern "C" fn(*mut c_void) = mem::transmute(free);
ffi::sk_pop_free(&mut (*self.stack).stack, Some(free));
}
}
@ -759,8 +746,8 @@ impl Drop for GeneralNames {
fn drop(&mut self) {
unsafe {
// This transmute is dubious but it's what openssl itself does...
let free: unsafe extern fn(*mut ffi::GENERAL_NAME) = ffi::GENERAL_NAME_free;
let free: unsafe extern fn(*mut c_void) = mem::transmute(free);
let free: unsafe extern "C" fn(*mut ffi::GENERAL_NAME) = ffi::GENERAL_NAME_free;
let free: unsafe extern "C" fn(*mut c_void) = mem::transmute(free);
ffi::OPENSSL_sk_pop_free(self.stack as *mut _, Some(free));
}
}

View File

@ -60,8 +60,7 @@ fn test_cert_gen_extension_ordering() {
fn test_cert_gen_extension_bad_ordering() {
let pkey = pkey();
let result = get_generator()
.add_extension(OtherNid(nid::AUTHORITY_KEY_IDENTIFIER,
"keyid:always".to_owned()))
.add_extension(OtherNid(nid::AUTHORITY_KEY_IDENTIFIER, "keyid:always".to_owned()))
.add_extension(OtherNid(nid::SUBJECT_KEY_IDENTIFIER, "hash".to_owned()))
.sign(&pkey);