base64ct/alphabet/
pbkdf2.rs

1use crate::alphabet::{Alphabet, DecodeStep, EncodeStep};
2
3/// PBKDF2 Base64: variant of unpadded standard Base64 with `.` instead of `+`.
4///
5/// ```text
6/// [A-Z]      [a-z]      [0-9]      .     /
7/// 0x41-0x5a, 0x61-0x7a, 0x30-0x39, 0x2e, 0x2f
8/// ```
9#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
10pub struct Base64Pbkdf2;
11
12impl Alphabet for Base64Pbkdf2 {
13    const BASE: u8 = b'A';
14    const DECODER: &'static [DecodeStep] = DECODER;
15    const ENCODER: &'static [EncodeStep] = ENCODER;
16    const PADDED: bool = false;
17    type Unpadded = Self;
18}
19
20const DECODER: &[DecodeStep] = &[
21    DecodeStep::Range(b'A'..=b'Z', -64),
22    DecodeStep::Range(b'a'..=b'z', -70),
23    DecodeStep::Range(b'0'..=b'9', 5),
24    DecodeStep::Eq(b'.', 63),
25    DecodeStep::Eq(b'/', 64),
26];
27
28const ENCODER: &[EncodeStep] = &[
29    EncodeStep::Diff(25, 6),
30    EncodeStep::Diff(51, -75),
31    EncodeStep::Diff(61, -(b'.' as i16 - 0x22)),
32    EncodeStep::Diff(62, b'/' as i16 - b'.' as i16 - 1),
33];