diff --git a/Cargo.toml b/Cargo.toml index 481be10..a16f891 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,6 @@ crate-git-revision = "0.0.6" proptest = "1.0.0" [dependencies] -base32 = "0.4.0" +data-encoding = "2.6.0" thiserror = "1.0.36" clap = { version = "4.2.4", default-features = false, features = ["std", "derive", "usage", "help"], optional = true } diff --git a/src/convert.rs b/src/convert.rs index 11a2d7b..08b579b 100644 --- a/src/convert.rs +++ b/src/convert.rs @@ -8,19 +8,12 @@ pub fn encode(ver: u8, payload: &[u8]) -> String { d.push(ver); d.extend_from_slice(payload); d.extend_from_slice(&checksum(&d)); - base32::encode(base32::Alphabet::RFC4648 { padding: false }, &d) + data_encoding::BASE32_NOPAD.encode(&d) } pub fn decode(s: &str) -> Result<(u8, Vec), DecodeError> { - // TODO: Look at what other base32 implementations are available, because - // this one allows for decoding of non-canonical base32 strings, and doesn't - // come with helpful methods for validating the length is canonical. - let data = base32::decode(base32::Alphabet::RFC4648 { padding: false }, s); + let data = data_encoding::BASE32_NOPAD.decode(s.as_bytes()).ok(); if let Some(data) = data { - let s_canonical_len = (data.len() * 8 + 4) / 5; - if s.len() != s_canonical_len { - return Err(DecodeError::Invalid); - } if data.len() < 3 { return Err(DecodeError::Invalid); }