Skip to content

Commit 22bc4e5

Browse files
Change the base32 lib to data-encoding (#65)
1 parent c5a374e commit 22bc4e5

2 files changed

Lines changed: 3 additions & 10 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ crate-git-revision = "0.0.6"
2727
proptest = "1.0.0"
2828

2929
[dependencies]
30-
base32 = "0.4.0"
30+
data-encoding = "2.6.0"
3131
thiserror = "1.0.36"
3232
clap = { version = "4.2.4", default-features = false, features = ["std", "derive", "usage", "help"], optional = true }

src/convert.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,12 @@ pub fn encode(ver: u8, payload: &[u8]) -> String {
88
d.push(ver);
99
d.extend_from_slice(payload);
1010
d.extend_from_slice(&checksum(&d));
11-
base32::encode(base32::Alphabet::RFC4648 { padding: false }, &d)
11+
data_encoding::BASE32_NOPAD.encode(&d)
1212
}
1313

1414
pub fn decode(s: &str) -> Result<(u8, Vec<u8>), DecodeError> {
15-
// TODO: Look at what other base32 implementations are available, because
16-
// this one allows for decoding of non-canonical base32 strings, and doesn't
17-
// come with helpful methods for validating the length is canonical.
18-
let data = base32::decode(base32::Alphabet::RFC4648 { padding: false }, s);
15+
let data = data_encoding::BASE32_NOPAD.decode(s.as_bytes()).ok();
1916
if let Some(data) = data {
20-
let s_canonical_len = (data.len() * 8 + 4) / 5;
21-
if s.len() != s_canonical_len {
22-
return Err(DecodeError::Invalid);
23-
}
2417
if data.len() < 3 {
2518
return Err(DecodeError::Invalid);
2619
}

0 commit comments

Comments
 (0)