summaryrefslogtreecommitdiffstats
path: root/guide
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2019-08-12 13:39:14 +0200
committerNeal H. Walfield <neal@pep.foundation>2019-08-23 19:15:13 +0200
commit05cf492f3417fd61f6b1e7dc4913a16fd5f201ea (patch)
treeeca0c2e0481e10b54884a766e7e864020089fe84 /guide
parent102dea398e920e91b34e5602033c2e7e53c50bb1 (diff)
openpgp: Use marker types to denote a Key's type.
- In addition to providing some added protection, this allows us to implement 'From<Key<_, _>> for Packet'.
Diffstat (limited to 'guide')
-rw-r--r--guide/src/chapter_01.md24
-rw-r--r--guide/src/chapter_02.md24
2 files changed, 32 insertions, 16 deletions
diff --git a/guide/src/chapter_01.md b/guide/src/chapter_01.md
index 8d973e07..d82d8bb0 100644
--- a/guide/src/chapter_01.md
+++ b/guide/src/chapter_01.md
@@ -14,6 +14,7 @@ use std::io::{self, Write};
extern crate failure;
extern crate sequoia_openpgp as openpgp;
use openpgp::serialize::stream::*;
+use openpgp::packet::prelude::*;
use openpgp::parse::stream::*;
const MESSAGE: &'static str = "дружба";
@@ -49,8 +50,9 @@ fn main() {
# fn sign(sink: &mut Write, plaintext: &str, tsk: &openpgp::TPK)
# -> openpgp::Result<()> {
# // Get the keypair to do the signing from the TPK.
-# let mut keypair = tsk.keys_valid().signing_capable().nth(0).unwrap().2
-# .clone().into_keypair()?;
+# let key : key::UnspecifiedSecret
+# = tsk.keys_valid().signing_capable().nth(0).unwrap().2.clone().into();
+# let mut keypair = key.into_keypair()?;
#
# // Start streaming an OpenPGP message.
# let message = Message::new(sink);
@@ -156,6 +158,7 @@ create it:
# extern crate sequoia_openpgp as openpgp;
# use openpgp::serialize::stream::*;
# use openpgp::parse::stream::*;
+# use openpgp::packet::prelude::*;
#
# const MESSAGE: &'static str = "дружба";
#
@@ -190,8 +193,9 @@ fn generate() -> openpgp::Result<openpgp::TPK> {
# fn sign(sink: &mut Write, plaintext: &str, tsk: &openpgp::TPK)
# -> openpgp::Result<()> {
# // Get the keypair to do the signing from the TPK.
-# let mut keypair = tsk.keys_valid().signing_capable().nth(0).unwrap().2
-# .clone().into_keypair()?;
+# let key : key::UnspecifiedSecret
+# = tsk.keys_valid().signing_capable().nth(0).unwrap().2.clone().into();
+# let mut keypair = key.into_keypair()?;
#
# // Start streaming an OpenPGP message.
# let message = Message::new(sink);
@@ -296,6 +300,7 @@ implements [`io::Write`], and we simply write the plaintext to it.
# extern crate failure;
# extern crate sequoia_openpgp as openpgp;
# use openpgp::serialize::stream::*;
+# use openpgp::packet::prelude::*;
# use openpgp::parse::stream::*;
#
# const MESSAGE: &'static str = "дружба";
@@ -331,8 +336,9 @@ implements [`io::Write`], and we simply write the plaintext to it.
fn sign(sink: &mut Write, plaintext: &str, tsk: &openpgp::TPK)
-> openpgp::Result<()> {
// Get the keypair to do the signing from the TPK.
- let mut keypair = tsk.keys_valid().signing_capable().nth(0).unwrap().2
- .clone().into_keypair()?;
+ let key : key::UnspecifiedSecret
+ = tsk.keys_valid().signing_capable().nth(0).unwrap().2.clone().into();
+ let mut keypair = key.into_keypair()?;
// Start streaming an OpenPGP message.
let message = Message::new(sink);
@@ -448,6 +454,7 @@ Verified data can be read from this using [`io::Read`].
# extern crate failure;
# extern crate sequoia_openpgp as openpgp;
# use openpgp::serialize::stream::*;
+# use openpgp::packet::prelude::*;
# use openpgp::parse::stream::*;
#
# const MESSAGE: &'static str = "дружба";
@@ -483,8 +490,9 @@ Verified data can be read from this using [`io::Read`].
# fn sign(sink: &mut Write, plaintext: &str, tsk: &openpgp::TPK)
# -> openpgp::Result<()> {
# // Get the keypair to do the signing from the TPK.
-# let mut keypair = tsk.keys_valid().signing_capable().nth(0).unwrap().2
-# .clone().into_keypair()?;
+# let key : key::UnspecifiedSecret
+# = tsk.keys_valid().signing_capable().nth(0).unwrap().2.clone().into();
+# let mut keypair = key.into_keypair()?;
#
# // Start streaming an OpenPGP message.
# let message = Message::new(sink);
diff --git a/guide/src/chapter_02.md b/guide/src/chapter_02.md
index b6463033..7c564ff0 100644
--- a/guide/src/chapter_02.md
+++ b/guide/src/chapter_02.md
@@ -15,6 +15,7 @@ extern crate sequoia_openpgp as openpgp;
use openpgp::crypto::SessionKey;
use openpgp::constants::SymmetricAlgorithm;
use openpgp::serialize::stream::*;
+use openpgp::packet::prelude::*;
use openpgp::parse::stream::*;
const MESSAGE: &'static str = "дружба";
@@ -118,9 +119,10 @@ fn main() {
# where D: FnMut(SymmetricAlgorithm, &SessionKey) -> openpgp::Result<()>
# {
# // The encryption key is the first and only subkey.
-# let key = self.secret.subkeys().nth(0)
+# let key : key::UnspecifiedSecret
+# = self.secret.subkeys().nth(0)
# .map(|binding| binding.key().clone())
-# .unwrap();
+# .unwrap().into();
#
# // The secret key is not encrypted.
# let mut pair = key.into_keypair().unwrap();
@@ -149,6 +151,7 @@ create it:
# use openpgp::crypto::SessionKey;
# use openpgp::constants::SymmetricAlgorithm;
# use openpgp::serialize::stream::*;
+# use openpgp::packet::prelude::*;
# use openpgp::parse::stream::*;
#
# const MESSAGE: &'static str = "дружба";
@@ -252,9 +255,10 @@ fn generate() -> openpgp::Result<openpgp::TPK> {
# where D: FnMut(SymmetricAlgorithm, &SessionKey) -> openpgp::Result<()>
# {
# // The encryption key is the first and only subkey.
-# let key = self.secret.subkeys().nth(0)
+# let key : key::UnspecifiedSecret
+# = self.secret.subkeys().nth(0)
# .map(|binding| binding.key().clone())
-# .unwrap();
+# .unwrap().into();
#
# // The secret key is not encrypted.
# let mut pair = key.into_keypair().unwrap();
@@ -283,6 +287,7 @@ implements [`io::Write`], and we simply write the plaintext to it.
# use openpgp::crypto::SessionKey;
# use openpgp::constants::SymmetricAlgorithm;
# use openpgp::serialize::stream::*;
+# use openpgp::packet::prelude::*;
# use openpgp::parse::stream::*;
#
# const MESSAGE: &'static str = "дружба";
@@ -386,9 +391,10 @@ fn encrypt(sink: &mut Write, plaintext: &str, recipient: &openpgp::TPK)
# where D: FnMut(SymmetricAlgorithm, &SessionKey) -> openpgp::Result<()>
# {
# // The encryption key is the first and only subkey.
-# let key = self.secret.subkeys().nth(0)
+# let key : key::UnspecifiedSecret
+# = self.secret.subkeys().nth(0)
# .map(|binding| binding.key().clone())
-# .unwrap();
+# .unwrap().into();
#
# // The secret key is not encrypted.
# let mut pair = key.into_keypair().unwrap();
@@ -431,6 +437,7 @@ Decrypted data can be read from this using [`io::Read`].
# use openpgp::crypto::SessionKey;
# use openpgp::constants::SymmetricAlgorithm;
# use openpgp::serialize::stream::*;
+# use openpgp::packet::prelude::*;
# use openpgp::parse::stream::*;
#
# const MESSAGE: &'static str = "дружба";
@@ -534,9 +541,10 @@ impl<'a> DecryptionHelper for Helper<'a> {
where D: FnMut(SymmetricAlgorithm, &SessionKey) -> openpgp::Result<()>
{
// The encryption key is the first and only subkey.
- let key = self.secret.subkeys().nth(0)
+ let key : key::UnspecifiedSecret
+ = self.secret.subkeys().nth(0)
.map(|binding| binding.key().clone())
- .unwrap();
+ .unwrap().into();
// The secret key is not encrypted.
let mut pair = key.into_keypair().unwrap();