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.
This commit is contained in:
Joseph Birr-Pixton 2020-06-20 12:59:20 +01:00
parent 1b99071bc4
commit ac3573bf98
4 changed files with 39 additions and 28 deletions

View File

@ -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"

View File

@ -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
}
}
}

View File

@ -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"

View File

@ -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
}
}
}