feat: add zeroize feature
This commit is contained in:
parent
666cdc6f2c
commit
5fbee1da4d
12
Cargo.toml
12
Cargo.toml
@ -44,15 +44,16 @@ version = "0.5"
|
||||
default-features = false
|
||||
features = ["std"]
|
||||
|
||||
[dependencies.zeroize]
|
||||
version = "0.5"
|
||||
optional = true
|
||||
|
||||
[dependencies.serde]
|
||||
optional = true
|
||||
version = "1.0"
|
||||
default-features = false
|
||||
features = ["std"]
|
||||
|
||||
[dev-dependencies.serde_test]
|
||||
version = "1.0"
|
||||
|
||||
[dependencies.lazy_static]
|
||||
version = "1.2.0"
|
||||
|
||||
@ -63,9 +64,12 @@ version = "1.2.7"
|
||||
criterion = "0.2"
|
||||
rand_chacha = "0.1"
|
||||
|
||||
[dev-dependencies.serde_test]
|
||||
version = "1.0"
|
||||
|
||||
[features]
|
||||
default = ["std", "i128", "u64_digit"]
|
||||
i128 = ["num-integer/i128", "num-traits/i128"]
|
||||
std = ["num-integer/std", "num-traits/std", "smallvec/std"]
|
||||
u64_digit = []
|
||||
prime = ["rand"]
|
||||
prime = ["rand"]
|
||||
|
@ -17,6 +17,9 @@ use std::{i64, u64};
|
||||
#[cfg(feature = "serde")]
|
||||
use serde;
|
||||
|
||||
#[cfg(feature = "zeroize")]
|
||||
use zeroize::Zeroize;
|
||||
|
||||
use integer::{Integer, Roots};
|
||||
use num_traits::{
|
||||
CheckedAdd, CheckedDiv, CheckedMul, CheckedSub, FromPrimitive, Num, One, Pow, Signed,
|
||||
@ -119,6 +122,15 @@ pub struct BigInt {
|
||||
pub(crate) data: BigUint,
|
||||
}
|
||||
|
||||
#[cfg(feature = "zeroize")]
|
||||
impl Zeroize for BigInt {
|
||||
fn zeroize(&mut self) {
|
||||
// TODO: Figure out how to better clear the sign.
|
||||
self.sign = Sign::NoSign;
|
||||
self.data.zeroize();
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the magnitude of a `BigInt`.
|
||||
///
|
||||
/// This is in a private module, pseudo pub(crate)
|
||||
|
@ -18,6 +18,9 @@ use std::{u64, u8};
|
||||
#[cfg(feature = "serde")]
|
||||
use serde;
|
||||
|
||||
#[cfg(feature = "zeroize")]
|
||||
use zeroize::Zeroize;
|
||||
|
||||
use integer::{Integer, Roots};
|
||||
use num_traits::{
|
||||
CheckedAdd, CheckedDiv, CheckedMul, CheckedSub, Float, FromPrimitive, Num, One, Pow,
|
||||
@ -50,6 +53,13 @@ pub struct BigUint {
|
||||
pub(crate) data: SmallVec<[BigDigit; VEC_SIZE]>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "zeroize")]
|
||||
impl Zeroize for BigUint {
|
||||
fn zeroize(&mut self) {
|
||||
self.data.zeroize();
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for BigUint {
|
||||
#[inline]
|
||||
fn eq(&self, other: &BigUint) -> bool {
|
||||
|
@ -90,6 +90,9 @@ extern crate rand;
|
||||
#[cfg(feature = "serde")]
|
||||
extern crate serde;
|
||||
|
||||
#[cfg(feature = "zeroize")]
|
||||
extern crate zeroize;
|
||||
|
||||
#[macro_use]
|
||||
extern crate smallvec;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user