1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use failure::*;

const ALPHABET: &[u8] = b"0123456789abcdefghijklmnoqprstuvwxyz";

pub fn decode(s: &str) -> Fallible<Vec<u8>> {
    base_x::decode(ALPHABET, s).map_err(|e| e.into())
}

pub fn encode(buf: &[u8]) -> String {
    base_x::encode(ALPHABET, buf)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_decode() {
        assert_eq!(decode("fg3h7vpw7een6jwwnzmq").unwrap(), b"Hello, World!");
    }

    #[test]
    fn test_encode() {
        assert_eq!(encode(b"Hello, World!"), "fg3h7vpw7een6jwwnzmq");
    }
}