aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-04-17 14:08:45 -0400
committerJesse Luehrs <doy@tozt.net>2021-04-17 14:08:45 -0400
commit516072b496e2cdd6e68230e6b500b5099bbe4b42 (patch)
tree714992bcf236ca5eaae0322ee972408789d41255
parent09b223b144bb9394fb56026f880cd7aaff081593 (diff)
downloadrbw-516072b496e2cdd6e68230e6b500b5099bbe4b42.tar.gz
rbw-516072b496e2cdd6e68230e6b500b5099bbe4b42.zip
use bounded iterators
new arrayvec version panics if the iterator overflows rather than just stopping
-rw-r--r--src/locked.rs7
-rw-r--r--src/pinentry.rs2
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(