~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/atproto

atproto's primitives in Rust, small and free of I/O

0
0
main
20 lines · 613 B Raw History
use atproto::base32::{LOWER, decode, encode};

#[test]
fn reads_only_what_it_writes() {
    // RFC 4648's vectors, lower case and unpadded.
    for (bytes, text) in [
        (&b""[..], ""),
        (b"f", "my"),
        (b"fo", "mzxq"),
        (b"foo", "mzxw6"),
        (b"foobar", "mzxw6ytboi"),
    ] {
        assert_eq!(encode(LOWER, bytes), text);
        assert_eq!(decode(LOWER, text).as_deref(), Some(bytes));
    }
    // Not of the alphabet, bits left over set, or a character too many.
    for bad in ["m1", "mz", "mzx", "maa", "MY"] {
        assert_eq!(decode(LOWER, bad), None, "{bad}");
    }
}