Skip to content

Commit

Permalink
Merge pull request #295 from simlay/make-tempfile-be-a-macos-specific…
Browse files Browse the repository at this point in the history
…-dependency

Make tempfile be a macos-only dependency
  • Loading branch information
sfackler authored May 25, 2024
2 parents 0b69ce6 + 3018442 commit 6ba3cf1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
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

0 comments on commit 6ba3cf1

Please sign in to comment.