Skip to content

Commit

Permalink
add Base32Z detection to DetectedEncoder
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Huseby <[email protected]>
  • Loading branch information
dhuseby committed May 10, 2024
1 parent 30d3cbe commit df3edd1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "multiutil"
version = "1.0.8"
version = "1.0.9"
edition = "2021"
authors = ["Dave Huseby <[email protected]>"]
description = "Multiformat utility functions and types"
Expand Down
21 changes: 13 additions & 8 deletions src/base_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,46 +88,51 @@ impl BaseEncoder for DetectedEncoder {
return Ok((Base::Base16Lower, data))
}

// base32 (no padding)
// base32 (upper)
if let Some(data) = base32::decode(base32::Alphabet::Rfc4648 { padding: false }, s) {
return Ok((Base::Base32Upper, data))
}

// base32 (padding)
// base32 (upper + padding)
if let Some(data) = base32::decode(base32::Alphabet::Rfc4648 { padding: true }, s) {
return Ok((Base::Base32PadUpper, data))
}

// base32 (lower + no padding)
// base32 (lower)
if let Some(data) = base32::decode(base32::Alphabet::Rfc4648Lower { padding: false }, s) {
return Ok((Base::Base32Lower, data))
}

// base32 (padding)
// base32 (lower + padding)
if let Some(data) = base32::decode(base32::Alphabet::Rfc4648Lower { padding: true }, s) {
return Ok((Base::Base32PadLower, data))
}

// base32 (no padding)
// base32 (hex + upper)
if let Some(data) = base32::decode(base32::Alphabet::Rfc4648Hex { padding: false }, s) {
return Ok((Base::Base32HexUpper, data))
}

// base32 (padding)
// base32 (hex + upper + padding)
if let Some(data) = base32::decode(base32::Alphabet::Rfc4648Hex { padding: true }, s) {
return Ok((Base::Base32HexPadUpper, data))
}

// base32 (lower + no padding)
// base32 (hex + lower)
if let Some(data) = base32::decode(base32::Alphabet::Rfc4648HexLower { padding: false }, s) {
return Ok((Base::Base32HexLower, data))
}

// base32 (padding)
// base32 (hex + lower + padding)
if let Some(data) = base32::decode(base32::Alphabet::Rfc4648HexLower { padding: true }, s) {
return Ok((Base::Base32HexPadLower, data))
}

// base32z
if let Some(data) = base32::decode(base32::Alphabet::Z, s) {
return Ok((Base::Base32Z, data))
}

// base36
if let Ok(data) = base36::decode(s) {
return Ok((Base::Base36Lower, data))
Expand Down

0 comments on commit df3edd1

Please sign in to comment.