Skip to content

Commit c44e602

Browse files
committed
Add Default trait to Fe32 (derived)
1 parent 86f7dc0 commit c44e602

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/primitives/gf32.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,14 @@ const CHARS_INV: [i8; 128] = [
6666
];
6767

6868
/// An element in GF(32), the finite field containing elements `[0,31]` inclusive.
69-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
69+
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
7070
#[repr(transparent)]
7171
pub struct Fe32(pub(crate) u8);
7272

7373
impl Fe32 {
74+
/// The Zero element is 0 numeric (character 'Q')
75+
pub const ZERO: Fe32 = Fe32(0);
76+
7477
// These are a little gratuitous for a reference implementation, but it makes me happy to do it.
7578
/// Numeric value maps to bech32 character: 0 == "q".
7679
pub const Q: Fe32 = Fe32(0);
@@ -487,6 +490,18 @@ mod tests {
487490
assert_eq!(fe * Fe32::P, fe) // Fe32::P == Fe32(1)
488491
}
489492
}
493+
494+
#[test]
495+
fn default() {
496+
assert_eq!(Fe32::default().to_u8(), 0);
497+
assert_eq!(Fe32::default(), Fe32::ZERO);
498+
}
499+
500+
#[test]
501+
fn const_zero() {
502+
assert_eq!(Fe32::ZERO.to_u8(), 0);
503+
assert_eq!(Fe32::ZERO.to_char(), 'q');
504+
}
490505
}
491506

492507
#[cfg(kani)]

0 commit comments

Comments
 (0)