-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start, support the zeroize crate for data security
* implement a fn zeroize method on Repr that's derived from the zeroize crate * add proptest and fuzz coverage for the new feature
- Loading branch information
Showing
6 changed files
with
116 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,5 @@ mod serde; | |
mod smallvec; | ||
#[cfg(feature = "sqlx")] | ||
mod sqlx; | ||
#[cfg(feature = "zeroize")] | ||
mod zeroize; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//! Implements the [`zeroize::Zeroize`] trait for [`CompactString`] | ||
use crate::CompactString; | ||
use zeroize::Zeroize; | ||
|
||
#[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))] | ||
impl Zeroize for CompactString { | ||
fn zeroize(&mut self) { | ||
self.0.zeroize(); | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use alloc::string::String; | ||
use test_strategy::proptest; | ||
|
||
use super::*; | ||
use crate::tests::rand_unicode; | ||
|
||
#[test] | ||
fn smoketest_zeroize() { | ||
let mut short = CompactString::from("hello"); | ||
short.zeroize(); | ||
assert_eq!(short, "\0\0\0\0\0"); | ||
|
||
let mut long = CompactString::from("I am a long string that will be on the heap"); | ||
long.zeroize(); | ||
assert_eq!(long, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"); | ||
assert!(long.is_heap_allocated()); | ||
} | ||
|
||
#[proptest] | ||
#[cfg_attr(miri, ignore)] | ||
fn proptest_zeroize(#[strategy(rand_unicode())] s: String) { | ||
let mut compact = CompactString::new(s.clone()); | ||
let mut control = s.clone(); | ||
|
||
compact.zeroize(); | ||
control.zeroize(); | ||
|
||
assert_eq!(compact, control); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters