From 3018442f15d74c28b29317d0c670a2a693c937d7 Mon Sep 17 00:00:00 2001 From: Sebastian Imlay Date: Tue, 7 May 2024 15:23:21 -0400 Subject: [PATCH] Make tempfile be a macos-only dependency --- Cargo.toml | 2 ++ src/imp/security_framework.rs | 9 ++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8960942..15b013d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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] diff --git a/src/imp/security_framework.rs b/src/imp/security_framework.rs index 63232b7..1f704bc 100644 --- a/src/imp/security_framework.rs +++ b/src/imp/security_framework.rs @@ -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; @@ -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; @@ -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> = Mutex::new(None); +static TEMP_KEYCHAIN: Mutex> = Mutex::new(None); fn convert_protocol(protocol: Protocol) -> SslProtocol { match protocol { @@ -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"))?; @@ -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)