From ac3573bf98b3ed8be2c8272ac5d448d5e44f352b Mon Sep 17 00:00:00 2001 From: Joseph Birr-Pixton Date: Sat, 20 Jun 2020 12:59:20 +0100 Subject: [PATCH] Remove dependency on tempfile This broke the MSRV build, and was bringing in the whole of rand, wasi, and a ton of other stuff. All so we could have a temporary directory during a few tests. 6 crates for generating randomness just for that! This accounted for 10% of the size of Cargo.lock alone. --- rustls-mio/Cargo.toml | 2 +- rustls-mio/tests/common/mod.rs | 44 ++++++++++++++++++++++++++++------ rustls/Cargo.toml | 1 - rustls/tests/common/mod.rs | 20 +--------------- 4 files changed, 39 insertions(+), 28 deletions(-) diff --git a/rustls-mio/Cargo.toml b/rustls-mio/Cargo.toml index d24e0f3b..76280bc5 100644 --- a/rustls-mio/Cargo.toml +++ b/rustls-mio/Cargo.toml @@ -27,8 +27,8 @@ mio = { version = "0.7", features = ["os-poll", "tcp"] } regex = "1.0" serde = "1.0" serde_derive = "1.0" -tempfile = "3.0" webpki-roots = "0.19" +ring = "0.16.0" [[example]] name = "tlsclient" diff --git a/rustls-mio/tests/common/mod.rs b/rustls-mio/tests/common/mod.rs index 5f588b77..c623e5c6 100644 --- a/rustls-mio/tests/common/mod.rs +++ b/rustls-mio/tests/common/mod.rs @@ -11,7 +11,25 @@ use std::time; use regex; use self::regex::Regex; -use tempfile; + +use ring::rand::SecureRandom; + +pub struct DeleteFilesOnDrop { + path: PathBuf, +} + +impl DeleteFilesOnDrop { + pub fn path(&self) -> &PathBuf { + &self.path + } +} + +impl Drop for DeleteFilesOnDrop { + fn drop(&mut self) { + fs::remove_dir_all(&self.path) + .unwrap(); + } +} macro_rules! embed_files { ( @@ -33,18 +51,30 @@ macro_rules! embed_files { } } - pub fn new_test_ca() -> tempfile::TempDir { - let dir = tempfile::TempDir::new().unwrap(); + pub fn new_test_ca() -> DeleteFilesOnDrop { + let mut rand = [0u8; 4]; + ring::rand::SystemRandom::new() + .fill(&mut rand) + .unwrap(); - fs::create_dir(dir.path().join("ecdsa")).unwrap(); - fs::create_dir(dir.path().join("rsa")).unwrap(); + let dir = env::temp_dir() + .join(format!("rustls-{:02x}{:02x}{:02x}{:02x}", + rand[0], rand[1], rand[2], rand[3])); + let deleter = DeleteFilesOnDrop { + path: dir, + }; + + fs::create_dir(&deleter.path).unwrap(); + fs::create_dir(deleter.path.join("ecdsa")).unwrap(); + fs::create_dir(deleter.path.join("rsa")).unwrap(); $( - let mut f = File::create(dir.path().join($keytype).join($path)).unwrap(); + let filename = deleter.path.join($keytype).join($path); + let mut f = File::create(&filename).unwrap(); f.write($name).unwrap(); )+ - dir + deleter } } } diff --git a/rustls/Cargo.toml b/rustls/Cargo.toml index 329a3311..c75c035a 100644 --- a/rustls/Cargo.toml +++ b/rustls/Cargo.toml @@ -27,7 +27,6 @@ quic = [] [dev-dependencies] env_logger = "0.7.1" log = "0.4.4" -tempfile = "3.0" webpki-roots = "0.19.0" criterion = "0.3.0" diff --git a/rustls/tests/common/mod.rs b/rustls/tests/common/mod.rs index c757986b..1253f1e6 100644 --- a/rustls/tests/common/mod.rs +++ b/rustls/tests/common/mod.rs @@ -1,9 +1,5 @@ -use std::fs::{self, File}; -use std::str; -use tempfile; - use std::sync::Arc; -use std::io::{self, Write}; +use std::io; use rustls; @@ -47,20 +43,6 @@ macro_rules! embed_files { _ => panic!("unknown keytype {} with path {}", keytype, path), } } - - pub fn new_test_ca() -> tempfile::TempDir { - let dir = tempfile::TempDir::new().unwrap(); - - fs::create_dir(dir.path().join("ecdsa")).unwrap(); - fs::create_dir(dir.path().join("rsa")).unwrap(); - - $( - let mut f = File::create(dir.path().join($keytype).join($path)).unwrap(); - f.write($name).unwrap(); - )+ - - dir - } } }