diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2023-03-07 10:59:33 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2023-03-07 11:50:31 +0100 |
commit | de5f99ba931d6d9d21450e0aa16b793bff1222e1 (patch) | |
tree | aa87e60c55c1d9004a97826b8a71b00fb0acbef4 /openpgp/src/crypto | |
parent | dd6fb556fa557e79b167d43b021e45c35db57821 (diff) |
openpgp: New constructor to allocate protected memory.
Diffstat (limited to 'openpgp/src/crypto')
-rw-r--r-- | openpgp/src/crypto/mem.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/openpgp/src/crypto/mem.rs b/openpgp/src/crypto/mem.rs index f8a963f0..fc5de59b 100644 --- a/openpgp/src/crypto/mem.rs +++ b/openpgp/src/crypto/mem.rs @@ -85,6 +85,16 @@ impl Hash for Protected { } impl Protected { + /// Allocates a chunk of protected memory. + /// + /// Effective protection of sensitive values requires avoiding any + /// copying and reallocations. Therefore, it is required to + /// provide the size upfront at allocation time, then copying the + /// secrets into this protected memory region. + pub fn new(size: usize) -> Protected { + vec![0; size].into_boxed_slice().into() + } + /// Converts to a buffer for modification. /// /// Don't expose `Protected` values unless you know what you're doing. |