fritzdecode/
fritz_base32.rs

1//! Fritz!OS base32 encoding. Similar to [RFC4648], but uses digits 1 through 6
2//! instead of 2 through 7.
3//!
4//! [RFC4648]: https://www.rfc-editor.org/rfc/rfc4648.html
5///
6/// # Example
7///
8/// ```rust
9/// # #![feature(assert_matches)]
10/// # use std::assert_matches::assert_matches;
11/// use fritzdecode::fritz_base32;
12///
13/// let decoded = fritz_base32::ENCODING.decode(b"KRSXG4BAMRQXIYJB");
14/// assert_eq!(decoded.unwrap(), "Test data!".as_bytes());
15///
16/// let decoded = fritz_base32::ENCODING.decode(b"K4ZG62THEBWGK2THORUA====");
17/// assert_matches!(
18///     decoded,
19///     Err(data_encoding::DecodeError {
20///         position: 20,
21///         kind: data_encoding::DecodeKind::Symbol
22///     })
23/// );
24/// ```
25use std::sync::LazyLock;
26
27use data_encoding::{Encoding, Specification};
28
29pub static ENCODING: LazyLock<Encoding> = LazyLock::new(|| {
30    let mut spec = Specification::new();
31    spec.symbols.push_str("ABCDEFGHIJKLMNOPQRSTUVWXYZ123456");
32    spec.encoding().expect("encoding is invalid")
33});