Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tempfile be a macos-only dependency #295

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ alpn = ["security-framework/alpn"]
security-framework = "2.0.0"
security-framework-sys = "2.0.0"
libc = "0.2"

[target.'cfg(target_os = "macos")'.dependencies]
tempfile = "3.1.0"

[target.'cfg(target_os = "windows")'.dependencies]
Expand Down
9 changes: 4 additions & 5 deletions src/imp/security_framework.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
extern crate libc;
extern crate security_framework;
extern crate security_framework_sys;
extern crate tempfile;

use self::security_framework::base;
use self::security_framework::certificate::SecCertificate;
Expand All @@ -12,7 +11,6 @@ use self::security_framework::secure_transport::{
self, ClientBuilder, SslConnectionType, SslContext, SslProtocol, SslProtocolSide,
};
use self::security_framework_sys::base::{errSecIO, errSecParam};
use self::tempfile::TempDir;
use std::error;
use std::fmt;
use std::io;
Expand All @@ -38,7 +36,7 @@ use {Protocol, TlsAcceptorBuilder, TlsConnectorBuilder};
static SET_AT_EXIT: Once = Once::new();

#[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))]
static TEMP_KEYCHAIN: Mutex<Option<(SecKeychain, TempDir)>> = Mutex::new(None);
static TEMP_KEYCHAIN: Mutex<Option<(SecKeychain, tempfile::TempDir)>> = Mutex::new(None);

fn convert_protocol(protocol: Protocol) -> SslProtocol {
match protocol {
Expand Down Expand Up @@ -93,7 +91,7 @@ impl Identity {
return Err(Error(base::Error::from(errSecParam)));
}

let dir = TempDir::new().map_err(|_| Error(base::Error::from(errSecIO)))?;
let dir = tempfile::TempDir::new().map_err(|_| Error(base::Error::from(errSecIO)))?;
let keychain = keychain::CreateOptions::new()
.password(&random_password()?)
.create(dir.path().join("identity.keychain"))?;
Expand Down Expand Up @@ -159,7 +157,8 @@ impl Identity {
let keychain = match *TEMP_KEYCHAIN.lock().unwrap() {
Some((ref keychain, _)) => keychain.clone(),
ref mut lock @ None => {
let dir = TempDir::new().map_err(|_| Error(base::Error::from(errSecIO)))?;
let dir =
tempfile::TempDir::new().map_err(|_| Error(base::Error::from(errSecIO)))?;

let mut keychain = keychain::CreateOptions::new()
.password(pass)
Expand Down
Loading