Commit bcd0dcaf authored by Steven Fackler's avatar Steven Fackler
Browse files

Rustfmt

parent 5c2410c3
Loading
Loading
Loading
Loading
+81 −58
Original line number Diff line number Diff line
@@ -11,7 +11,8 @@ use std::panic::{self, AssertUnwindSafe};
use std::process::Command;

// The set of `OPENSSL_NO_<FOO>`s that we care about.
const DEFINES: &'static [&'static str] = &["OPENSSL_NO_BUF_FREELISTS",
const DEFINES: &'static [&'static str] = &[
    "OPENSSL_NO_BUF_FREELISTS",
    "OPENSSL_NO_COMP",
    "OPENSSL_NO_EC",
    "OPENSSL_NO_EC2M",
@@ -23,7 +24,8 @@ const DEFINES: &'static [&'static str] = &["OPENSSL_NO_BUF_FREELISTS",
    "OPENSSL_NO_SHA",
    "OPENSSL_NO_SRP",
    "OPENSSL_NO_SSL3_METHOD",
                                           "OPENSSL_NO_TLSEXT"];
    "OPENSSL_NO_TLSEXT",
];

enum Version {
    Openssl110,
@@ -52,16 +54,22 @@ fn main() {
    };

    if !Path::new(&lib_dir).exists() {
        panic!("OpenSSL library directory does not exist: {}",
               lib_dir.to_string_lossy());
        panic!(
            "OpenSSL library directory does not exist: {}",
            lib_dir.to_string_lossy()
        );
    }
    if !Path::new(&include_dir).exists() {
        panic!("OpenSSL include directory does not exist: {}",
               include_dir.to_string_lossy());
        panic!(
            "OpenSSL include directory does not exist: {}",
            include_dir.to_string_lossy()
        );
    }

    println!("cargo:rustc-link-search=native={}",
             lib_dir.to_string_lossy());
    println!(
        "cargo:rustc-link-search=native={}",
        lib_dir.to_string_lossy()
    );
    println!("cargo:include={}", include_dir.to_string_lossy());

