Skip to content

Commit 5018673

Browse files
committed
Remove magic number
1 parent 535cd17 commit 5018673

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/descriptor/checksum.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use crate::Error;
1616

1717
const CHECKSUM_CHARSET: &[u8] = b"qpzry9x8gf2tvdw0s3jn54khce6mua7l";
1818

19+
const CHECKSUM_LENGTH: usize = 8;
20+
1921
fn poly_mod(mut c: u64, val: u64) -> u64 {
2022
let c0 = c >> 35;
2123

@@ -117,15 +119,15 @@ impl Engine {
117119

118120
/// Obtains the checksum characters of all the data thus-far fed to the
119121
/// engine without allocating, to get a string use [`Self::checksum`].
120-
pub fn checksum_chars(&mut self) -> [char; 8] {
122+
pub fn checksum_chars(&mut self) -> [char; CHECKSUM_LENGTH] {
121123
if self.clscount > 0 {
122124
self.c = poly_mod(self.c, self.cls);
123125
}
124-
(0..8).for_each(|_| self.c = poly_mod(self.c, 0));
126+
(0..CHECKSUM_LENGTH).for_each(|_| self.c = poly_mod(self.c, 0));
125127
self.c ^= 1;
126128

127-
let mut chars = [0 as char; 8];
128-
for j in 0..8 {
129+
let mut chars = [0 as char; CHECKSUM_LENGTH];
130+
for j in 0..CHECKSUM_LENGTH {
129131
chars[j] = CHECKSUM_CHARSET[((self.c >> (5 * (7 - j))) & 31) as usize] as char;
130132
}
131133
chars

0 commit comments

Comments
 (0)