Skip to content

Commit 23ac1f5

Browse files
authored
base32ct: comments and constants (#2336)
1 parent a10b8a1 commit 23ac1f5

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

base32ct/src/alphabet.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ pub(crate) mod rfc4648;
44

55
use core::{fmt::Debug, ops::RangeInclusive};
66

7-
/// Core encoder/decoder functions for a particular Base64 alphabet
7+
/// Core encoder/decoder functions for a particular Base32 alphabet
88
pub trait Alphabet: 'static + Copy + Debug + Eq + Send + Sized + Sync {
9-
/// First character in this Base64 alphabet
9+
/// First character in this Base32 alphabet
1010
const BASE: u8;
1111

1212
/// Decoder passes

base32ct/src/alphabet/rfc4648.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl Alphabet for Base32Unpadded {
3737
/// Lower-case Base32 decoder.
3838
const DECODE_LOWER: &[DecodeStep] = &[DecodeStep(b'a'..=b'z', -96), DecodeStep(b'2'..=b'7', -23)];
3939

40-
/// Standard Base64 encoder
40+
/// Lower-case Base32 encoder
4141
const ENCODE_LOWER: &[EncodeStep] = &[EncodeStep(25, 73)];
4242

4343
/// RFC4648 upper case Base32 encoding with `=` padding.
@@ -51,9 +51,8 @@ pub struct Base32Upper;
5151

5252
impl Alphabet for Base32Upper {
5353
const BASE: u8 = b'A';
54-
const DECODER: &'static [DecodeStep] =
55-
&[DecodeStep(b'A'..=b'Z', -64), DecodeStep(b'2'..=b'7', -23)];
56-
const ENCODER: &'static [EncodeStep] = &[EncodeStep(25, 41)];
54+
const DECODER: &'static [DecodeStep] = DECODE_UPPER;
55+
const ENCODER: &'static [EncodeStep] = ENCODE_UPPER;
5756
const PADDED: bool = true;
5857
}
5958

@@ -68,8 +67,13 @@ pub struct Base32UpperUnpadded;
6867

6968
impl Alphabet for Base32UpperUnpadded {
7069
const BASE: u8 = b'A';
71-
const DECODER: &'static [DecodeStep] =
72-
&[DecodeStep(b'A'..=b'Z', -64), DecodeStep(b'2'..=b'7', -23)];
73-
const ENCODER: &'static [EncodeStep] = &[EncodeStep(25, 41)];
70+
const DECODER: &'static [DecodeStep] = DECODE_UPPER;
71+
const ENCODER: &'static [EncodeStep] = ENCODE_UPPER;
7472
const PADDED: bool = false;
7573
}
74+
75+
/// Lower-case Base32 decoder.
76+
const DECODE_UPPER: &[DecodeStep] = &[DecodeStep(b'A'..=b'Z', -64), DecodeStep(b'2'..=b'7', -23)];
77+
78+
/// Upper-case Base32 encoder
79+
const ENCODE_UPPER: &[EncodeStep] = &[EncodeStep(25, 41)];

0 commit comments

Comments
 (0)