Inversed-Tech / eyelid

Private iris matching
Apache License 2.0
0 stars 0 forks source link

Auto-expand polynomials to avoid "out of range" panics #31

Closed teor2345 closed 3 months ago

teor2345 commented 3 months ago

This is the first part of the fixes in #13.

This PR replaces polynomial initialisation with an auto-expanding IndexMut implementation. It also makes sure modular reductions and canonical leading coefficients are maintained across existing code in main.

For testing, it reduces the size of the tiny test polynomial, so we are frequently testing 0, 1, and -1 coefficients.

Usage Notes

Use the new IndexMut implementation like poly[index] = Coeff::one().

After setting the index, the caller must reduce the polynomial and restore canonical form, by calling Poly::reduce_mod_poly(). This can't be done automatically, because IndexMut returns a reference to the value, not the whole vector.

Avoid using the raw poly.coeffs[index], because it uses <Vec as IndexMut>, which panics if the index is beyond the existing size of the vector.

teor2345 commented 3 months ago

Merged after fixing some spelling mistakes