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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! A Base32 encoding/decoding library supporting multiple alphabats.
//!
//! It is `#![no_std]` compatible.
//!
//! ## Multiple Base32 variants support
//!
//! - [RFC 4648](https://en.wikipedia.org/wiki/Base32#Base_32_Encoding_per_%C2%A76)
//! - [RFC 4648 Hex](https://en.wikipedia.org/wiki/Base32#Base_32_Encoding_with_Extended_Hex_Alphabet_per_%C2%A77)
//! - [Crockford Base32](https://en.wikipedia.org/wiki/Base32#Crockford's_Base32)
//! - [Z-Base32](https://en.wikipedia.org/wiki/Base32#z-base-32)
//! - YiDu (Chinese-optimized, avoids pronouncing confusion like E~1 / R~2)
//! - Custom variants
//!
//! ## Usage
//!
//! Encode data using RFC 4648 with padding
//!
//! ```rust
//! use base_n::{Encoder, base32, Decoder};
//!
//! let data = 0xB93246A429u64.to_be_bytes().to_vec();
//! assert_eq!(&data, &[0, 0, 0, 0xB9, 0x32, 0x46, 0xa4, 0x29]);
//!
//! // Encoding
//! let encoded = base32::RFC4648_PAD.encode(&data);
//! assert_eq!(encoded, "AAAABOJSI2SCS===");
//!
//! // Decoding
//! let decoded = base32::RFC4648_PAD.decode(&encoded).unwrap();
//! assert_eq!(data, decoded);
//! ```
//!
//! Customized alphabet
//!
//! ```rust
//! use base_n::{Encoder, base32::Base32Variant};
//!
//! const CUSTOM_BASE32: Base32Variant = Base32Variant::builder()
//! .name("Custom")
//! .mapping(b"ABCDEFGHIJKLMNOPQRSTUVWXYZ123456")
//! .build();
//! println!("{}", CUSTOM_BASE32.encode(b"Hello, world!")); // JBSWY2DPFQQHO22SNRSCC
//! ```
extern crate alloc;
use String;
use Vec;