Flatten crypto module

This commit is contained in:
Steven Fackler 2016-10-22 09:16:38 -07:00
parent 58f6d1138a
commit 98b7f2f935
17 changed files with 57 additions and 75 deletions

View File

@ -1,28 +0,0 @@
// Copyright 2011 Google Inc.
// 2013 Jack Lloyd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
mod util;
pub mod dsa;
pub mod hash;
pub mod memcmp;
pub mod pkcs12;
pub mod pkcs5;
pub mod pkey;
pub mod rand;
pub mod rsa;
pub mod sign;
pub mod symm;

View File

@ -7,7 +7,7 @@ use libc::{c_int, c_char, c_void};
use {cvt, cvt_p};
use bn::BigNumRef;
use bio::{MemBio, MemBioSlice};
use crypto::util::{CallbackState, invoke_passwd_cb};
use util::{CallbackState, invoke_passwd_cb};
/// Builder for upfront DSA parameter generation
pub struct DSAParams(*mut ffi::DSA);
@ -248,7 +248,7 @@ mod test {
#[test]
pub fn test_password() {
let mut password_queried = false;
let key = include_bytes!("../../test/dsa-encrypted.pem");
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;

View File

@ -22,17 +22,27 @@ use error::ErrorStack;
mod macros;
pub mod asn1;
mod bio;
mod opaque;
mod util;
pub mod asn1;
pub mod bn;
pub mod crypto;
pub mod dh;
pub mod dsa;
pub mod error;
pub mod hash;
pub mod memcmp;
pub mod nid;
pub mod pkcs12;
pub mod pkcs5;
pub mod pkey;
pub mod rand;
pub mod rsa;
pub mod sign;
pub mod ssl;
pub mod symm;
pub mod version;
pub mod x509;
mod opaque;
pub fn cvt_p<T>(r: *mut T) -> Result<*mut T, ErrorStack> {
if r.is_null() {

View File

@ -7,7 +7,7 @@ use std::ptr;
use std::ffi::CString;
use {cvt, cvt_p};
use crypto::pkey::PKey;
use pkey::PKey;
use error::ErrorStack;
use x509::X509;
@ -98,14 +98,14 @@ mod compat {
#[cfg(test)]
mod test {
use crypto::hash::MessageDigest;
use hash::MessageDigest;
use serialize::hex::ToHex;
use super::*;
#[test]
fn parse() {
let der = include_bytes!("../../test/identity.p12");
let der = include_bytes!("../test/identity.p12");
let pkcs12 = Pkcs12::from_der(der).unwrap();
let parsed = pkcs12.parse("mypass").unwrap();

View File

@ -3,8 +3,8 @@ use std::ptr;
use ffi;
use cvt;
use crypto::hash::MessageDigest;
use crypto::symm::Cipher;
use hash::MessageDigest;
use symm::Cipher;
use error::ErrorStack;
#[derive(Clone, Eq, PartialEq, Hash, Debug)]
@ -98,8 +98,8 @@ pub fn pbkdf2_hmac(pass: &[u8],
#[cfg(test)]
mod tests {
use crypto::hash::MessageDigest;
use crypto::symm::Cipher;
use hash::MessageDigest;
use symm::Cipher;
// Test vectors from
// https://git.lysator.liu.se/nettle/nettle/blob/nettle_3.1.1_release_20150424/testsuite/pbkdf2-test.c

View File

@ -5,10 +5,10 @@ use ffi;
use {cvt, cvt_p};
use bio::{MemBio, MemBioSlice};
use crypto::dsa::DSA;
use crypto::rsa::RSA;
use dsa::DSA;
use rsa::RSA;
use error::ErrorStack;
use crypto::util::{CallbackState, invoke_passwd_cb};
use util::{CallbackState, invoke_passwd_cb};
pub struct PKey(*mut ffi::EVP_PKEY);
@ -167,19 +167,19 @@ impl Drop for PKey {
mod tests {
#[test]
fn test_private_key_from_pem() {
let key = include_bytes!("../../test/key.pem");
let key = include_bytes!("../test/key.pem");
super::PKey::private_key_from_pem(key).unwrap();
}
#[test]
fn test_public_key_from_pem() {
let key = include_bytes!("../../test/key.pem.pub");
let key = include_bytes!("../test/key.pem.pub");
super::PKey::public_key_from_pem(key).unwrap();
}
#[test]
fn test_pem() {
let key = include_bytes!("../../test/key.pem");
let key = include_bytes!("../test/key.pem");
let key = super::PKey::private_key_from_pem(key).unwrap();
let priv_key = key.private_key_to_pem().unwrap();

View File

@ -8,7 +8,7 @@ use {cvt, cvt_p, cvt_n};
use bn::{BigNum, BigNumRef};
use bio::{MemBio, MemBioSlice};
use error::ErrorStack;
use crypto::util::{CallbackState, invoke_passwd_cb};
use util::{CallbackState, invoke_passwd_cb};
/// Type of encryption padding to use.
#[derive(Copy, Clone)]
@ -421,7 +421,7 @@ mod test {
#[test]
pub fn test_password() {
let mut password_queried = false;
let key = include_bytes!("../../test/rsa-encrypted.pem");
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;
@ -438,7 +438,7 @@ mod test {
#[test]
pub fn test_public_encrypt_private_decrypt_with_padding() {
let key = include_bytes!("../../test/rsa.pem.pub");
let key = include_bytes!("../test/rsa.pem.pub");
let public_key = RSA::public_key_from_pem(key).unwrap();
let mut result = vec![0; public_key.size()];
@ -446,7 +446,7 @@ mod test {
let len = public_key.public_encrypt(original_data, &mut result, Padding::pkcs1()).unwrap();
assert_eq!(len, 256);
let pkey = include_bytes!("../../test/rsa.pem");
let pkey = include_bytes!("../test/rsa.pem");
let private_key = RSA::private_key_from_pem(pkey).unwrap();
let mut dec_result = vec![0; private_key.size()];
let len = private_key.private_decrypt(&result, &mut dec_result, Padding::pkcs1()).unwrap();

View File

@ -60,8 +60,8 @@ use std::marker::PhantomData;
use std::ptr;
use {cvt, cvt_p};
use crypto::hash::MessageDigest;
use crypto::pkey::PKey;
use hash::MessageDigest;
use pkey::PKey;
use error::ErrorStack;
#[cfg(ossl110)]
@ -208,11 +208,11 @@ mod test {
use serialize::hex::FromHex;
use std::iter;
use crypto::hash::MessageDigest;
use crypto::sign::{Signer, Verifier};
use crypto::rsa::RSA;
use crypto::dsa::DSA;
use crypto::pkey::PKey;
use hash::MessageDigest;
use sign::{Signer, Verifier};
use rsa::RSA;
use dsa::DSA;
use pkey::PKey;
static INPUT: &'static [u8] =
&[101, 121, 74, 104, 98, 71, 99, 105, 79, 105, 74, 83, 85, 122, 73, 49, 78, 105, 74, 57,
@ -240,7 +240,7 @@ mod test {
#[test]
fn rsa_sign() {
let key = include_bytes!("../../test/rsa.pem");
let key = include_bytes!("../test/rsa.pem");
let private_key = RSA::private_key_from_pem(key).unwrap();
let pkey = PKey::from_rsa(private_key).unwrap();
@ -253,7 +253,7 @@ mod test {
#[test]
fn rsa_verify_ok() {
let key = include_bytes!("../../test/rsa.pem");
let key = include_bytes!("../test/rsa.pem");
let private_key = RSA::private_key_from_pem(key).unwrap();
let pkey = PKey::from_rsa(private_key).unwrap();
@ -264,7 +264,7 @@ mod test {
#[test]
fn rsa_verify_invalid() {
let key = include_bytes!("../../test/rsa.pem");
let key = include_bytes!("../test/rsa.pem");
let private_key = RSA::private_key_from_pem(key).unwrap();
let pkey = PKey::from_rsa(private_key).unwrap();
@ -279,12 +279,12 @@ mod test {
let input: Vec<u8> = (0..25).cycle().take(1024).collect();
let private_key = {
let key = include_bytes!("../../test/dsa.pem");
let key = include_bytes!("../test/dsa.pem");
PKey::from_dsa(DSA::private_key_from_pem(key).unwrap()).unwrap()
};
let public_key = {
let key = include_bytes!("../../test/dsa.pem.pub");
let key = include_bytes!("../test/dsa.pem.pub");
PKey::from_dsa(DSA::public_key_from_pem(key).unwrap()).unwrap()
};
@ -302,12 +302,12 @@ mod test {
let input: Vec<u8> = (0..25).cycle().take(1024).collect();
let private_key = {
let key = include_bytes!("../../test/dsa.pem");
let key = include_bytes!("../test/dsa.pem");
PKey::from_dsa(DSA::private_key_from_pem(key).unwrap()).unwrap()
};
let public_key = {
let key = include_bytes!("../../test/dsa.pem.pub");
let key = include_bytes!("../test/dsa.pem.pub");
PKey::from_dsa(DSA::public_key_from_pem(key).unwrap()).unwrap()
};

View File

@ -24,7 +24,7 @@ use dh::DH;
use x509::{X509StoreContextRef, X509FileType, X509, X509Ref, X509VerifyError};
#[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))]
use x509::verify::X509VerifyParamRef;
use crypto::pkey::PKey;
use pkey::PKey;
use error::ErrorStack;
use opaque::Opaque;

View File

@ -14,7 +14,7 @@ use std::time::Duration;
use tempdir::TempDir;
use crypto::hash::MessageDigest;
use hash::MessageDigest;
use ssl;
use ssl::SSL_VERIFY_PEER;
use ssl::{SslMethod, HandshakeError};
@ -25,7 +25,7 @@ use x509::X509FileType;
use x509::X509;
#[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))]
use x509::verify::X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS;
use crypto::pkey::PKey;
use pkey::PKey;
use std::net::UdpSocket;
@ -167,7 +167,7 @@ macro_rules! run_test(
use ssl::SslMethod;
use ssl::{SslContext, Ssl, SslStream};
use ssl::SSL_VERIFY_PEER;
use crypto::hash::MessageDigest;
use hash::MessageDigest;
use x509::X509StoreContextRef;
use serialize::hex::FromHex;
use super::Server;
@ -774,7 +774,7 @@ mod dtlsv1 {
use std::net::TcpStream;
use std::thread;
use crypto::hash::MessageDigest;
use hash::MessageDigest;
use ssl::SslMethod;
use ssl::{SslContext, SslStream};
use ssl::SSL_VERIFY_PEER;

View File

@ -15,9 +15,9 @@ use {cvt, cvt_p};
use asn1::Asn1Time;
use asn1::Asn1TimeRef;
use bio::{MemBio, MemBioSlice};
use crypto::hash::MessageDigest;
use crypto::pkey::PKey;
use crypto::rand::rand_bytes;
use hash::MessageDigest;
use pkey::PKey;
use rand::rand_bytes;
use error::ErrorStack;
use ffi;
use nid::Nid;

View File

@ -1,8 +1,8 @@
use serialize::hex::FromHex;
use crypto::hash::MessageDigest;
use crypto::pkey::PKey;
use crypto::rsa::RSA;
use hash::MessageDigest;
use pkey::PKey;
use rsa::RSA;
use x509::{X509, X509Generator};
use x509::extension::Extension::{KeyUsage, ExtKeyUsage, SubjectAltName, OtherNid, OtherStr};
use x509::extension::AltNameOption as SAN;