base64ct/alphabet/
standard.rs
1use super::{Alphabet, DecodeStep, EncodeStep};
4
5#[derive(Copy, Clone, Debug, Eq, PartialEq)]
12pub struct Base64;
13
14impl Alphabet for Base64 {
15 const BASE: u8 = b'A';
16 const DECODER: &'static [DecodeStep] = DECODER;
17 const ENCODER: &'static [EncodeStep] = ENCODER;
18 const PADDED: bool = true;
19 type Unpadded = Base64Unpadded;
20}
21
22#[derive(Copy, Clone, Debug, Eq, PartialEq)]
29pub struct Base64Unpadded;
30
31impl Alphabet for Base64Unpadded {
32 const BASE: u8 = b'A';
33 const DECODER: &'static [DecodeStep] = DECODER;
34 const ENCODER: &'static [EncodeStep] = ENCODER;
35 const PADDED: bool = false;
36 type Unpadded = Self;
37}
38
39const DECODER: &[DecodeStep] = &[
41 DecodeStep::Range(b'A'..=b'Z', -64),
42 DecodeStep::Range(b'a'..=b'z', -70),
43 DecodeStep::Range(b'0'..=b'9', 5),
44 DecodeStep::Eq(b'+', 63),
45 DecodeStep::Eq(b'/', 64),
46];
47
48const ENCODER: &[EncodeStep] = &[
50 EncodeStep::Diff(25, 6),
51 EncodeStep::Diff(51, -75),
52 EncodeStep::Diff(61, -(b'+' as i16 - 0x1c)),
53 EncodeStep::Diff(62, b'/' as i16 - b'+' as i16 - 1),
54];