    let version = validate_headers(&[include_dir.clone().into()]);
@@ -103,7 +111,8 @@ fn find_openssl_dir(target: &str) -> OsString {

    try_pkg_config();

    let mut msg = format!("
    let mut msg = format!(
        "

Could not find directory of OpenSSL installation, and this `-sys` crate cannot
proceed without this knowledge. If OpenSSL is installed and this crate had
@@ -121,12 +130,14 @@ and include information about your system as well as this message.
",
        host,
        target,
                          env!("CARGO_PKG_VERSION"));
        env!("CARGO_PKG_VERSION")
    );

    if host.contains("apple-darwin") && target.contains("apple-darwin") {
        let system = Path::new("/usr/lib/libssl.0.9.8.dylib");
        if system.exists() {
            msg.push_str(&format!("
            msg.push_str(&format!(
                "

It looks like you're compiling on macOS, where the system contains a version of
OpenSSL 0.9.8. This crate no longer supports OpenSSL 0.9.8.
@@ -137,24 +148,28 @@ install the `openssl` package, or as a maintainer you can use the openssl-sys

Unfortunately though the compile cannot continue, so aborting.

"));
"
            ));
        }
    }

    if host.contains("unknown-linux") && target.contains("unknown-linux-gnu") {
        if Command::new("pkg-config").output().is_err() {
            msg.push_str(&format!("
            msg.push_str(&format!(
                "
It looks like you're compiling on Linux and also targeting Linux. Currently this
requires the `pkg-config` utility to find OpenSSL but unfortunately `pkg-config`
could not be found. If you have OpenSSL installed you can likely fix this by
installing `pkg-config`.

"));
"
            ));
        }
    }

    if host.contains("windows") && target.contains("windows-gnu") {
        msg.push_str(&format!("
        msg.push_str(&format!(
            "
It looks like you're compiling for MinGW but you may not have either OpenSSL or
pkg-config installed. You can install these two dependencies with:

@@ -162,11 +177,13 @@ pkg-config installed. You can install these two dependencies with:

and try building this crate again.

"));
"
        ));
    }

    if host.contains("windows") && target.contains("windows-msvc") {
        msg.push_str(&format!("
        msg.push_str(&format!(
            "
It looks like you're compiling for MSVC but we couldn't detect an OpenSSL
installation. If there isn't one installed then you can try the rust-openssl
README for more information about how to download precompiled binaries of
@@ -174,7 +191,8 @@ OpenSSL:

    https://github.com/sfackler/rust-openssl#windows

"));
"
        ));
    }

    panic!(msg);
@@ -198,9 +216,9 @@ fn try_pkg_config() {
        return;
    }

    let lib = match pkg_config::Config::new()
              .print_system_libs(false)
              .find("openssl") {
    let lib = match pkg_config::Config::new().print_system_libs(false).find(
        "openssl",
    ) {
        Ok(lib) => lib,
        Err(e) => {
            println!("run pkg_config fail: {:?}", e);
@@ -236,7 +254,8 @@ fn validate_headers(include_dirs: &[PathBuf]) -> Version {
    path.push("expando.c");
    let mut file = BufWriter::new(File::create(&path).unwrap());

    write!(file,
    write!(
        file,
        "\
#include <openssl/opensslv.h>
#include <openssl/opensslconf.h>
@@ -270,18 +289,19 @@ RUST_OPENSSL_101
#else
RUST_OPENSSL_OLD
#endif
")
            .unwrap();
"
    ).unwrap();

    for define in DEFINES {
        write!(file,
        write!(
            file,
            "\
#ifdef {define}
RUST_{define}
#endif
",
               define = define)
                .unwrap();
            define = define
        ).unwrap();
    }

    file.flush().unwrap();
@@ -295,7 +315,8 @@ RUST_{define}
    let expanded = match panic::catch_unwind(AssertUnwindSafe(|| gcc.file(&path).expand())) {
        Ok(expanded) => expanded,
        Err(_) => {
            panic!("
            panic!(
                "
Failed to find OpenSSL development headers.

You can try fixing this setting the `OPENSSL_DIR` environment variable
@@ -312,7 +333,8 @@ specific to your distribution:
See rust-openssl README for more information:

    https://github.com/sfackler/rust-openssl#linux
");
"
            );
        }
    };
    let expanded = String::from_utf8(expanded).unwrap();
@@ -381,13 +403,15 @@ See rust-openssl README for more information:
        println!("cargo:version=101");
        Version::Openssl101
    } else {
        panic!("
        panic!(
            "

This crate is only compatible with OpenSSL 1.0.1, 1.0.2, and 1.1.0, or LibreSSL
2.5.0, 2.5.1, 2.5.2, 2.5.3, and 2.5.4, but a different version of OpenSSL was
found. The build is now aborting due to this version mismatch.

");
"
        );
    }
}

@@ -413,13 +437,10 @@ fn determine_mode(libdir: &Path, libs: &[&str]) -> &'static str {
        .map(|e| e.file_name())
        .filter_map(|e| e.into_string().ok())
        .collect::<HashSet<_>>();
    let can_static =
        libs.iter()
            .all(|l| {
    let can_static = libs.iter().all(|l| {
        files.contains(&format!("lib{}.a", l)) || files.contains(&format!("{}.lib", l))
    });
    let can_dylib = libs.iter()
        .all(|l| {
    let can_dylib = libs.iter().all(|l| {
        files.contains(&format!("lib{}.so", l)) || files.contains(&format!("{}.dll", l)) ||
            files.contains(&format!("lib{}.dylib", l))
    });
@@ -427,9 +448,11 @@ fn determine_mode(libdir: &Path, libs: &[&str]) -> &'static str {
        (true, false) => return "static",
        (false, true) => return "dylib",
        (false, false) => {
            panic!("OpenSSL libdir at `{}` does not contain the required files \
            panic!(
                "OpenSSL libdir at `{}` does not contain the required files \
                    to either statically or dynamically link OpenSSL",
                   libdir.display());
                libdir.display()
            );
        }
        (true, true) => {}
    }
+742 −624

File changed.

Preview size limit exceeded, changes collapsed.

+141 −123
Original line number Diff line number Diff line
@@ -148,13 +148,15 @@ pub struct EVP_PKEY {
#[repr(C)]
pub struct BIO {
    pub method: *mut ::BIO_METHOD,
    pub callback: Option<unsafe extern "C" fn(*mut ::BIO,
    pub callback: Option<
        unsafe extern "C" fn(*mut ::BIO,
                             c_int,
                             *const c_char,
                             c_int,
                             c_long,
                             c_long)
                                              -> c_long>,
                             -> c_long,
    >,
    pub cb_arg: *mut c_char,
    pub init: c_int,
    pub shutdown: c_int,
@@ -192,23 +194,28 @@ pub struct EVP_CIPHER {
    pub key_len: c_int,
    pub iv_len: c_int,
    pub flags: c_ulong,
    pub init: Option<unsafe extern "C" fn(*mut ::EVP_CIPHER_CTX,
    pub init: Option<
        unsafe extern "C" fn(*mut ::EVP_CIPHER_CTX,
                             *const c_uchar,
                             *const c_uchar,
                             c_int)
                                          -> c_int>,
    pub do_cipher: Option<unsafe extern "C" fn(*mut ::EVP_CIPHER_CTX,
                             -> c_int,
    >,
    pub do_cipher: Option<
        unsafe extern "C" fn(*mut ::EVP_CIPHER_CTX,
                             *mut c_uchar,
                             *const c_uchar,
                             size_t)
                                               -> c_int>,
                             -> c_int,
    >,
    pub cleanup: Option<unsafe extern "C" fn(*mut ::EVP_CIPHER_CTX) -> c_int>,
    pub ctx_size: c_int,
    pub set_asn1_parameters:
        Option<unsafe extern "C" fn(*mut ::EVP_CIPHER_CTX, *mut ::ASN1_TYPE) -> c_int>,
    pub get_asn1_parameters:
        Option<unsafe extern "C" fn(*mut ::EVP_CIPHER_CTX, *mut ::ASN1_TYPE) -> c_int>,
    pub ctrl: Option<unsafe extern "C" fn(*mut ::EVP_CIPHER_CTX, c_int, c_int, *mut c_void) -> c_int>,
    pub ctrl:
        Option<unsafe extern "C" fn(*mut ::EVP_CIPHER_CTX, c_int, c_int, *mut c_void) -> c_int>,
    pub app_data: *mut c_void,
}

@@ -369,8 +376,8 @@ pub const CRYPTO_LOCK_SSL_CTX: c_int = 12;
pub const CRYPTO_LOCK_SSL_SESSION: c_int = 14;

static mut MUTEXES: *mut Vec<Mutex<()>> = 0 as *mut Vec<Mutex<()>>;
static mut GUARDS: *mut Vec<Option<MutexGuard<'static, ()>>> =
    0 as *mut Vec<Option<MutexGuard<'static, ()>>>;
static mut GUARDS: *mut Vec<Option<MutexGuard<'static, ()>>> = 0 as
    *mut Vec<Option<MutexGuard<'static, ()>>>;

unsafe extern "C" fn locking_function(mode: c_int, n: c_int, _file: *const c_char, _line: c_int) {
    let mutex = &(*MUTEXES)[n as usize];
@@ -378,9 +385,7 @@ unsafe extern "C" fn locking_function(mode: c_int, n: c_int, _file: *const c_cha
    if mode & ::CRYPTO_LOCK != 0 {
        (*GUARDS)[n as usize] = Some(mutex.lock().unwrap());
    } else {
        &(*GUARDS)[n as usize]
             .take()
             .expect("lock already unlocked");
        &(*GUARDS)[n as usize].take().expect("lock already unlocked");
    }
}

@@ -424,17 +429,21 @@ fn set_id_callback() {}
// macros

pub unsafe fn SSL_CTX_set_ecdh_auto(ctx: *mut SSL_CTX, onoff: c_int) -> c_int {
    ::SSL_CTX_ctrl(ctx,
    ::SSL_CTX_ctrl(
        ctx,
        SSL_CTRL_SET_ECDH_AUTO,
        onoff as c_long,
                   ptr::null_mut()) as c_int
        ptr::null_mut(),
    ) as c_int
}

pub unsafe fn SSL_set_ecdh_auto(ssl: *mut ::SSL, onoff: c_int) -> c_int {
    ::SSL_ctrl(ssl,
    ::SSL_ctrl(
        ssl,
        SSL_CTRL_SET_ECDH_AUTO,
        onoff as c_long,
               ptr::null_mut()) as c_int
        ptr::null_mut(),
    ) as c_int
}

pub unsafe fn SSL_session_reused(ssl: *mut ::SSL) -> c_int {
@@ -458,26 +467,28 @@ extern "C" {
    pub fn CRYPTO_malloc(num: c_int, file: *const c_char, line: c_int) -> *mut c_void;
    pub fn CRYPTO_free(buf: *mut c_void);
    pub fn CRYPTO_num_locks() -> c_int;
    pub fn CRYPTO_set_locking_callback(func: unsafe extern "C" fn(mode: c_int,
                                                                  n: c_int,
                                                                  file: *const c_char,
                                                                  line: c_int));
    pub fn CRYPTO_set_locking_callback(
        func: unsafe extern "C" fn(mode: c_int, n: c_int, file: *const c_char, line: c_int),
    );
    pub fn CRYPTO_set_id_callback(func: unsafe extern "C" fn() -> c_ulong);

    pub fn ERR_load_crypto_strings();

    pub fn RSA_generate_key(modsz: c_int,
    pub fn RSA_generate_key(
        modsz: c_int,
        e: c_ulong,
        cb: Option<extern "C" fn(c_int, c_int, *mut c_void)>,
                            cbarg: *mut c_void)
                            -> *mut RSA;
        cbarg: *mut c_void,
    ) -> *mut RSA;

    pub fn OCSP_cert_to_id(dgst: *const ::EVP_MD,
    pub fn OCSP_cert_to_id(
        dgst: *const ::EVP_MD,
        subject: *mut ::X509,
                           issuer: *mut ::X509)
                           -> *mut ::OCSP_CERTID;
        issuer: *mut ::X509,
    ) -> *mut ::OCSP_CERTID;

    pub fn PKCS12_create(pass: *mut c_char,
    pub fn PKCS12_create(
        pass: *mut c_char,
        friendly_name: *mut c_char,
        pkey: *mut EVP_PKEY,
        cert: *mut X509,
@@ -486,8 +497,8 @@ extern "C" {
        nid_cert: c_int,
        iter: c_int,
        mac_iter: c_int,
                         keytype: c_int)
                         -> *mut PKCS12;
        keytype: c_int,
    ) -> *mut PKCS12;

    pub fn SSL_library_init() -> c_int;
    pub fn SSL_load_error_strings();
@@ -499,66 +510,73 @@ extern "C" {
    pub fn TLSv1_1_method() -> *const ::SSL_METHOD;
    pub fn TLSv1_2_method() -> *const ::SSL_METHOD;
    pub fn DTLSv1_method() -> *const ::SSL_METHOD;
    pub fn SSL_get_ex_new_index(argl: c_long,
    pub fn SSL_get_ex_new_index(
        argl: c_long,
        argp: *mut c_void,
        new_func: Option<::CRYPTO_EX_new>,
        dup_func: Option<::CRYPTO_EX_dup>,
                                free_func: Option<::CRYPTO_EX_free>)
                                -> c_int;
    pub fn SSL_set_tmp_ecdh_callback(ssl: *mut ::SSL,
                                     ecdh: unsafe extern "C" fn(ssl: *mut ::SSL,
                                                                is_export: c_int,
                                                                keylength: c_int)
                                                                -> *mut ::EC_KEY);
        free_func: Option<::CRYPTO_EX_free>,
    ) -> c_int;
    pub fn SSL_set_tmp_ecdh_callback(
        ssl: *mut ::SSL,
        ecdh: unsafe extern "C" fn(ssl: *mut ::SSL, is_export: c_int, keylength: c_int)
                                   -> *mut ::EC_KEY,
    );
    pub fn SSL_CIPHER_get_version(cipher: *const ::SSL_CIPHER) -> *mut c_char;
    pub fn SSL_CTX_get_ex_new_index(argl: c_long,
    pub fn SSL_CTX_get_ex_new_index(
        argl: c_long,
        argp: *mut c_void,
        new_func: Option<::CRYPTO_EX_new>,
        dup_func: Option<::CRYPTO_EX_dup>,
                                    free_func: Option<::CRYPTO_EX_free>)
                                    -> c_int;
    pub fn SSL_CTX_set_tmp_ecdh_callback(ctx: *mut ::SSL_CTX,
                                         ecdh: unsafe extern "C" fn(ssl: *mut ::SSL,
                                                                    is_export: c_int,
                                                                    keylength: c_int)
                                                                    -> *mut ::EC_KEY);
        free_func: Option<::CRYPTO_EX_free>,
    ) -> c_int;
    pub fn SSL_CTX_set_tmp_ecdh_callback(
        ctx: *mut ::SSL_CTX,
        ecdh: unsafe extern "C" fn(ssl: *mut ::SSL, is_export: c_int, keylength: c_int)
                                   -> *mut ::EC_KEY,
    );
    pub fn X509_get_subject_name(x: *mut ::X509) -> *mut ::X509_NAME;
    pub fn X509_set_notAfter(x: *mut ::X509, tm: *const ::ASN1_TIME) -> c_int;
    pub fn X509_set_notBefore(x: *mut ::X509, tm: *const ::ASN1_TIME) -> c_int;
    pub fn X509_get_ext_d2i(x: *mut ::X509,
    pub fn X509_get_ext_d2i(
        x: *mut ::X509,
        nid: c_int,
        crit: *mut c_int,
                            idx: *mut c_int)
                            -> *mut c_void;
    pub fn X509_NAME_add_entry_by_NID(x: *mut ::X509_NAME,
        idx: *mut c_int,
    ) -> *mut c_void;
    pub fn X509_NAME_add_entry_by_NID(
        x: *mut ::X509_NAME,
        field: c_int,
        ty: c_int,
        bytes: *mut c_uchar,
        len: c_int,
        loc: c_int,
                                      set: c_int)
                                      -> c_int;
        set: c_int,
    ) -> c_int;
    pub fn X509_NAME_get_entry(n: *mut ::X509_NAME, loc: c_int) -> *mut ::X509_NAME_ENTRY;
    pub fn X509_NAME_ENTRY_get_data(ne: *mut ::X509_NAME_ENTRY) -> *mut ::ASN1_STRING;
    pub fn X509_STORE_CTX_get_chain(ctx: *mut ::X509_STORE_CTX) -> *mut stack_st_X509;
    pub fn X509V3_EXT_nconf_nid(conf: *mut ::CONF,
    pub fn X509V3_EXT_nconf_nid(
        conf: *mut ::CONF,
        ctx: *mut ::X509V3_CTX,
        ext_nid: c_int,
                                value: *mut c_char)
                                -> *mut ::X509_EXTENSION;
    pub fn X509V3_EXT_nconf(conf: *mut ::CONF,
        value: *mut c_char,
    ) -> *mut ::X509_EXTENSION;
    pub fn X509V3_EXT_nconf(
        conf: *mut ::CONF,
        ctx: *mut ::X509V3_CTX,
        name: *mut c_char,
                            value: *mut c_char)
                            -> *mut ::X509_EXTENSION;
        value: *mut c_char,
    ) -> *mut ::X509_EXTENSION;
    pub fn ASN1_STRING_to_UTF8(out: *mut *mut c_uchar, s: *mut ::ASN1_STRING) -> c_int;
    pub fn ASN1_STRING_data(x: *mut ::ASN1_STRING) -> *mut c_uchar;
    pub fn CRYPTO_add_lock(pointer: *mut c_int,
    pub fn CRYPTO_add_lock(
        pointer: *mut c_int,
        amount: c_int,
        type_: c_int,
        file: *const c_char,
                           line: c_int)
                           -> c_int;
        line: c_int,
    ) -> c_int;
    pub fn EVP_MD_CTX_create() -> *mut EVP_MD_CTX;
    pub fn EVP_MD_CTX_destroy(ctx: *mut EVP_MD_CTX);
    pub fn EVP_PKEY_bits(key: *mut EVP_PKEY) -> c_int;
+9 −7
Original line number Diff line number Diff line
@@ -28,13 +28,15 @@ pub struct SSL {
    s3: *mut c_void,
    d1: *mut c_void,
    read_ahead: c_int,
    msg_callback: Option<unsafe extern "C" fn(c_int,
    msg_callback: Option<
        unsafe extern "C" fn(c_int,
                             c_int,
                             c_int,
                             *const c_void,
                             size_t,
                             *mut SSL,
                                              *mut c_void)>,
                             *mut c_void),
    >,
    msg_callback_arg: *mut c_void,
    hit: c_int,
    param: *mut c_void,
+170 −144

File changed.

Preview size limit exceeded, changes collapsed.

Loading