From 5c1ca1aba9420ced0480315d93dfea608723d3d4 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sun, 3 Nov 2024 21:34:34 +0100 Subject: [PATCH] replace alphabet: use ~ and . instead of ! and $ ! and $ are bash-unsafe, and though ~ and . are ugly within the chunked alphadecimals, ugliness is still better than having problems with cli --- Cargo.lock | 2 +- Cargo.toml | 4 ++-- src/lib.rs | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5a4774d..e7871db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -54,7 +54,7 @@ checksum = "d92bec98840b8f03a5ff5413de5293bfcd8bf96467cf5452609f939ec6f5de16" [[package]] name = "baid64" -version = "0.2.2" +version = "0.3.0" dependencies = [ "amplify", "base64", diff --git a/Cargo.toml b/Cargo.toml index f763273..711350a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "baid64" -version = "0.2.2" -description = "Easy-to-check Base64 encoding for identities" +version = "0.3.0" +description = "Easy-to-check URL-safe Base64 encoding for identities" keywords = ["base64", "encoding", "mnemonic"] categories = ["encoding", "value-formatting", "command-line-utilities"] readme = "README.md" diff --git a/src/lib.rs b/src/lib.rs index f3c38e5..9d5cb63 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,7 +32,7 @@ pub const ID_MIN_LEN: usize = 4; pub const HRI_MAX_LEN: usize = 16; pub const BAID64_ALPHABET: &str = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!$"; + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789~."; fn check(hri: &'static str, payload: [u8; LEN]) -> [u8; 4] { let key = sha2::Sha256::digest(hri.as_bytes()); @@ -104,8 +104,8 @@ where let orig = s; use base64::alphabet::Alphabet; - use base64::engine::general_purpose::NO_PAD; use base64::engine::GeneralPurpose; + use base64::engine::general_purpose::NO_PAD; let mut checksum = None; @@ -229,8 +229,8 @@ impl Baid64Display { impl Display for Baid64Display { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { use base64::alphabet::Alphabet; - use base64::engine::general_purpose::NO_PAD; use base64::engine::GeneralPurpose; + use base64::engine::general_purpose::NO_PAD; if (self.prefix && !f.sign_minus()) || (!self.prefix && f.sign_minus()) { write!(f, "{}:", self.hri)?;