summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-03-30 17:14:16 +0200
committerJustus Winter <justus@sequoia-pgp.org>2020-03-30 17:14:16 +0200
commitf06d3e34c032049ba1782a7647baa77667d3afee (patch)
treea89c4574484d975479fc40fa356171898258817d
parentbe0709040b09b5c9acb4b03c647b313ba9924f8d (diff)
openpgp: New doctest for crypto::mem::{Protected,Encrypted}.
-rw-r--r--openpgp/src/crypto/mem.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/openpgp/src/crypto/mem.rs b/openpgp/src/crypto/mem.rs
index 780db044..ee2af859 100644
--- a/openpgp/src/crypto/mem.rs
+++ b/openpgp/src/crypto/mem.rs
@@ -12,6 +12,17 @@ use memsec;
///
/// The memory is guaranteed not to be copied around, and is cleared
/// when the object is dropped.
+///
+/// ```rust
+/// use sequoia_openpgp::crypto::mem::Protected;
+///
+/// {
+/// let p: Protected = vec![0, 1, 2].into();
+/// assert_eq!(p.as_ref(), &[0, 1, 2]);
+/// }
+///
+/// // p is cleared once it goes out of scope.
+/// ```
#[derive(Clone)]
pub struct Protected(Pin<Box<[u8]>>);
@@ -121,6 +132,19 @@ impl fmt::Debug for Protected {
/// This kind of protection was pioneered by OpenSSH. The commit
/// adding it can be found
/// [here](https://marc.info/?l=openbsd-cvs&m=156109087822676).
+///
+/// # Example
+///
+/// ```rust
+/// use sequoia_openpgp::crypto::mem::Encrypted;
+///
+/// let e = Encrypted::new(vec![0, 1, 2].into());
+/// e.map(|p| {
+/// // e is temporarily decrypted and made available to the closure.
+/// assert_eq!(p.as_ref(), &[0, 1, 2]);
+/// // p is cleared once the function returns.
+/// });
+/// ```
#[derive(Clone, Debug)]
pub struct Encrypted {
ciphertext: Protected,