Improved Zeroize impl for BigInt's Sign (#39)

The `zeroize` crate defines a blanket impl of `Zeroize` for any type
with the `DefaultIsZeroes` marker trait, which replaces the value with
its `Default` using volatile writes with a memory fence.

This does require defining `Default` on `Sign`, but it seems like
`Sign::NoSign` is a fairly reasonable choice for a default.
This commit is contained in:
Tony Arcieri 2022-03-03 01:08:36 -07:00 committed by GitHub
parent 158aea7d50
commit f6b46ffe32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -53,14 +53,15 @@ pub enum Sign {
Plus,
}
#[cfg(feature = "zeroize")]
impl Zeroize for Sign {
fn zeroize(&mut self) {
// TODO: Figure out how to better clear the sign.
*self = Sign::NoSign;
impl Default for Sign {
fn default() -> Sign {
Sign::NoSign
}
}
#[cfg(feature = "zeroize")]
impl zeroize::DefaultIsZeroes for Sign {}
impl Neg for Sign {
type Output = Sign;