Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use data_encoding::{DecodeError, DecodeKind, Encoding, BASE32_NOPAD};
- fn main() {
- println!("{:?}", decode(b"77777777"));
- println!("{:?}", decode(b"777777777"));
- println!("{:?}", decode(b"7777777777"));
- }
- fn decode(bytes: &[u8]) -> Result<Vec<u8>, DecodeError> {
- let mut spec = BASE32_NOPAD.specification();
- spec.check_trailing_bits = false;
- truncate_decode(spec.encoding().unwrap(), bytes)
- }
- fn truncate_decode(encoding: Encoding, input: &[u8]) -> Result<Vec<u8>, DecodeError> {
- match encoding.decode(input) {
- Err(DecodeError {
- position,
- kind: DecodeKind::Length,
- }) => encoding.decode(&input[..position]),
- output => output,
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement