Implement zeroing memory for wallet password (#2229)

Testing ergonomics, if this approach is acceptable I'll implement it for other sensitive parts.
This commit is contained in:
hashmap
2018-12-28 23:12:59 +01:00
committed by Ignotus Peverell
parent 69800bb6ec
commit 80f7ae678a
5 changed files with 36 additions and 3 deletions
+1 -1
View File
@@ -43,7 +43,7 @@ pub mod secp_static;
pub use crate::secp_static::static_secp_instance;
pub mod types;
pub use crate::types::{LogLevel, LoggingConfig};
pub use crate::types::{LogLevel, LoggingConfig, ZeroingString};
pub mod macros;
+24
View File
@@ -64,3 +64,27 @@ impl Default for LoggingConfig {
}
}
}
use std::ops::Deref;
use zeroize::Zeroize;
pub struct ZeroingString(String);
impl Drop for ZeroingString {
fn drop(&mut self) {
self.0.zeroize();
}
}
impl From<&str> for ZeroingString {
fn from(s: &str) -> Self {
ZeroingString(String::from(s))
}
}
impl Deref for ZeroingString {
type Target = str;
fn deref(&self) -> &str {
&self.0
}
}