use std::ops::{Add, Mul, Sub}; use generic_array::{ArrayLength, GenericArray}; use rand::{Rng, RngCore}; use generic_array::typenum::Unsigned; pub trait GF: Add + Sub + Mul + Copy + Clone + Eq + TryFrom { const ORDER: usize; type ChunkSize: ArrayLength; /// Additive identity const ZERO: Self; /// Multiplicative identity const ONE: Self; /// Multiplicative inverse fn minv(self) -> Self; fn decode(chunk: GenericArray) -> Self; fn encode(self) -> GenericArray; fn decode_slice(s: &[u8]) -> Self { let mut chunk = GenericArray::::default(); for i in 0..Self::ChunkSize::to_usize() { chunk[i] = s.get(i).copied().unwrap_or(0); } Self::decode(chunk) } fn sample(rng: &mut (impl Rng + ?Sized)) -> Self; }