Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ base-x = { version = "0.2.7", default-features = false }
base256emoji = "1.0.2"
data-encoding = { version = "2.3.1", default-features = false, features = ["alloc"] }
data-encoding-macro = "0.1.9"
base45 = "3.1.0"

[dev-dependencies]
criterion = "0.7"
Expand Down
2 changes: 2 additions & 0 deletions cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ impl fmt::Display for StrBase {
Base::Base32Z => "base32z",
Base::Base36Lower => "base36lower",
Base::Base36Upper => "base36upper",
Base::Base45 => "base45",
Base::Base58Flickr => "base58flickr",
Base::Base58Btc => "base58btc",
Base::Base64 => "base64",
Expand Down Expand Up @@ -118,6 +119,7 @@ impl FromStr for StrBase {
"base32z" => Ok(Base::Base32Z),
"base36lower" => Ok(Base::Base36Lower),
"base36upper" => Ok(Base::Base36Upper),
"base45" => Ok(Base::Base45),
"base58flickr" => Ok(Base::Base58Flickr),
"base58btc" => Ok(Base::Base58Btc),
"base64" => Ok(Base::Base64),
Expand Down
2 changes: 2 additions & 0 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ build_base_enum! {
'k' => Base36Lower,
/// Base36, [0-9A-Z] no padding (alphabet: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ).
'K' => Base36Upper,
/// Base45, rfc9285 (alphabet: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:).
'R' => Base45,
/// Base58 flicker (alphabet: 123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ).
'Z' => Base58Flickr,
/// Base58 bitcoin (alphabet: 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz).
Expand Down
6 changes: 6 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ impl From<data_encoding::DecodeError> for Error {
Self::InvalidBaseString
}
}

impl From<base45::DecodeError> for Error {
fn from(_: base45::DecodeError) -> Self {
Self::InvalidBaseString
}
}
13 changes: 13 additions & 0 deletions src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,16 @@ impl BaseCodec for Base36Upper {
Ok(base_x::decode(encoding::BASE36_UPPER, &uppercased)?)
}
}

/// Base45, rfc9285 (alphabet: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:).
pub(crate) struct Base45;

impl BaseCodec for Base45 {
fn encode<I: AsRef<[u8]>>(input: I) -> String {
base45::encode(input.as_ref())
}

fn decode<I: AsRef<str>>(input: I) -> Result<Vec<u8>> {
Ok(base45::decode(input.as_ref())?)
}
}
1 change: 1 addition & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ fn test_basic() {
(Base32Z, "hxf1zgedpcfzg1ebb"),
(Base36Lower, "k2lcpzo5yikidynfl"),
(Base36Upper, "K2LCPZO5YIKIDYNFL"),
(Base45, "RRFF.OEB$D5/DZ24"),
(Base58Flickr, "Z7Pznk19XTTzBtx"),
(Base58Btc, "z7paNL19xttacUY"),
(Base64, "meWVzIG1hbmkgIQ"),
Expand Down
Loading