summaryrefslogtreecommitdiffstats
path: root/openpgp/src/crypto/mod.rs
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-12-18 17:29:58 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-12-19 10:32:18 +0100
commit8799d48c5525ebe564070c4c3cd19df1b866e5ca (patch)
tree7c025dafa04f3140294e38127d531575cc12d554 /openpgp/src/crypto/mod.rs
parent48cc5f28b158f853c1755ccadb958ce20d8a9007 (diff)
openpgp: Prepare to encrypt passwords.
- Remove direct access, provide Password::map instead.
Diffstat (limited to 'openpgp/src/crypto/mod.rs')
-rw-r--r--openpgp/src/crypto/mod.rs23
1 files changed, 9 insertions, 14 deletions
diff --git a/openpgp/src/crypto/mod.rs b/openpgp/src/crypto/mod.rs
index 667f2d82..f02657df 100644
--- a/openpgp/src/crypto/mod.rs
+++ b/openpgp/src/crypto/mod.rs
@@ -116,20 +116,6 @@ impl fmt::Debug for SessionKey {
#[derive(Clone, PartialEq, Eq)]
pub struct Password(mem::Protected);
-impl AsRef<[u8]> for Password {
- fn as_ref(&self) -> &[u8] {
- &self.0
- }
-}
-
-impl Deref for Password {
- type Target = [u8];
-
- fn deref(&self) -> &Self::Target {
- &self.0
- }
-}
-
impl From<Vec<u8>> for Password {
fn from(v: Vec<u8>) -> Self {
Password(v.into())
@@ -166,6 +152,15 @@ impl fmt::Debug for Password {
}
}
+impl Password {
+ /// Maps the given function over the password.
+ pub fn map<F, T>(&self, mut fun: F) -> T
+ where F: FnMut(&mem::Protected) -> T
+ {
+ fun(&self.0)
+ }
+}
+
/// Hash the specified file.
///