Skip to content

Commit 8e2c0e2

Browse files
committed
rustfmt: Run on util/base32.rs
1 parent ebb213f commit 8e2c0e2

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

lightning/src/util/base32.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ pub enum Alphabet {
3333
/// RFC4648 encoding.
3434
RFC4648 {
3535
/// Whether to use padding.
36-
padding: bool
36+
padding: bool,
3737
},
3838
/// Zbase32 encoding.
39-
ZBase32
39+
ZBase32,
4040
}
4141

4242
impl Alphabet {
@@ -60,9 +60,7 @@ impl Alphabet {
6060
}
6161
ret
6262
},
63-
Self::ZBase32 => {
64-
Self::encode_data(data, ZBASE_ALPHABET)
65-
},
63+
Self::ZBase32 => Self::encode_data(data, ZBASE_ALPHABET),
6664
};
6765
ret.truncate(output_length);
6866

@@ -79,7 +77,9 @@ impl Alphabet {
7977
Self::RFC4648 { padding } => {
8078
let mut unpadded_data_length = data.len();
8179
if *padding {
82-
if data.len() % 8 != 0 { return Err(()); }
80+
if data.len() % 8 != 0 {
81+
return Err(());
82+
}
8383
data.iter().rev().take(6).for_each(|&c| {
8484
if c == b'=' {
8585
unpadded_data_length -= 1;
@@ -88,13 +88,14 @@ impl Alphabet {
8888
}
8989
(&data[..unpadded_data_length], RFC4648_INV_ALPHABET)
9090
},
91-
Self::ZBase32 => {
92-
(data, ZBASE_INV_ALPHABET)
93-
}
91+
Self::ZBase32 => (data, ZBASE_INV_ALPHABET),
9492
};
9593
// If the string has more characters than are required to alphabet_encode the number of bytes
9694
// decodable, treat the string as invalid.
97-
match data.len() % 8 { 1|3|6 => return Err(()), _ => {} }
95+
match data.len() % 8 {
96+
1 | 3 | 6 => return Err(()),
97+
_ => {},
98+
}
9899
Ok(Self::decode_data(data, alphabet)?)
99100
}
100101

@@ -175,9 +176,13 @@ mod tests {
175176
("6n9hq", &[0xf0, 0xbf, 0xc7]),
176177
("4t7ye", &[0xd4, 0x7a, 0x04]),
177178
("6im5sdy", &[0xf5, 0x57, 0xbb, 0x0c]),
178-
("ybndrfg8ejkmcpqxot1uwisza345h769", &[0x00, 0x44, 0x32, 0x14, 0xc7, 0x42, 0x54, 0xb6,
179-
0x35, 0xcf, 0x84, 0x65, 0x3a, 0x56, 0xd7, 0xc6,
180-
0x75, 0xbe, 0x77, 0xdf])
179+
(
180+
"ybndrfg8ejkmcpqxot1uwisza345h769",
181+
&[
182+
0x00, 0x44, 0x32, 0x14, 0xc7, 0x42, 0x54, 0xb6, 0x35, 0xcf, 0x84, 0x65, 0x3a, 0x56,
183+
0xd7, 0xc6, 0x75, 0xbe, 0x77, 0xdf,
184+
],
185+
),
181186
];
182187

183188
#[test]
@@ -242,7 +247,9 @@ mod tests {
242247
}
243248

244249
for (input, encoded) in RFC4648_NON_PADDED_TEST_VECTORS {
245-
let res = &Alphabet::RFC4648 { padding: false }.decode(std::str::from_utf8(encoded).unwrap()).unwrap();
250+
let res = &Alphabet::RFC4648 { padding: false }
251+
.decode(std::str::from_utf8(encoded).unwrap())
252+
.unwrap();
246253
assert_eq!(&res[..], &input[..]);
247254
}
248255
}
@@ -251,9 +258,8 @@ mod tests {
251258
fn padding() {
252259
let num_padding = [0, 6, 4, 3, 1];
253260
for i in 1..6 {
254-
let encoded = Alphabet::RFC4648 { padding: true }.encode(
255-
(0..(i as u8)).collect::<Vec<u8>>().as_ref()
256-
);
261+
let encoded = Alphabet::RFC4648 { padding: true }
262+
.encode((0..(i as u8)).collect::<Vec<u8>>().as_ref());
257263
assert_eq!(encoded.len(), 8);
258264
for j in 0..(num_padding[i % 5]) {
259265
assert_eq!(encoded.as_bytes()[encoded.len() - j - 1], b'=');

0 commit comments

Comments
 (0)