Skip to content

Commit

Permalink
Add Fe32::ZERO const
Browse files Browse the repository at this point in the history
  • Loading branch information
optout21 committed Jul 16, 2024
1 parent 86f7dc0 commit 4b42138
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/primitives/checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ impl<'hrp> Iterator for HrpFe32Iter<'hrp> {
Some(high) => return Some(Fe32(high >> 5)),
None => {
self.high_iter = None;
return Some(Fe32::Q);
return Some(Fe32::ZERO);
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/primitives/gf32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ const CHARS_INV: [i8; 128] = [
pub struct Fe32(pub(crate) u8);

impl Fe32 {
/// The Zero element is 0 numeric (character 'Q')
pub const ZERO: Fe32 = Fe32(0);

// These are a little gratuitous for a reference implementation, but it makes me happy to do it.
/// Numeric value maps to bech32 character: 0 == "q".
pub const Q: Fe32 = Fe32(0);
Expand Down Expand Up @@ -257,7 +260,7 @@ impl AsRef<u8> for Fe32 {
}

impl super::Field for Fe32 {
const ZERO: Self = Fe32::Q;
const ZERO: Self = Fe32::ZERO;
const ONE: Self = Fe32::P;
const GENERATOR: Self = Fe32::Z;
const MULTIPLICATIVE_ORDER: usize = 31;
Expand Down Expand Up @@ -487,6 +490,12 @@ mod tests {
assert_eq!(fe * Fe32::P, fe) // Fe32::P == Fe32(1)
}
}

#[test]
fn const_zero() {
assert_eq!(Fe32::ZERO.to_u8(), 0);
assert_eq!(Fe32::ZERO.to_char(), 'q');
}
}

#[cfg(kani)]
Expand Down

0 comments on commit 4b42138

Please sign in to comment.