summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-02-06 12:30:27 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-02-06 12:30:27 +0100
commitd6f553a2f3063d2995fbd91ed137cc876d7ecdc0 (patch)
treed191406c8d326ff15ae933b7985239c08fca3692
parent35b03999024955f68008d9ef5287cff753ed178b (diff)
openpgp: Remove the armored! macro.
- The packet parser now digests armored data, so there is no need to use this even in examples or tests, just use the appropriate .from_bytes(..) function. - Fixes #169.
-rw-r--r--examples/guide-exploring-openpgp.rs12
-rw-r--r--examples/guide-getting-started.rs8
-rw-r--r--examples/guide-the-keystore.rs10
-rw-r--r--guide/src/chapter_00.md8
-rw-r--r--openpgp/src/armor.rs33
-rw-r--r--openpgp/src/parse/stream.rs38
-rw-r--r--openpgp/src/serialize/stream.rs8
-rw-r--r--openpgp/src/tpk/mod.rs6
-rw-r--r--src/lib.rs9
9 files changed, 45 insertions, 87 deletions
diff --git a/examples/guide-exploring-openpgp.rs b/examples/guide-exploring-openpgp.rs
index 66b95588..409475ef 100644
--- a/examples/guide-exploring-openpgp.rs
+++ b/examples/guide-exploring-openpgp.rs
@@ -1,12 +1,11 @@
//! https://sequoia-pgp.org/guide/exploring-openpgp/
-#[macro_use] // For armored!
extern crate sequoia_openpgp as openpgp;
use openpgp::parse::Parse;
fn main() {
- let mut reader = armored!(
- "-----BEGIN PGP PUBLIC KEY BLOCK-----
+ let tpk =
+ b"-----BEGIN PGP PUBLIC KEY BLOCK-----
mQENBFpxtsABCADZcBa1Q3ZLZnju18o0+t8LoQuIIeyeUQ0H45y6xUqyrD5HSkVM
VGQs6IHLq70mAizBJ4VznUVqVOh/NhOlapXi6/TKpjHvttdg45o6Pgqa0Kx64luT
@@ -35,11 +34,10 @@ fn main() {
bGeT3KvlJlH5kthQ9shsmT14gYwGMR6rKpNUXmlpetkjqUK7pGVaHGgJWUZ9QPGU
awwPdWWvZSyXJAPZ9lC5sTKwMJDwIxILug==
=lAie
- -----END PGP PUBLIC KEY BLOCK-----"
- );
+ -----END PGP PUBLIC KEY BLOCK-----";
- // Parse message.
- let pile = openpgp::PacketPile::from_reader(&mut reader).unwrap();
+ // Parse the TPK.
+ let pile = openpgp::PacketPile::from_bytes(tpk).unwrap();
// Iterate over children.
for (i, p) in pile.children().enumerate() {
diff --git a/examples/guide-getting-started.rs b/examples/guide-getting-started.rs
index 940f9032..28be8a41 100644
--- a/examples/guide-getting-started.rs
+++ b/examples/guide-getting-started.rs
@@ -1,17 +1,15 @@
//! https://sequoia-pgp.org/guide/getting-started/
-#[macro_use] // For armored!
extern crate sequoia_openpgp as openpgp;
use std::io;
fn main() {
- let mut reader = armored!(
- "-----BEGIN PGP ARMORED FILE-----
+ let mut reader = openpgp::armor::Reader::from_bytes(
+ b"-----BEGIN PGP ARMORED FILE-----
SGVsbG8gd29ybGQhCg==
=XLsG
- -----END PGP ARMORED FILE-----"
- );
+ -----END PGP ARMORED FILE-----", None);
io::copy(&mut reader, &mut io::stdout()).unwrap();
}
diff --git a/examples/guide-the-keystore.rs b/examples/guide-the-keystore.rs
index dac57c85..b4c5b15b 100644
--- a/examples/guide-the-keystore.rs
+++ b/examples/guide-the-keystore.rs
@@ -1,14 +1,13 @@
//! https://sequoia-pgp.org/guide/the-keystore/
-#[macro_use] // For armored!
extern crate sequoia_openpgp as openpgp;
extern crate sequoia;
use sequoia::{core, store};
use openpgp::parse::Parse;
fn main() {
- let mut reader = armored!(
- "-----BEGIN PGP PUBLIC KEY BLOCK-----
+ let tpk =
+ b"-----BEGIN PGP PUBLIC KEY BLOCK-----
mQENBFpxtsABCADZcBa1Q3ZLZnju18o0+t8LoQuIIeyeUQ0H45y6xUqyrD5HSkVM
VGQs6IHLq70mAizBJ4VznUVqVOh/NhOlapXi6/TKpjHvttdg45o6Pgqa0Kx64luT
@@ -37,14 +36,13 @@ fn main() {
bGeT3KvlJlH5kthQ9shsmT14gYwGMR6rKpNUXmlpetkjqUK7pGVaHGgJWUZ9QPGU
awwPdWWvZSyXJAPZ9lC5sTKwMJDwIxILug==
=lAie
- -----END PGP PUBLIC KEY BLOCK-----"
- );
+ -----END PGP PUBLIC KEY BLOCK-----";
// Provide some context.
let ctx = core::Context::new("org.sequoia-pgp.guide").unwrap();
// Parse TPK.
- let tpk = openpgp::TPK::from_reader(&mut reader).unwrap();
+ let tpk = openpgp::TPK::from_bytes(tpk).unwrap();
// Open a store.
let store = store::Store::open(&ctx, "default").unwrap();
diff --git a/guide/src/chapter_00.md b/guide/src/chapter_00.md
index 3d440841..10570cf4 100644
--- a/guide/src/chapter_00.md
+++ b/guide/src/chapter_00.md
@@ -47,18 +47,16 @@ not populated `main` yet. Let's do that! Open `src/main.rs` with
your favorite editor, and enter:
```
-#[macro_use] // For armored!
extern crate sequoia_openpgp as openpgp;
use std::io;
fn main() {
- let mut reader = armored!(
- "-----BEGIN PGP ARMORED FILE-----
+ let mut reader = openpgp::armor::Reader::from_bytes(
+ b"-----BEGIN PGP ARMORED FILE-----
SGVsbG8gd29ybGQhCg==
=XLsG
- -----END PGP ARMORED FILE-----"
- );
+ -----END PGP ARMORED FILE-----", None);
io::copy(&mut reader, &mut io::stdout()).unwrap();
}
diff --git a/openpgp/src/armor.rs b/openpgp/src/armor.rs
index 72f80682..64cf5242 100644
--- a/openpgp/src/armor.rs
+++ b/openpgp/src/armor.rs
@@ -932,39 +932,6 @@ impl<'a> Read for Reader<'a> {
// XXX: impl BufferedReader for Reader
-#[macro_export]
-/// Constructs a reader from an armored string literal.
-///
-/// # Example
-///
-/// ```
-/// use std::io::Read;
-/// #[macro_use] extern crate sequoia_openpgp as openpgp;
-/// # use std::io::Result;
-/// # fn main() { f().unwrap(); }
-/// # fn f() -> Result<()> {
-///
-/// let mut reader = armored!(
-/// "-----BEGIN PGP ARMORED FILE-----
-///
-/// SGVsbG8gd29ybGQh
-/// =s4Gu
-/// -----END PGP ARMORED FILE-----"
-/// );
-///
-/// let mut content = String::new();
-/// reader.read_to_string(&mut content)?;
-/// assert_eq!(content, "Hello world!");
-/// # Ok(())
-/// # }
-/// ```
-macro_rules! armored {
- ($data:expr) => {{
- use ::std::io::Cursor;
- $crate::armor::Reader::new(Cursor::new(&$data), None)
- }};
-}
-
const CRC24_INIT: u32 = 0xB704CE;
const CRC24_POLY: u32 = 0x1864CFB;
diff --git a/openpgp/src/parse/stream.rs b/openpgp/src/parse/stream.rs
index 82e0d3ad..62a0fce9 100644
--- a/openpgp/src/parse/stream.rs
+++ b/openpgp/src/parse/stream.rs
@@ -73,7 +73,7 @@ const BUFFER_SIZE: usize = 25 * 1024 * 1024;
/// # Example
///
/// ```
-/// #[macro_use] extern crate sequoia_openpgp as openpgp;
+/// extern crate sequoia_openpgp as openpgp;
/// extern crate failure;
/// use std::io::Read;
/// use openpgp::{KeyID, TPK, Result};
@@ -92,18 +92,18 @@ const BUFFER_SIZE: usize = 25 * 1024 * 1024;
/// }
/// }
///
-/// let mut reader = armored!(
-/// "-----BEGIN PGP MESSAGE-----
+/// let message =
+/// b"-----BEGIN PGP MESSAGE-----
///
/// xA0DAAoWBpwMNI3YLBkByxJiAAAAAABIZWxsbyBXb3JsZCHCdQQAFgoAJwWCW37P
/// 8RahBI6MM/pGJjN5dtl5eAacDDSN2CwZCZAGnAw0jdgsGQAAeZQA/2amPbBXT96Q
/// O7PFms9DRuehsVVrFkaDtjN2WSxI4RGvAQDq/pzNdCMpy/Yo7AZNqZv5qNMtDdhE
/// b2WH5lghfKe/AQ==
/// =DjuO
-/// -----END PGP MESSAGE-----"
-/// );
+/// -----END PGP MESSAGE-----";
+///
/// let h = Helper {};
-/// let mut v = Verifier::from_reader(reader, h)?;
+/// let mut v = Verifier::from_bytes(message, h)?;
///
/// let mut content = Vec::new();
/// v.read_to_end(&mut content)
@@ -637,7 +637,7 @@ impl<'a> io::Read for Transformer<'a> {
/// # Example
///
/// ```
-/// #[macro_use] extern crate sequoia_openpgp as openpgp;
+/// extern crate sequoia_openpgp as openpgp;
/// extern crate failure;
/// use std::io::{self, Read};
/// use openpgp::{KeyID, TPK, Result};
@@ -656,18 +656,18 @@ impl<'a> io::Read for Transformer<'a> {
/// }
/// }
///
-/// let mut sig_reader = armored!(
-/// "-----BEGIN SIGNATURE-----
+/// let signature =
+/// b"-----BEGIN SIGNATURE-----
///
/// wnUEABYKACcFglt+z/EWoQSOjDP6RiYzeXbZeXgGnAw0jdgsGQmQBpwMNI3YLBkA
/// AHmUAP9mpj2wV0/ekDuzxZrPQ0bnobFVaxZGg7YzdlksSOERrwEA6v6czXQjKcv2
/// KOwGTamb+ajTLQ3YRG9lh+ZYIXynvwE=
/// =IJ29
-/// -----END SIGNATURE-----"
-/// );
-/// let mut data = io::Cursor::new("Hello World!");
+/// -----END SIGNATURE-----";
+///
+/// let data = b"Hello World!";
/// let h = Helper {};
-/// let mut v = DetachedVerifier::from_reader(sig_reader, data, h)?;
+/// let mut v = DetachedVerifier::from_bytes(signature, data, h)?;
///
/// let mut content = Vec::new();
/// v.read_to_end(&mut content)
@@ -756,7 +756,7 @@ impl DetachedVerifier {
/// # Example
///
/// ```
-/// #[macro_use] extern crate sequoia_openpgp as openpgp;
+/// extern crate sequoia_openpgp as openpgp;
/// extern crate failure;
/// use std::io::Read;
/// use openpgp::{KeyID, TPK, Result, packet::{Key, PKESK, SKESK}};
@@ -783,17 +783,17 @@ impl DetachedVerifier {
/// }
/// }
///
-/// let mut reader = armored!(
-/// "-----BEGIN PGP MESSAGE-----
+/// let message =
+/// b"-----BEGIN PGP MESSAGE-----
///
/// wy4ECQMIY5Zs8RerVcXp85UgoUKjKkevNPX3WfcS5eb7rkT9I6kw6N2eEc5PJUDh
/// 0j0B9mnPKeIwhp2kBHpLX/en6RfNqYauX9eSeia7aqsd/AOLbO9WMCLZS5d2LTxN
/// rwwb8Aggyukj13Mi0FF5
/// =OB/8
-/// -----END PGP MESSAGE-----"
-/// );
+/// -----END PGP MESSAGE-----";
+///
/// let h = Helper {};
-/// let mut v = Decryptor::from_reader(reader, h)?;
+/// let mut v = Decryptor::from_bytes(message, h)?;
///
/// let mut content = Vec::new();
/// v.read_to_end(&mut content)
diff --git a/openpgp/src/serialize/stream.rs b/openpgp/src/serialize/stream.rs
index 74b713af..a1e74622 100644
--- a/openpgp/src/serialize/stream.rs
+++ b/openpgp/src/serialize/stream.rs
@@ -790,7 +790,7 @@ impl<'a> Encryptor<'a> {
///
/// ```
/// use std::io::Write;
- /// #[macro_use] extern crate sequoia_openpgp as openpgp; // For armored!
+ /// extern crate sequoia_openpgp as openpgp;
/// use openpgp::constants::DataFormat;
/// use openpgp::serialize::stream::{
/// Message, Encryptor, EncryptionMode, LiteralWriter,
@@ -799,9 +799,9 @@ impl<'a> Encryptor<'a> {
/// # use openpgp::parse::Parse;
/// # fn main() { f().unwrap(); }
/// # fn f() -> Result<()> {
- /// let tpk = openpgp::TPK::from_reader(armored!(
+ /// let tpk = openpgp::TPK::from_bytes(
/// # // We do some acrobatics here to abbreviate the TPK.
- /// "-----BEGIN PGP PUBLIC KEY BLOCK-----
+ /// b"-----BEGIN PGP PUBLIC KEY BLOCK-----
///
/// mQENBFpxtsABCADZcBa1Q3ZLZnju18o0+t8LoQuIIeyeUQ0H45y6xUqyrD5HSkVM
/// # VGQs6IHLq70mAizBJ4VznUVqVOh/NhOlapXi6/TKpjHvttdg45o6Pgqa0Kx64luT
@@ -835,7 +835,7 @@ impl<'a> Encryptor<'a> {
/// ...
/// -----END PGP PUBLIC KEY BLOCK-----"
/// # */
- /// )).unwrap();
+ /// ).unwrap();
///
/// let mut o = vec![];
/// let message = Message::new(&mut o);
diff --git a/openpgp/src/tpk/mod.rs b/openpgp/src/tpk/mod.rs
index 7ac044f6..1bbd8cea 100644
--- a/openpgp/src/tpk/mod.rs
+++ b/openpgp/src/tpk/mod.rs
@@ -3659,7 +3659,7 @@ mod test {
#[test]
fn issue_120() {
- let reader = armored!("
+ let tpk = b"
-----BEGIN PGP ARMORED FILE-----
xcBNBFoVcvoBCACykTKOJddF8SSUAfCDHk86cNTaYnjCoy72rMgWJsrMLnz/V16B
@@ -3690,7 +3690,7 @@ AeGalQHjc5kAZu5R76Mwt06MEQ/HL1pIvufTFxkr/SzIv8Ih7Kexb0IrybmfD351
Pu1xwz57O4zo1VYf6TqHJzVC3OMvMUM2hhdecMUe5x6GorNaj6g=
=1Vzu
-----END PGP ARMORED FILE-----
-");
- assert!(TPK::from_reader(reader).is_err());
+";
+ assert!(TPK::from_bytes(tpk).is_err());
}
}
diff --git a/src/lib.rs b/src/lib.rs
index 148e1f3d..97cddbab 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -7,18 +7,17 @@
//!
//! ```
//! use std::io::Read;
-//! #[macro_use] extern crate sequoia_openpgp as openpgp;
+//! extern crate sequoia_openpgp as openpgp;
//! # use std::io::Result;
//! # fn main() { f().unwrap(); }
//! # fn f() -> Result<()> {
//!
-//! let mut reader = armored!(
-//! "-----BEGIN PGP ARMORED FILE-----
+//! let mut reader = openpgp::armor::Reader::from_bytes(
+//! b"-----BEGIN PGP ARMORED FILE-----
//!
//! SGVsbG8gd29ybGQh
//! =s4Gu
-//! -----END PGP ARMORED FILE-----"
-//! );
+//! -----END PGP ARMORED FILE-----", None);
//!
//! let mut content = String::new();
//! reader.read_to_string(&mut content)?;