From 0a2e798894f1ec650726a08fd7dffd915cc643ef Mon Sep 17 00:00:00 2001 From: "Tony Arcieri (iqlusion)" Date: Mon, 14 Nov 2022 15:26:07 -0700 Subject: [PATCH] Switch from `subtle-encoding` to `base16ct` (#443) --- Cargo.lock | 13 ++----------- Cargo.toml | 2 +- cli/Cargo.toml | 2 +- cli/src/terminal.rs | 3 +-- src/cccid.rs | 18 ++++++++++-------- src/chuid.rs | 18 ++++++++++-------- 6 files changed, 25 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 54b0888..226147e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1003,15 +1003,6 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" -[[package]] -name = "subtle-encoding" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dcb1ed7b8330c5eed5441052651dd7a12c75e2ed88f2ec024ae1fa3a5e59945" -dependencies = [ - "zeroize", -] - [[package]] name = "syn" version = "1.0.103" @@ -1270,6 +1261,7 @@ dependencies = [ name = "yubikey" version = "0.6.0" dependencies = [ + "base16ct", "chrono", "cookie-factory", "der-parser", @@ -1294,7 +1286,6 @@ dependencies = [ "sha2", "signature", "subtle", - "subtle-encoding", "uuid", "x509", "x509-parser", @@ -1305,12 +1296,12 @@ dependencies = [ name = "yubikey-cli" version = "0.6.0" dependencies = [ + "base16ct", "clap", "env_logger", "log", "once_cell", "sha2", - "subtle-encoding", "termcolor", "x509-parser", "yubikey", diff --git a/Cargo.toml b/Cargo.toml index 7a2edd4..16f7f89 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ cookie-factory = "0.3" der-parser = "8" des = "0.8" elliptic-curve = "0.12" +hex = { package = "base16ct", version = "0.1", features = ["alloc"] } hmac = "0.12" log = "0.4" nom = "7" @@ -41,7 +42,6 @@ secrecy = "0.8" sha1 = { version = "0.10", features = ["oid"] } sha2 = { version = "0.10", features = ["oid"] } subtle = "2" -subtle-encoding = "0.5" uuid = { version = "1.2", features = ["v4"] } x509 = "0.2" x509-parser = "0.14" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 1fe0720..7b272a9 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -17,10 +17,10 @@ rust-version = "1.56" [dependencies] clap = { version = "4", features = ["derive"] } env_logger = "0.9" +hex = { package = "base16ct", version = "0.1", features = ["alloc"] } log = "0.4" once_cell = "1" sha2 = "0.10" -subtle-encoding = "0.5" termcolor = "1" x509-parser = "0.14" yubikey = { version = "0.6", path = ".." } diff --git a/cli/src/terminal.rs b/cli/src/terminal.rs index 5af2fed..19dc569 100644 --- a/cli/src/terminal.rs +++ b/cli/src/terminal.rs @@ -8,7 +8,6 @@ use std::{ str, sync::Mutex, }; -use subtle_encoding::hex; use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, StandardStreamLock, WriteColor}; use x509_parser::parse_x509_certificate; use yubikey::{certificate::Certificate, piv::*, YubiKey}; @@ -200,7 +199,7 @@ pub fn print_cert_info( print_cert_attr( stream, "Fingerprint", - str::from_utf8(hex::encode(fingerprint).as_slice()).unwrap(), + &hex::upper::encode_string(&fingerprint), )?; print_cert_attr( stream, diff --git a/src/cccid.rs b/src/cccid.rs index 5a7f190..332c415 100644 --- a/src/cccid.rs +++ b/src/cccid.rs @@ -32,11 +32,7 @@ use crate::{Error, Result, YubiKey}; use rand_core::{OsRng, RngCore}; -use std::{ - fmt::{self, Debug, Display}, - str, -}; -use subtle_encoding::hex; +use std::fmt::{self, Debug, Display}; /// CCCID offset const CCC_ID_OFFS: usize = 9; @@ -114,8 +110,14 @@ impl CccId { } } -impl Display for CccId { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str(str::from_utf8(&hex::encode(&self.0[..])).unwrap()) +impl AsRef<[u8]> for CccId { + fn as_ref(&self) -> &[u8] { + &self.0 + } +} + +impl Display for CccId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(&hex::upper::encode_string(self.as_ref())) } } diff --git a/src/chuid.rs b/src/chuid.rs index 77d98ba..1b36c96 100644 --- a/src/chuid.rs +++ b/src/chuid.rs @@ -31,11 +31,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. use crate::{Error, Result, YubiKey}; -use std::{ - fmt::{self, Debug, Display}, - str, -}; -use subtle_encoding::hex; +use std::fmt::{self, Debug, Display}; use uuid::Uuid; /// FASC-N offset @@ -130,8 +126,14 @@ impl ChuId { } } -impl Display for ChuId { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str(str::from_utf8(&hex::encode(&self.0[..])).unwrap()) +impl AsRef<[u8]> for ChuId { + fn as_ref(&self) -> &[u8] { + &self.0 + } +} + +impl Display for ChuId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(&hex::upper::encode_string(self.as_ref())) } }