diff --git a/openssl/src/asn1.rs b/openssl/src/asn1.rs index e9c58e76..9a83a5da 100644 --- a/openssl/src/asn1.rs +++ b/openssl/src/asn1.rs @@ -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) } } } diff --git a/openssl/src/bio.rs b/openssl/src/bio.rs index 199fc0c8..5fc4f31f 100644 --- a/openssl/src/bio.rs +++ b/openssl/src/bio.rs @@ -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 { 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)) } diff --git a/openssl/src/bn.rs b/openssl/src/bn.rs index fb0c286c..78684d0a 100644 --- a/openssl/src/bn.rs +++ b/openssl/src/bn.rs @@ -37,9 +37,7 @@ impl Drop for BnCtx { impl BnCtx { /// Returns a new `BnCtx`. pub fn new() -> Result { - 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 { 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 { + do_trial_division: bool) + -> Result { 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 { - 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) } } } diff --git a/openssl/src/dh.rs b/openssl/src/dh.rs index b0c9737b..f2659eb3 100644 --- a/openssl/src/dh.rs +++ b/openssl/src/dh.rs @@ -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 { - 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 { - 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 { - 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; @@ -142,7 +133,7 @@ mod tests { CACB83E6B486F6B3CA3F7971506026C0B857F689962856DED4010ABD0BE\ 621C3A3960A54E710C375F26375D7014103A4B54330C198AF126116D227\ 6E11715F693877FAD7EF09CADB094AE91E1A1597") - .unwrap(); + .unwrap(); let g = BigNum::from_hex_str("3FB32C9B73134D0B2E77506660EDBD484CA7B18F21EF205407F4793A1A0\ BA12510DBC15077BE463FFF4FED4AAC0BB555BE3A6C1B0C6B47B1BC3773\ BF7E8C6F62901228F8C28CBB18A55AE31341000A650196F931C77A57F2D\ @@ -152,10 +143,10 @@ mod tests { D2BBD2DF016199ECD06E1557CD0915B3353BBB64E0EC377FD028370DF92\ B52C7891428CDC67EB6184B523D1DB246C32F63078490F00EF8D647D148\ D47954515E2327CFEF98C582664B4C0F6CC41659") - .unwrap(); + .unwrap(); let q = BigNum::from_hex_str("8CF83642A709A097B447997640129DA299B1A47D1EB3750BA308B0FE64F\ 5FBD3") - .unwrap(); + .unwrap(); let dh = Dh::from_params(p, g, q).unwrap(); ctx.set_tmp_dh(&dh).unwrap(); } diff --git a/openssl/src/dsa.rs b/openssl/src/dsa.rs index 46bdfaff..9351d852 100644 --- a/openssl/src/dsa.rs +++ b/openssl/src/dsa.rs @@ -105,8 +105,7 @@ impl Dsa { } /// Writes an DSA private key as unencrypted PEM formatted data - pub fn private_key_to_pem(&self) -> Result, ErrorStack> - { + pub fn private_key_to_pem(&self) -> Result, 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 - { + pub fn public_key_from_pem(buf: &[u8]) -> Result { ffi::init(); let mem_bio = try!(MemBioSlice::new(buf)); @@ -250,15 +248,16 @@ mod test { let mut password_queried = false; let key = include_bytes!("../test/dsa-encrypted.pem"); Dsa::private_key_from_pem_cb(key, |password| { - password_queried = true; - password[0] = b'm' as c_char; - password[1] = b'y' as c_char; - password[2] = b'p' as c_char; - password[3] = b'a' as c_char; - password[4] = b's' as c_char; - password[5] = b's' as c_char; - 6 - }).unwrap(); + password_queried = true; + password[0] = b'm' as c_char; + password[1] = b'y' as c_char; + password[2] = b'p' as c_char; + password[3] = b'a' as c_char; + password[4] = b's' as c_char; + password[5] = b's' as c_char; + 6 + }) + .unwrap(); assert!(password_queried); } diff --git a/openssl/src/ec_key.rs b/openssl/src/ec_key.rs index 5d634c5a..81b790aa 100644 --- a/openssl/src/ec_key.rs +++ b/openssl/src/ec_key.rs @@ -30,9 +30,7 @@ impl Drop for EcKey { impl EcKey { pub fn new_by_curve_name(nid: Nid) -> Result { - 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) } } } diff --git a/openssl/src/hash.rs b/openssl/src/hash.rs index 4093ab79..c91976bf 100644 --- a/openssl/src/hash.rs +++ b/openssl/src/hash.rs @@ -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() { diff --git a/openssl/src/lib.rs b/openssl/src/lib.rs index 4212e9de..f335c097 100644 --- a/openssl/src/lib.rs +++ b/openssl/src/lib.rs @@ -63,9 +63,5 @@ pub fn cvt(r: c_int) -> Result { } pub fn cvt_n(r: c_int) -> Result { - if r < 0 { - Err(ErrorStack::get()) - } else { - Ok(r) - } + if r < 0 { Err(ErrorStack::get()) } else { Ok(r) } } diff --git a/openssl/src/nid.rs b/openssl/src/nid.rs index b58e3a3d..afbd60a5 100644 --- a/openssl/src/nid.rs +++ b/openssl/src/nid.rs @@ -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); - diff --git a/openssl/src/pkcs12.rs b/openssl/src/pkcs12.rs index d5d4750a..ab0934a8 100644 --- a/openssl/src/pkcs12.rs +++ b/openssl/src/pkcs12.rs @@ -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 } } diff --git a/openssl/src/pkcs5.rs b/openssl/src/pkcs5.rs index b0c899e5..8d6dcce8 100644 --- a/openssl/src/pkcs5.rs +++ b/openssl/src/pkcs5.rs @@ -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, diff --git a/openssl/src/pkey.rs b/openssl/src/pkey.rs index 4cbfcce7..fc48c8b4 100644 --- a/openssl/src/pkey.rs +++ b/openssl/src/pkey.rs @@ -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) } } } diff --git a/openssl/src/rsa.rs b/openssl/src/rsa.rs index e63e567d..666b99dd 100644 --- a/openssl/src/rsa.rs +++ b/openssl/src/rsa.rs @@ -178,7 +178,7 @@ impl Rsa { to.as_mut_ptr(), self.0, padding.0))); - Ok(len as usize) + Ok(len as usize) } } @@ -203,7 +203,7 @@ impl Rsa { to.as_mut_ptr(), self.0, padding.0))); - Ok(len as usize) + Ok(len as usize) } } @@ -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; @@ -413,15 +405,16 @@ mod test { let mut password_queried = false; let key = include_bytes!("../test/rsa-encrypted.pem"); Rsa::private_key_from_pem_cb(key, |password| { - password_queried = true; - password[0] = b'm' as c_char; - password[1] = b'y' as c_char; - password[2] = b'p' as c_char; - password[3] = b'a' as c_char; - password[4] = b's' as c_char; - password[5] = b's' as c_char; - 6 - }).unwrap(); + password_queried = true; + password[0] = b'm' as c_char; + password[1] = b'y' as c_char; + password[2] = b'p' as c_char; + password[3] = b'a' as c_char; + password[4] = b's' as c_char; + password[5] = b's' as c_char; + 6 + }) + .unwrap(); assert!(password_queried); } @@ -441,11 +434,11 @@ mod test { let mut dec_result = vec![0; private_key.size()]; let len = private_key.private_decrypt(&result, &mut dec_result, PKCS1_PADDING).unwrap(); - assert_eq!(&dec_result[..len], original_data); + assert_eq!(&dec_result[..len], original_data); } #[test] - fn test_private_encrypt() { + fn test_private_encrypt() { let k0 = super::Rsa::generate(512).unwrap(); let k0pkey = k0.public_key_to_pem().unwrap(); let k1 = super::Rsa::public_key_from_pem(&k0pkey).unwrap(); @@ -457,21 +450,21 @@ mod test { let mut dmesg = vec![0; k1.size()]; let len = k1.public_decrypt(&emesg, &mut dmesg, PKCS1_PADDING).unwrap(); assert_eq!(msg, &dmesg[..len]); - } + } - #[test] - fn test_public_encrypt() { - let k0 = super::Rsa::generate(512).unwrap(); - let k0pkey = k0.private_key_to_pem().unwrap(); - let k1 = super::Rsa::private_key_from_pem(&k0pkey).unwrap(); + #[test] + fn test_public_encrypt() { + let k0 = super::Rsa::generate(512).unwrap(); + let k0pkey = k0.private_key_to_pem().unwrap(); + let k1 = super::Rsa::private_key_from_pem(&k0pkey).unwrap(); - let msg = vec![0xdeu8, 0xadu8, 0xd0u8, 0x0du8]; + let msg = vec![0xdeu8, 0xadu8, 0xd0u8, 0x0du8]; - let mut emesg = vec![0; k0.size()]; - k0.public_encrypt(&msg, &mut emesg, PKCS1_PADDING).unwrap(); - let mut dmesg = vec![0; k1.size()]; - let len = k1.private_decrypt(&emesg, &mut dmesg, PKCS1_PADDING).unwrap(); - assert_eq!(msg, &dmesg[..len]); - } + let mut emesg = vec![0; k0.size()]; + k0.public_encrypt(&msg, &mut emesg, PKCS1_PADDING).unwrap(); + let mut dmesg = vec![0; k1.size()]; + let len = k1.private_decrypt(&emesg, &mut dmesg, PKCS1_PADDING).unwrap(); + assert_eq!(msg, &dmesg[..len]); + } } diff --git a/openssl/src/sign.rs b/openssl/src/sign.rs index a1a37ce6..eeee5cc7 100644 --- a/openssl/src/sign.rs +++ b/openssl/src/sign.rs @@ -166,9 +166,7 @@ impl<'a> Verifier<'a> { pub fn finish(&self, signature: &[u8]) -> Result { 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) } @@ -216,27 +215,27 @@ mod test { static INPUT: &'static [u8] = &[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]; + 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]; 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(_) => {} } } @@ -337,29 +336,29 @@ mod test { fn hmac_md5() { // test vectors from RFC 2202 let tests: [(Vec, Vec, Vec); 7] = - [(iter::repeat(0x0b_u8).take(16).collect(), - b"Hi There".to_vec(), - "9294727a3638bb1c13f48ef8158bfc9d".from_hex().unwrap()), - (b"Jefe".to_vec(), - b"what do ya want for nothing?".to_vec(), - "750c783e6ab0b503eaa86e310a5db738".from_hex().unwrap()), - (iter::repeat(0xaa_u8).take(16).collect(), - iter::repeat(0xdd_u8).take(50).collect(), - "56be34521d144c88dbb8c733f0e8b3f6".from_hex().unwrap()), - ("0102030405060708090a0b0c0d0e0f10111213141516171819".from_hex().unwrap(), - iter::repeat(0xcd_u8).take(50).collect(), - "697eaf0aca3a3aea3a75164746ffaa79".from_hex().unwrap()), - (iter::repeat(0x0c_u8).take(16).collect(), - b"Test With Truncation".to_vec(), - "56461ef2342edc00f9bab995690efd4c".from_hex().unwrap()), - (iter::repeat(0xaa_u8).take(80).collect(), - b"Test Using Larger Than Block-Size Key - Hash Key First".to_vec(), - "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd".from_hex().unwrap()), - (iter::repeat(0xaa_u8).take(80).collect(), - b"Test Using Larger Than Block-Size Key \ + [(iter::repeat(0x0b_u8).take(16).collect(), + b"Hi There".to_vec(), + "9294727a3638bb1c13f48ef8158bfc9d".from_hex().unwrap()), + (b"Jefe".to_vec(), + b"what do ya want for nothing?".to_vec(), + "750c783e6ab0b503eaa86e310a5db738".from_hex().unwrap()), + (iter::repeat(0xaa_u8).take(16).collect(), + iter::repeat(0xdd_u8).take(50).collect(), + "56be34521d144c88dbb8c733f0e8b3f6".from_hex().unwrap()), + ("0102030405060708090a0b0c0d0e0f10111213141516171819".from_hex().unwrap(), + iter::repeat(0xcd_u8).take(50).collect(), + "697eaf0aca3a3aea3a75164746ffaa79".from_hex().unwrap()), + (iter::repeat(0x0c_u8).take(16).collect(), + b"Test With Truncation".to_vec(), + "56461ef2342edc00f9bab995690efd4c".from_hex().unwrap()), + (iter::repeat(0xaa_u8).take(80).collect(), + b"Test Using Larger Than Block-Size Key - Hash Key First".to_vec(), + "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd".from_hex().unwrap()), + (iter::repeat(0xaa_u8).take(80).collect(), + b"Test Using Larger Than Block-Size Key \ and Larger Than One Block-Size Data" .to_vec(), - "6f630fad67cda0ee1fb1f562db3aa53e".from_hex().unwrap())]; + "6f630fad67cda0ee1fb1f562db3aa53e".from_hex().unwrap())]; test_hmac(MessageDigest::md5(), &tests); } @@ -368,29 +367,29 @@ mod test { fn hmac_sha1() { // test vectors from RFC 2202 let tests: [(Vec, Vec, Vec); 7] = - [(iter::repeat(0x0b_u8).take(20).collect(), - b"Hi There".to_vec(), - "b617318655057264e28bc0b6fb378c8ef146be00".from_hex().unwrap()), - (b"Jefe".to_vec(), - b"what do ya want for nothing?".to_vec(), - "effcdf6ae5eb2fa2d27416d5f184df9c259a7c79".from_hex().unwrap()), - (iter::repeat(0xaa_u8).take(20).collect(), - iter::repeat(0xdd_u8).take(50).collect(), - "125d7342b9ac11cd91a39af48aa17b4f63f175d3".from_hex().unwrap()), - ("0102030405060708090a0b0c0d0e0f10111213141516171819".from_hex().unwrap(), - iter::repeat(0xcd_u8).take(50).collect(), - "4c9007f4026250c6bc8414f9bf50c86c2d7235da".from_hex().unwrap()), - (iter::repeat(0x0c_u8).take(20).collect(), - b"Test With Truncation".to_vec(), - "4c1a03424b55e07fe7f27be1d58bb9324a9a5a04".from_hex().unwrap()), - (iter::repeat(0xaa_u8).take(80).collect(), - b"Test Using Larger Than Block-Size Key - Hash Key First".to_vec(), - "aa4ae5e15272d00e95705637ce8a3b55ed402112".from_hex().unwrap()), - (iter::repeat(0xaa_u8).take(80).collect(), - b"Test Using Larger Than Block-Size Key \ + [(iter::repeat(0x0b_u8).take(20).collect(), + b"Hi There".to_vec(), + "b617318655057264e28bc0b6fb378c8ef146be00".from_hex().unwrap()), + (b"Jefe".to_vec(), + b"what do ya want for nothing?".to_vec(), + "effcdf6ae5eb2fa2d27416d5f184df9c259a7c79".from_hex().unwrap()), + (iter::repeat(0xaa_u8).take(20).collect(), + iter::repeat(0xdd_u8).take(50).collect(), + "125d7342b9ac11cd91a39af48aa17b4f63f175d3".from_hex().unwrap()), + ("0102030405060708090a0b0c0d0e0f10111213141516171819".from_hex().unwrap(), + iter::repeat(0xcd_u8).take(50).collect(), + "4c9007f4026250c6bc8414f9bf50c86c2d7235da".from_hex().unwrap()), + (iter::repeat(0x0c_u8).take(20).collect(), + b"Test With Truncation".to_vec(), + "4c1a03424b55e07fe7f27be1d58bb9324a9a5a04".from_hex().unwrap()), + (iter::repeat(0xaa_u8).take(80).collect(), + b"Test Using Larger Than Block-Size Key - Hash Key First".to_vec(), + "aa4ae5e15272d00e95705637ce8a3b55ed402112".from_hex().unwrap()), + (iter::repeat(0xaa_u8).take(80).collect(), + b"Test Using Larger Than Block-Size Key \ and Larger Than One Block-Size Data" .to_vec(), - "e8e99d0f45237d786d6bbaa7965c7808bbff1a91".from_hex().unwrap())]; + "e8e99d0f45237d786d6bbaa7965c7808bbff1a91".from_hex().unwrap())]; test_hmac(MessageDigest::sha1(), &tests); } diff --git a/openssl/src/ssl/bio.rs b/openssl/src/ssl/bio.rs index a0215c2f..486b4dba 100644 --- a/openssl/src/ssl/bio.rs +++ b/openssl/src/ssl/bio.rs @@ -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: F) -> Result> ::std::panic::catch_unwind(::std::panic::AssertUnwindSafe(f)) } -unsafe extern fn bwrite(bio: *mut BIO, buf: *const c_char, len: c_int) -> c_int { +unsafe extern "C" fn bwrite(bio: *mut BIO, buf: *const c_char, len: c_int) -> c_int { BIO_clear_retry_flags(bio); let state = state::(bio); @@ -98,7 +98,7 @@ unsafe extern fn bwrite(bio: *mut BIO, buf: *const c_char, len: c_int) } } -unsafe extern fn bread(bio: *mut BIO, buf: *mut c_char, len: c_int) -> c_int { +unsafe extern "C" fn bread(bio: *mut BIO, buf: *mut c_char, len: c_int) -> c_int { BIO_clear_retry_flags(bio); let state = state::(bio); @@ -128,15 +128,15 @@ fn retriable_error(err: &io::Error) -> bool { } } -unsafe extern fn bputs(bio: *mut BIO, s: *const c_char) -> c_int { +unsafe extern "C" fn bputs(bio: *mut BIO, s: *const c_char) -> c_int { bwrite::(bio, s, strlen(s) as c_int) } -unsafe extern fn ctrl(bio: *mut BIO, - cmd: c_int, - _num: c_long, - _ptr: *mut c_void) - -> c_long { +unsafe extern "C" fn ctrl(bio: *mut BIO, + cmd: c_int, + _num: c_long, + _ptr: *mut c_void) + -> c_long { if cmd == BIO_CTRL_FLUSH { let state = state::(bio); @@ -156,7 +156,7 @@ unsafe extern fn ctrl(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(bio: *mut BIO) -> c_int { +unsafe extern "C" fn destroy(bio: *mut BIO) -> c_int { if bio.is_null() { return 0; } @@ -193,8 +193,7 @@ mod compat { impl BIO_METHOD { pub fn new() -> 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::) != 0); @@ -203,7 +202,7 @@ mod compat { assert!(ffi::BIO_meth_set_ctrl(ptr, super::ctrl::) != 0); assert!(ffi::BIO_meth_set_create(ptr, super::create) != 0); assert!(ffi::BIO_meth_set_destroy(ptr, super::destroy::) != 0); - return ret + return ret; } } diff --git a/openssl/src/ssl/connector.rs b/openssl/src/ssl/connector.rs index f89acf1e..bea54a4e 100644 --- a/openssl/src/ssl/connector.rs +++ b/openssl/src/ssl/connector.rs @@ -118,7 +118,7 @@ impl ServerConnectorBuilder { { let mut ctx = try!(ctx(method)); ctx.set_options(ssl::SSL_OP_SINGLE_DH_USE | ssl::SSL_OP_SINGLE_ECDH_USE | - ssl::SSL_OP_CIPHER_SERVER_PREFERENCE); + ssl::SSL_OP_CIPHER_SERVER_PREFERENCE); let dh = try!(Dh::from_pem(DHPARAM_PEM.as_bytes())); try!(ctx.set_tmp_dh(&dh)); try!(setup_curves(&mut ctx)); @@ -168,7 +168,7 @@ impl ServerConnectorBuilder { chain: I) -> Result where I: IntoIterator, - I::Item: AsRef + I::Item: AsRef { try!(ctx.set_private_key(private_key)); try!(ctx.set_certificate(certificate)); @@ -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(()) } diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs index 802ce8f0..c1630996 100644 --- a/openssl/src/ssl/mod.rs +++ b/openssl/src/ssl/mod.rs @@ -221,12 +221,12 @@ lazy_static! { static ref ALPN_PROTOS_IDX: c_int = get_new_idx::>(); } -unsafe extern fn free_data_box(_parent: *mut c_void, - ptr: *mut c_void, - _ad: *mut ffi::CRYPTO_EX_DATA, - _idx: c_int, - _argl: c_long, - _argp: *mut c_void) { +unsafe extern "C" fn free_data_box(_parent: *mut c_void, + ptr: *mut c_void, + _ad: *mut ffi::CRYPTO_EX_DATA, + _idx: c_int, + _argl: c_long, + _argp: *mut c_void) { if !ptr.is_null() { Box::::from_raw(ptr as *mut T); } @@ -250,7 +250,7 @@ fn get_new_ssl_idx() -> c_int { } } -extern fn raw_verify(preverify_ok: c_int, x509_ctx: *mut ffi::X509_STORE_CTX) -> c_int +extern "C" fn raw_verify(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(preverify_ok: c_int, x509_ctx: *mut ffi::X509_STORE_CTX) } } -extern fn ssl_raw_verify(preverify_ok: c_int, x509_ctx: *mut ffi::X509_STORE_CTX) -> c_int +extern "C" fn ssl_raw_verify(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::()); + let verify = ffi::SSL_get_ex_data(ssl as *const _, get_ssl_verify_data_idx::()); let verify: &F = &*(verify as *mut F); let ctx = X509StoreContextRef::from_ptr(x509_ctx); @@ -282,7 +281,7 @@ extern fn ssl_raw_verify(preverify_ok: c_int, x509_ctx: *mut ffi::X509_STORE_ } } -extern fn raw_sni(ssl: *mut ffi::SSL, al: *mut c_int, _arg: *mut c_void) -> c_int +extern "C" fn raw_sni(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,24 +337,24 @@ 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, - out: *mut *mut c_uchar, - outlen: *mut c_uchar, - inbuf: *const c_uchar, - inlen: c_uint, - _arg: *mut c_void) - -> c_int { +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, + inlen: c_uint, + _arg: *mut c_void) + -> c_int { unsafe { select_proto_using(ssl, out, outlen, inbuf, inlen, *NPN_PROTOS_IDX) } } #[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))] -extern fn raw_alpn_select_cb(ssl: *mut ffi::SSL, - out: *mut *const c_uchar, - outlen: *mut c_uchar, - inbuf: *const c_uchar, - inlen: c_uint, - _arg: *mut c_void) - -> c_int { +extern "C" fn raw_alpn_select_cb(ssl: *mut ffi::SSL, + out: *mut *const c_uchar, + outlen: *mut c_uchar, + inbuf: *const c_uchar, + inlen: c_uint, + _arg: *mut c_void) + -> c_int { unsafe { select_proto_using(ssl, out as *mut _, outlen, inbuf, inlen, *ALPN_PROTOS_IDX) } } @@ -366,11 +365,11 @@ 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, - out: *mut *const c_uchar, - outlen: *mut c_uint, - _arg: *mut c_void) - -> c_int { +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) + -> c_int { unsafe { // First, get the list of (supported) protocols saved in the context extra data. let ssl_ctx = ffi::SSL_get_SSL_CTX(ssl); @@ -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::(), mem::transmute(verify)); + ffi::SSL_CTX_set_ex_data(self.as_ptr(), + get_verify_data_idx::(), + mem::transmute(verify)); ffi::SSL_CTX_set_verify(self.as_ptr(), mode.bits as c_int, Some(raw_verify::)); } } @@ -475,8 +476,8 @@ impl SslContextBuilder { ffi::SSL_CTX_set_ex_data(self.as_ptr(), get_verify_data_idx::(), mem::transmute(callback)); - let f: extern fn(_, _, _) -> _ = raw_sni::; - let f: extern fn() = mem::transmute(f); + let f: extern "C" fn(_, _, _) -> _ = raw_sni::; + 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>(&mut self, file: P) - -> Result<(), ErrorStack> { + pub fn set_certificate_chain_file>(&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 { - 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 stderror::Error for HandshakeError { 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 fmt::Display for HandshakeError { 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)); @@ -1368,9 +1341,9 @@ impl fmt::Debug for SslStream { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.debug_struct("SslStream") - .field("stream", &self.get_ref()) - .field("ssl", &self.ssl()) - .finish() + .field("stream", &self.get_ref()) + .field("ssl", &self.ssl()) + .finish() } } @@ -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() } } } diff --git a/openssl/src/ssl/tests/mod.rs b/openssl/src/ssl/tests/mod.rs index eeada33a..5e42d5c0 100644 --- a/openssl/src/ssl/tests/mod.rs +++ b/openssl/src/ssl/tests/mod.rs @@ -57,25 +57,29 @@ impl Server { let addr = next_addr(); let mut child = Command::new("openssl") - .arg("s_server") - .arg("-accept") - .arg(addr.port().to_string()) - .args(args) - .arg("-cert") - .arg(&cert) - .arg("-key") - .arg(&key) - .arg("-no_dhe") - .stdout(Stdio::null()) - .stderr(Stdio::null()) - .stdin(Stdio::piped()) - .spawn() - .unwrap(); + .arg("s_server") + .arg("-accept") + .arg(addr.port().to_string()) + .args(args) + .arg("-cert") + .arg(&cert) + .arg("-key") + .arg(&key) + .arg("-no_dhe") + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .stdin(Stdio::piped()) + .spawn() + .unwrap(); let stdin = child.stdin.take().unwrap(); 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) { @@ -111,12 +115,12 @@ impl Server { let mut input = input.into_iter(); let (s, addr) = Server::spawn(&["-dtls1"], Some(Box::new(move |mut io| { - for s in input.by_ref() { - if io.write_all(s.as_bytes()).is_err() { - break; - } - } - }))); + for s in input.by_ref() { + if io.write_all(s.as_bytes()).is_err() { + break; + } + } + }))); // Need to wait for the UDP socket to get bound in our child process, // but don't currently have a great way to do that so just wait for a // bit. @@ -294,10 +298,10 @@ run_test!(verify_trusted_get_error_err, |method, stream| { run_test!(verify_callback_data, |method, stream| { let mut ctx = SslContext::builder(method).unwrap(); - // Node id was generated as SHA256 hash of certificate "test/cert.pem" - // in DER format. - // Command: openssl x509 -in test/cert.pem -outform DER | openssl dgst -sha256 - // Please update if "test/cert.pem" will ever change +// Node id was generated as SHA256 hash of certificate "test/cert.pem" +// in DER format. +// Command: openssl x509 -in test/cert.pem -outform DER | openssl dgst -sha256 +// Please update if "test/cert.pem" will ever change let node_hash_str = "59172d9313e84459bcff27f967e79e6e9217e584"; let node_id = node_hash_str.from_hex().unwrap(); ctx.set_verify_callback(SSL_VERIFY_PEER, move |_preverify_ok, x509_ctx| { @@ -632,7 +636,7 @@ fn test_npn_server_advertise_multiple() { assert!(ctx.set_certificate_file(&Path::new("test/cert.pem"), X509FileType::PEM) .is_ok()); ctx.set_private_key_file(&Path::new("test/key.pem"), X509FileType::PEM) - .unwrap(); + .unwrap(); ctx.build() }; // Have the listener wait on the connection in a different thread. @@ -673,7 +677,7 @@ fn test_alpn_server_advertise_multiple() { assert!(ctx.set_certificate_file(&Path::new("test/cert.pem"), X509FileType::PEM) .is_ok()); ctx.set_private_key_file(&Path::new("test/key.pem"), X509FileType::PEM) - .unwrap(); + .unwrap(); ctx.build() }; // Have the listener wait on the connection in a different thread. @@ -714,7 +718,7 @@ fn test_alpn_server_select_none() { assert!(ctx.set_certificate_file(&Path::new("test/cert.pem"), X509FileType::PEM) .is_ok()); ctx.set_private_key_file(&Path::new("test/key.pem"), X509FileType::PEM) - .unwrap(); + .unwrap(); ctx.build() }; // Have the listener wait on the connection in a different thread. @@ -815,8 +819,7 @@ fn wait_io(stream: &TcpStream, read: bool, timeout_ms: u32) -> bool { } } -fn handshake(res: Result, HandshakeError>) - -> SslStream { +fn handshake(res: Result, HandshakeError>) -> SslStream { 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::) + let connector = ServerConnectorBuilder::mozilla_intermediate(SslMethod::tls(), + &key, + &cert, + None::) .unwrap() .build(); let stream = listener.accept().unwrap().0; @@ -1144,10 +1149,10 @@ 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::) - .unwrap() - .build(); + let connector = + ServerConnectorBuilder::mozilla_modern(SslMethod::tls(), &key, &cert, None::) + .unwrap() + .build(); let stream = listener.accept().unwrap().0; let mut stream = connector.connect(stream).unwrap(); diff --git a/openssl/src/symm.rs b/openssl/src/symm.rs index bffe337a..d4b15f28 100644 --- a/openssl/src/symm.rs +++ b/openssl/src/symm.rs @@ -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 { 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 { + pub fn new(t: Cipher, + mode: Mode, + key: &[u8], + iv: Option<&[u8]>) + -> Result { 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(); diff --git a/openssl/src/util.rs b/openssl/src/util.rs index 68d9b32a..49f38c3d 100644 --- a/openssl/src/util.rs +++ b/openssl/src/util.rs @@ -36,12 +36,13 @@ impl Drop for CallbackState { /// 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(buf: *mut c_char, - size: c_int, - _rwflag: c_int, - cb_state: *mut c_void) - -> c_int - where F: FnOnce(&mut [c_char]) -> usize { +pub unsafe extern "C" fn invoke_passwd_cb(buf: *mut c_char, + size: c_int, + _rwflag: c_int, + cb_state: *mut c_void) + -> c_int + where F: FnOnce(&mut [c_char]) -> usize +{ let callback = &mut *(cb_state as *mut CallbackState); let result = panic::catch_unwind(AssertUnwindSafe(|| { diff --git a/openssl/src/version.rs b/openssl/src/version.rs index 245305e8..d7db39a7 100644 --- a/openssl/src/version.rs +++ b/openssl/src/version.rs @@ -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}; diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs index b7cbe363..b49a9848 100644 --- a/openssl/src/x509/mod.rs +++ b/openssl/src/x509/mod.rs @@ -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 { - 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)); } } diff --git a/openssl/src/x509/tests.rs b/openssl/src/x509/tests.rs index 185c4910..1c248ba2 100644 --- a/openssl/src/x509/tests.rs +++ b/openssl/src/x509/tests.rs @@ -60,10 +60,9 @@ 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::SUBJECT_KEY_IDENTIFIER, "hash".to_owned())) - .sign(&pkey); + .add_extension(OtherNid(nid::AUTHORITY_KEY_IDENTIFIER, "keyid:always".to_owned())) + .add_extension(OtherNid(nid::SUBJECT_KEY_IDENTIFIER, "hash".to_owned())) + .sign(&pkey); assert!(result.is_err()); }