Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into no-std
Browse files Browse the repository at this point in the history
# Conflicts:
#	Cargo.toml
#	src/convert.rs
  • Loading branch information
overcat committed Sep 3, 2024
2 parents 4608d1f + 9b58e04 commit 74a4619
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
11 changes: 3 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repository = "https://github.com/stellar/rs-stellar-strkey"
authors = ["Stellar Development Foundation <[email protected]>"]
license = "Apache-2.0"
readme = "README.md"
version = "0.0.8"
version = "0.0.9"
edition = "2021"
rust-version = "1.67.0"

Expand All @@ -28,10 +28,5 @@ crate-git-revision = "0.0.6"
proptest = "1.0.0"

[dependencies]
base32 = "0.5.1"
clap = { version = "4.5.16", default-features = false, features = [
"std",
"derive",
"usage",
"help",
], optional = true }
data-encoding = "2.6.0"
clap = { version = "4.2.4", default-features = false, features = ["std", "derive", "usage", "help"], optional = true }
11 changes: 2 additions & 9 deletions src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,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<u8>), 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);
}
Expand Down

0 comments on commit 74a4619

Please sign in to comment.