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:
committed by
Ignotus Peverell
parent
69800bb6ec
commit
80f7ae678a
+1
-1
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user