1use super::{Alphabet, DecodeStep, EncodeStep};
4
5#[derive(Copy, Clone, Debug, Eq, PartialEq)]
12pub struct Base64Url;
13
14impl Alphabet for Base64Url {
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 = Base64UrlUnpadded;
20}
21
22#[derive(Copy, Clone, Debug, Eq, PartialEq)]
29pub struct Base64UrlUnpadded;
30
31impl Alphabet for Base64UrlUnpadded {
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 - 0x20)),
53    EncodeStep::Diff(62, b'_' as i16 - b'-' as i16 - 1),
54];