diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/locked.rs | 7 | ||||
-rw-r--r-- | src/pinentry.rs | 2 |
2 files changed, 7 insertions, 2 deletions
diff --git a/src/locked.rs b/src/locked.rs index aecc54d..611e57e 100644 --- a/src/locked.rs +++ b/src/locked.rs @@ -30,6 +30,11 @@ impl Vec { self.data.as_mut_slice() } + pub fn zero(&mut self) { + self.truncate(0); + self.data.extend(std::iter::repeat(0).take(LEN)) + } + pub fn extend(&mut self, it: impl Iterator<Item = u8>) { self.data.extend(it); } @@ -41,7 +46,7 @@ impl Vec { impl Drop for Vec { fn drop(&mut self) { - self.extend(std::iter::repeat(0)); + self.zero(); self.data.as_mut().zeroize(); } } diff --git a/src/pinentry.rs b/src/pinentry.rs index b055b77..d62d4b2 100644 --- a/src/pinentry.rs +++ b/src/pinentry.rs @@ -53,7 +53,7 @@ pub async fn getpin( drop(stdin); let mut buf = crate::locked::Vec::new(); - buf.extend(std::iter::repeat(0)); + buf.zero(); // unwrap is safe because we specified stdout as piped in the command opts // above let len = read_password( |