rspamd_base32/lib.rs
1//! # Rspamd Base32 encode/decode library
2//! This is a conversion module from and to [zbase32](http://philzimmermann.com/docs/human-oriented-base-32-encoding.txt)
3//! encoding. It also supports [RFC 4648](https://datatracker.ietf.org/doc/html/rfc4648)
4//! and [Bech32](https://en.bitcoin.it/wiki/Bech32) alphabets.
5//!
6//! The main purpose of zbase32 is to provide *human* readable encoding that is
7//! more efficient than `hex` encoding.
8//! `zbase32` utilizes up to `len * 5 / 8` of space for encoded date and contains
9//! no padding (and hence no error control, like `base64`).
10//! However, it seems to be much readable for a human when an encoding does not contain padding.
11//!
12//! ## Disclaimers
13//!
14//! This module is intended to be compatible with [Rspamd](https://rspamd.com)
15//! base32 [encoding](https://rspamd.com/doc/lua/rspamd_util.html#f0372b),
16//! so it has **bug-to-bug** compatibility with Rspamd C implementation including:
17//!
18//! - Zbase32 encodes data in reversed octets order (due to the initial bug in Rspamd and lack of test vectors)
19//! - RFC 4648 encoding does not include padding (because padding as defined in RFC for base32 is just ugly)
20//!
21//!
22//! ## Example
23//!
24//! ~~~rust
25//!use rspamd_base32::{encode, decode};
26//!
27//!fn main() {
28//! let a = b"hello world";
29//! let b = "em3ags7py376g3tprd";
30//!
31//! assert_eq!(encode(a), b);
32//! assert_eq!(a, &decode(b).unwrap()[..]);
33//!}
34//!~~~
35#![forbid(unsafe_code)]
36
37pub mod alphabet;
38pub mod encode;
39#[cfg(any(feature = "alloc", feature = "std", test))]
40pub use crate::encode::{encode, encode_alphabet, encode_alphabet_slice};
41
42pub mod decode;
43#[cfg(any(feature = "alloc", feature = "std", test))]
44pub use crate::decode::{decode, decode_alphabet, decode_alphabet_vec};
45
46#[cfg(test)]
47mod tests;
48