From 1b7d2460402c9cb355c17d7a45df3b84edc233f5 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Fri, 4 Feb 2022 12:04:51 +0100 Subject: [PATCH] use itertools and from_utf8_unchecked avoid allocations and skip the utf8 check on the hex string Signed-off-by: Wolfgang Bumiller --- Cargo.toml | 1 + src/main.rs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 685e9b6..2d44636 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ futures = "0.3" futures-util = "0.3" hex = "0.4" hyper = "0.14" +itertools = "0.10" openssl = "0.10" percent-encoding = "2" serde = { version = "1.0", features = ["derive"] } diff --git a/src/main.rs b/src/main.rs index cefe565..ea5693c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -159,6 +159,7 @@ impl CtrlTunnel { return true; } + use itertools::Itertools; let fp = match cert.digest(openssl::hash::MessageDigest::sha256()) { Ok(fp) => fp, Err(err) => { @@ -171,8 +172,7 @@ impl CtrlTunnel { let fp_string = fp_string .as_bytes() .chunks(2) - .map(|v| std::str::from_utf8(v).unwrap()) - .collect::>() + .map(|v| unsafe { std::str::from_utf8_unchecked(v) }) .join(":"); let expected = expected.to_lowercase();