diff options
Diffstat (limited to 'ipc/src/sexp.rs')
-rw-r--r-- | ipc/src/sexp.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/ipc/src/sexp.rs b/ipc/src/sexp.rs index 8ff75eca..7a8ce18c 100644 --- a/ipc/src/sexp.rs +++ b/ipc/src/sexp.rs @@ -396,17 +396,22 @@ impl String_ { /// Creates a Protected memory region from this String. /// /// Securely erases the contents of the original String. - pub fn into_protected(mut self) -> Protected { + pub fn into_protected(self) -> Protected { let r = Protected::from(&self.0[..]); + drop(self); // Securely erases this string. + r + } +} + +impl Drop for String_ { + fn drop(&mut self) { unsafe { memsec::memzero(self.0.as_mut_ptr(), self.0.len()); if let Some(p) = self.1.as_mut() { memsec::memzero(p.as_mut_ptr(), p.len()); } } - r } - } impl From<&str> for String_ { |