Skip to content

Commit

Permalink
fix: dry code
Browse files Browse the repository at this point in the history
  • Loading branch information
0xAlcibiades committed Sep 11, 2024
1 parent 7333d38 commit 9ad12d8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ tokio-rustls = "0.26.0"
tokio-stream = { version = "0.1.16", features = ["net"] }
tower = { version = "0.5.1", features = ["util"] }
tracing = "0.1.40"
tracing-subscriber = "0.3.18"

[dev-dependencies]
hyper = { version = "1.4.1", features = ["client"] }
tokio = { version = "1.0", features = ["rt", "net", "test-util"] }
tracing-subscriber = "0.3.18"
47 changes: 1 addition & 46 deletions src/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ mod tests {
debug!("Server task started");
let mut tls_stream = Box::pin(tls_incoming(tcp_incoming, tls_acceptor));
let result =
tokio::time::timeout(std::time::Duration::from_secs(1), tls_stream.next()).await;
tokio::time::timeout(std::time::Duration::from_millis(10), tls_stream.next()).await;
debug!("Server task completed with result: {:?}", result.is_err());
result
});
Expand Down Expand Up @@ -377,49 +377,4 @@ mod tests {
}
}))
}

// Helper function to load certificates
fn load_certs(filename: &str) -> io::Result<Vec<CertificateDer<'static>>> {
debug!("Loading certificates from {}", filename);
let certfile = std::fs::File::open(filename).map_err(|e| {
error!("Failed to open certificate file: {}", e);
io::Error::new(
io::ErrorKind::Other,
format!("failed to open {}: {}", filename, e),
)
})?;
let mut reader = io::BufReader::new(certfile);
let certs = rustls_pemfile::certs(&mut reader)
.collect::<Result<Vec<_>, _>>()
.map_err(|e| {
error!("Failed to parse certificates: {}", e);
io::Error::new(io::ErrorKind::Other, e)
})?;
debug!("Loaded {} certificates", certs.len());
Ok(certs)
}

// Helper function to load private key
fn load_private_key(filename: &str) -> io::Result<PrivateKeyDer<'static>> {
debug!("Loading private key from {}", filename);
let keyfile = std::fs::File::open(filename).map_err(|e| {
error!("Failed to open private key file: {}", e);
io::Error::new(
io::ErrorKind::Other,
format!("failed to open {}: {}", filename, e),
)
})?;
let mut reader = io::BufReader::new(keyfile);
let key = rustls_pemfile::private_key(&mut reader)
.map_err(|e| {
error!("Failed to parse private key: {}", e);
io::Error::new(io::ErrorKind::Other, e)
})?
.ok_or_else(|| {
error!("No private key found in file");
io::Error::new(io::ErrorKind::Other, "no private key found")
})?;
debug!("Loaded private key");
Ok(key)
}
}

0 comments on commit 9ad12d8

Please sign in to comment.