diff --git a/Cargo.lock b/Cargo.lock index c94712c..fda1308 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,15 +30,15 @@ dependencies = [ [[package]] name = "age-core" version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2bf6a89c984ca9d850913ece2da39e1d200563b0a94b002b253beee4c5acf99" +source = "git+https://github.com/str4d/rage.git?rev=5e530a3a6aad9e189e26903bc8114e2da526b4b5#5e530a3a6aad9e189e26903bc8114e2da526b4b5" dependencies = [ - "base64 0.21.7", + "base64 0.22.1", + "bech32", "chacha20poly1305", "cookie-factory", "hkdf", "io_tee", - "nom", + "nom 8.0.0", "rand", "secrecy 0.10.3", "sha2", @@ -48,11 +48,10 @@ dependencies = [ [[package]] name = "age-plugin" version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8a31f37914cf72cf36a1cd8ea9f24e5df20899e9348dd3d1c8273f4420ce493" +source = "git+https://github.com/str4d/rage.git?rev=5e530a3a6aad9e189e26903bc8114e2da526b4b5#5e530a3a6aad9e189e26903bc8114e2da526b4b5" dependencies = [ "age-core", - "base64 0.21.7", + "base64 0.22.1", "bech32", "chrono", ] @@ -63,7 +62,7 @@ version = "0.5.0" dependencies = [ "age-core", "age-plugin", - "base64 0.21.7", + "base64 0.22.1", "bech32", "console", "dialoguer", @@ -129,7 +128,7 @@ dependencies = [ "asn1-rs-derive", "asn1-rs-impl", "displaydoc", - "nom", + "nom 7.1.3", "num-traits", "rusticata-macros", "thiserror", @@ -198,6 +197,12 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "base64ct" version = "1.6.0" @@ -215,9 +220,9 @@ dependencies = [ [[package]] name = "bech32" -version = "0.9.1" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" +checksum = "32637268377fc7b10a8c6d51de3e7fba1ce5dd371a96e342b34e6078db558e7f" [[package]] name = "bitflags" @@ -486,7 +491,7 @@ checksum = "dbd676fbbab537128ef0278adb5576cf363cff6aa22a7b24effe97347cfab61e" dependencies = [ "asn1-rs", "displaydoc", - "nom", + "nom 7.1.3", "num-bigint", "num-traits", "rusticata-macros", @@ -1358,6 +1363,15 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "nom" +version = "8.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df9761775871bdef83bee530e60050f7e54b1105350d6884eb0fb4f46c2f9405" +dependencies = [ + "memchr", +] + [[package]] name = "ntapi" version = "0.4.1" @@ -2000,7 +2014,7 @@ version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "faf0c4a6ece9950b9abdb62b1cfcf2a68b3b67a10ba445b3bb85be2a293d0632" dependencies = [ - "nom", + "nom 7.1.3", ] [[package]] @@ -3006,7 +3020,7 @@ dependencies = [ "data-encoding", "der-parser", "lazy_static", - "nom", + "nom 7.1.3", "oid-registry", "rusticata-macros", "thiserror", @@ -3027,7 +3041,7 @@ dependencies = [ "elliptic-curve", "hmac", "log", - "nom", + "nom 7.1.3", "num-bigint-dig", "num-integer", "num-traits", diff --git a/Cargo.toml b/Cargo.toml index 7a04d58..23599e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,8 +24,8 @@ assets = [ [dependencies] age-core = "0.11" age-plugin = "0.6" -base64 = "0.21" -bech32 = "0.9" +base64 = "0.22" +bech32 = "0.11" console = { version = "0.15", default-features = false } dialoguer = { version = "0.11", default-features = false, features = ["password"] } env_logger = "0.10" @@ -56,3 +56,7 @@ man = "0.3" tempfile = "3" test-with = "0.11" which = "5" + +[patch.crates-io] +age-core = { git = "https://github.com/str4d/rage.git", rev = "5e530a3a6aad9e189e26903bc8114e2da526b4b5" } +age-plugin = { git = "https://github.com/str4d/rage.git", rev = "5e530a3a6aad9e189e26903bc8114e2da526b4b5" } diff --git a/src/key.rs b/src/key.rs index 87167a8..db716f8 100644 --- a/src/key.rs +++ b/src/key.rs @@ -1,8 +1,8 @@ //! Structs for handling YubiKeys. +use age_core::primitives::bech32_encode; use age_core::secrecy::{ExposeSecret, SecretString}; use age_plugin::{identity, Callbacks}; -use bech32::{ToBase32, Variant}; use dialoguer::Password; use log::{debug, error, warn}; use std::convert::Infallible; @@ -422,14 +422,9 @@ pub struct Stub { impl fmt::Display for Stub { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str( - bech32::encode( - IDENTITY_PREFIX, - self.to_bytes().to_base32(), - Variant::Bech32, - ) - .expect("HRP is valid") - .to_uppercase() - .as_str(), + bech32_encode(IDENTITY_PREFIX, &self.to_bytes()) + .to_uppercase() + .as_str(), ) } } diff --git a/src/main.rs b/src/main.rs index a2746ec..69f2840 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,7 +28,7 @@ use error::Error; const PLUGIN_NAME: &str = "yubikey"; const BINARY_NAME: &str = "age-plugin-yubikey"; -const IDENTITY_PREFIX: &str = "age-plugin-yubikey-"; +const IDENTITY_PREFIX: bech32::Hrp = bech32::Hrp::parse_unchecked("AGE-PLUGIN-YUBIKEY-"); const USABLE_SLOTS: [RetiredSlotId; 20] = [ RetiredSlotId::R1, diff --git a/src/piv_p256/recipient.rs b/src/piv_p256/recipient.rs index 67e1df2..a0a661b 100644 --- a/src/piv_p256/recipient.rs +++ b/src/piv_p256/recipient.rs @@ -1,4 +1,4 @@ -use bech32::{ToBase32, Variant}; +use age_core::primitives::bech32_encode_to_fmt; use p256::elliptic_curve::sec1::{FromEncodedPoint, ToEncodedPoint}; use yubikey::{certificate::PublicKeyInfo, Certificate}; @@ -6,7 +6,7 @@ use std::fmt; use crate::recipient::{static_tag, TAG_BYTES}; -const RECIPIENT_PREFIX: &str = "age1yubikey"; +const RECIPIENT_PREFIX: bech32::Hrp = bech32::Hrp::parse_unchecked("age1yubikey"); /// Wrapper around a compressed secp256r1 curve point. #[derive(Clone)] @@ -20,15 +20,7 @@ impl fmt::Debug for Recipient { impl fmt::Display for Recipient { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str( - bech32::encode( - RECIPIENT_PREFIX, - self.to_encoded().as_bytes().to_base32(), - Variant::Bech32, - ) - .expect("HRP is valid") - .as_str(), - ) + bech32_encode_to_fmt(f, RECIPIENT_PREFIX, self.to_encoded().as_bytes()) } }