Skip to content

Commit c4791fa

Browse files
committed
Add comments for base32 file
1 parent 3e46d4c commit c4791fa

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lightning/src/util/base32.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,22 @@
2020
// SOFTWARE.
2121
// (reference https://github.com/andreasots/base32/blob/master/LICENSE-MIT)
2222

23+
/// Alphabet used for encoding and decoding.
2324
#[derive(Copy, Clone)]
2425
pub enum Alphabet {
25-
// RFC4648
26+
/// RFC4648 base32 encoding. padding: bool indicates whether to use padding.
2627
RFC4648 { padding: bool },
27-
// Crockford
28+
/// Crockford base32 encoding.
2829
Crockford,
2930
}
3031

32+
/// RFC4648 base32 encoding with padding.
3133
const RFC4648_ALPHABET: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
34+
35+
/// Crockford base32 encoding.
3236
const CROCKFORD_ALPHABET: &'static [u8] = b"0123456789ABCDEFGHJKMNPQRSTVWXYZ";
3337

34-
// Encode a byte slice into a base32 string.
38+
/// Encode a byte slice into a base32 string.
3539
pub fn encode(alphabet: Alphabet, data: &[u8]) -> String {
3640
let (alphabet, padding) = match alphabet {
3741
Alphabet::RFC4648 { padding } => (RFC4648_ALPHABET, padding),
@@ -72,10 +76,13 @@ pub fn encode(alphabet: Alphabet, data: &[u8]) -> String {
7276
String::from_utf8(ret).unwrap()
7377
}
7478

79+
/// Inverse RFC4648 lookup table for decoding.
7580
const RFC4648_INV_ALPHABET: [i8; 43] = [
7681
-1, -1, 26, 27, 28, 29, 30, 31, -1, -1, -1, -1, -1, 0, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8,
7782
9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
7883
];
84+
85+
/// Inverse Crockford lookup table for decoding.
7986
const CROCKFORD_INV_ALPHABET: [i8; 43] = [
8087
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, 16, 17, 1,
8188
18, 19, 1, 20, 21, 0, 22, 23, 24, 25, 26, -1, 27, 28, 29, 30, 31,

0 commit comments

Comments
 (0)