Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::{env, fs, io};
fn main() {
// Send GET request and inspect result, with proper error handling.
if let Err(e) = run_client() {
eprintln!("FAILED: {}", e);
eprintln!("FAILED: {e}");
std::process::exit(1);
}
}
Expand All @@ -34,7 +34,7 @@ async fn run_client() -> io::Result<()> {

// First parameter is target URL (mandatory).
let url = match env::args().nth(1) {
Some(ref url) => Uri::from_str(url).map_err(|e| error(format!("{}", e)))?,
Some(ref url) => Uri::from_str(url).map_err(|e| error(format!("{e}")))?,
None => {
println!("Usage: client <url> <ca_store>");
return Ok(());
Expand All @@ -44,8 +44,8 @@ async fn run_client() -> io::Result<()> {
// Second parameter is custom Root-CA store (optional, defaults to native cert store).
let mut ca = match env::args().nth(2) {
Some(ref path) => {
let f = fs::File::open(path)
.map_err(|e| error(format!("failed to open {}: {}", path, e)))?;
let f =
fs::File::open(path).map_err(|e| error(format!("failed to open {path}: {e}")))?;
let rd = io::BufReader::new(f);
Some(rd)
}
Expand Down Expand Up @@ -86,15 +86,15 @@ async fn run_client() -> io::Result<()> {
let res = client
.get(url)
.await
.map_err(|e| error(format!("Could not get: {:?}", e)))?;
.map_err(|e| error(format!("Could not get: {e:?}")))?;
println!("Status:\n{}", res.status());
println!("Headers:\n{:#?}", res.headers());

let body = res
.into_body()
.collect()
.await
.map_err(|e| error(format!("Could not get body: {:?}", e)))?
.map_err(|e| error(format!("Could not get body: {e:?}")))?
.to_bytes();
println!("Body:\n{}", String::from_utf8_lossy(&body));

Expand Down
12 changes: 6 additions & 6 deletions examples/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use tokio_rustls::TlsAcceptor;
fn main() {
// Serve an echo service over HTTPS, with proper error handling.
if let Err(e) = run_server() {
eprintln!("FAILED: {}", e);
eprintln!("FAILED: {e}");
std::process::exit(1);
}
}
Expand Down Expand Up @@ -52,7 +52,7 @@ async fn run_server() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// Load private key.
let key = load_private_key("examples/sample.rsa")?;

println!("Starting to serve on https://{}", addr);
println!("Starting to serve on https://{addr}");

// Create a TCP listener via tokio.
let incoming = TcpListener::bind(&addr).await?;
Expand Down Expand Up @@ -118,8 +118,8 @@ async fn echo(req: Request<Incoming>) -> Result<Response<Full<Bytes>>, hyper::Er
// Load public certificate from file.
fn load_certs(filename: &str) -> io::Result<Vec<CertificateDer<'static>>> {
// Open certificate file.
let certfile = fs::File::open(filename)
.map_err(|e| error(format!("failed to open {}: {}", filename, e)))?;
let certfile =
fs::File::open(filename).map_err(|e| error(format!("failed to open {filename}: {e}")))?;
let mut reader = io::BufReader::new(certfile);

// Load and return certificate.
Expand All @@ -129,8 +129,8 @@ fn load_certs(filename: &str) -> io::Result<Vec<CertificateDer<'static>>> {
// Load private key from file.
fn load_private_key(filename: &str) -> io::Result<PrivateKeyDer<'static>> {
// Open keyfile.
let keyfile = fs::File::open(filename)
.map_err(|e| error(format!("failed to open {}: {}", filename, e)))?;
let keyfile =
fs::File::open(filename).map_err(|e| error(format!("failed to open {filename}: {e}")))?;
let mut reader = io::BufReader::new(keyfile);

// Load and return a single private key.
Expand Down
6 changes: 2 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,14 @@ impl ConfigBuilderExt for ConfigBuilder<ClientConfig, WantsVerifier> {
match roots.add(cert) {
Ok(_) => valid_count += 1,
Err(err) => {
crate::log::debug!("certificate parsing failed: {:?}", err);
crate::log::debug!("certificate parsing failed: {err:?}");
invalid_count += 1
}
}
}

crate::log::debug!(
"with_native_roots processed {} valid and {} invalid certs",
valid_count,
invalid_count
"with_native_roots processed {valid_count} valid and {invalid_count} invalid certs"
);
if roots.is_empty() {
crate::log::debug!("no valid native root CA certificates found");
Expand Down
6 changes: 3 additions & 3 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn wait_for_server(addr: &str) {
}
thread::sleep(time::Duration::from_millis(i * 100));
}
panic!("failed to connect to {:?} after 10 tries", addr);
panic!("failed to connect to {addr:?} after 10 tries");
}

#[test]
Expand All @@ -55,7 +55,7 @@ fn server() {
let output = Command::new("curl")
.arg("--insecure")
.arg("--http1.0")
.arg(format!("https://{}", addr))
.arg(format!("https://{addr}"))
.output()
.expect("cannot run curl");

Expand Down Expand Up @@ -87,7 +87,7 @@ fn custom_ca_store() {
wait_for_server(addr);

let rc = client_command()
.arg(format!("https://{}", addr))
.arg(format!("https://{addr}"))
.arg("examples/sample.pem")
.output()
.expect("cannot run client example");
Expand Down