diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2018-12-05 14:15:10 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2018-12-05 14:15:10 +0100 |
commit | b1abf63f5a4f446b187f80b5f48be1e7f3021386 (patch) | |
tree | e3784b4f4c40d336b2d20b59d2e7da916ccf5b29 | |
parent | f54be56633d0d7bcaacbba0652d0b10e2696fdca (diff) |
openpgp: Drop openpgp::Reader.
- Now that the packet parser transparently strips armor, this reader
is no longer necessary.
-rw-r--r-- | openpgp/examples/notarize.rs | 4 | ||||
-rw-r--r-- | openpgp/src/lib.rs | 3 | ||||
-rw-r--r-- | openpgp/src/reader.rs | 56 | ||||
-rw-r--r-- | sqv/src/sqv.rs | 6 | ||||
-rw-r--r-- | tool/src/commands/mod.rs | 9 | ||||
-rw-r--r-- | tool/src/sq.rs | 23 | ||||
-rw-r--r-- | tool/tests/sq-sign.rs | 38 |
7 files changed, 25 insertions, 114 deletions
diff --git a/openpgp/examples/notarize.rs b/openpgp/examples/notarize.rs index 4893a077..3138f478 100644 --- a/openpgp/examples/notarize.rs +++ b/openpgp/examples/notarize.rs @@ -45,9 +45,7 @@ fn main() { // Create a parser for the message to be notarized. let mut input = io::stdin(); let mut ppr - = openpgp::parse::PacketParser::from_reader( - openpgp::Reader::from_reader(&mut input) - .expect("Failed to build reader")) + = openpgp::parse::PacketParser::from_reader(&mut input) .expect("Failed to build parser"); while let PacketParserResult::Some(mut pp) = ppr { diff --git a/openpgp/src/lib.rs b/openpgp/src/lib.rs index 7ae66728..753aa6c7 100644 --- a/openpgp/src/lib.rs +++ b/openpgp/src/lib.rs @@ -111,9 +111,6 @@ pub mod parse; pub mod tpk; pub mod serialize; -mod reader; -pub use reader::Reader; - mod packet_pile; pub mod message; diff --git a/openpgp/src/reader.rs b/openpgp/src/reader.rs deleted file mode 100644 index a6abc01f..00000000 --- a/openpgp/src/reader.rs +++ /dev/null @@ -1,56 +0,0 @@ -use buffered_reader::{ - BufferedReader, BufferedReaderGeneric, BufferedReaderMemory, - BufferedReaderFile, -}; -use std::io; -use std::path::Path; - -use CTB; -use Result; -use armor; - -/// Transparently strips ASCII Armor. -/// -/// This reader detects and strips ASCII Armor. -pub struct Reader<'a>(Box<'a + BufferedReader<()>>); - -impl<'a> Reader<'a> { - fn from_buffered_reader(mut br: Box<'a + BufferedReader<()>>) - -> Result<Self> { - let ptag = br.data_hard(1)?[0]; - if let Ok(_) = CTB::from_ptag(ptag) { - Ok(Reader(br)) - } else { - Ok(Reader(Box::new(BufferedReaderGeneric::new( - armor::Reader::from_buffered_reader(br, None), - None)))) - } - } - - /// Creates a `Reader` from an `io::Read`er. - pub fn from_reader<R>(reader: R) -> Result<Self> - where R: io::Read + 'a - { - Self::from_buffered_reader( - Box::new(BufferedReaderGeneric::new(reader, None))) - } - - /// Creates a `Reader` from a file. - pub fn from_file<P>(path: P) -> Result<Self> - where P: AsRef<Path> - { - Self::from_buffered_reader(Box::new(BufferedReaderFile::open(path)?)) - } - - /// Creates a `Reader` from a buffer. - pub fn from_bytes(bytes: &'a [u8]) -> Result<Self> { - Self::from_buffered_reader( - Box::new(BufferedReaderMemory::new(bytes))) - } -} - -impl<'a> io::Read for Reader<'a> { - fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { - self.0.read(buf) - } -} diff --git a/sqv/src/sqv.rs b/sqv/src/sqv.rs index 567f6427..963fcf1b 100644 --- a/sqv/src/sqv.rs +++ b/sqv/src/sqv.rs @@ -66,8 +66,7 @@ fn real_main() -> Result<(), failure::Error> { // .unwrap() is safe, because "sig-file" is required. let sig_file = matches.value_of_os("sig-file").unwrap(); - let mut ppr = PacketParser::from_reader( - openpgp::Reader::from_file(sig_file)?)?; + let mut ppr = PacketParser::from_file(sig_file)?; let mut sigs_seen = HashSet::new(); let mut sigs : Vec<(Signature, KeyID, Option<TPK>)> = Vec::new(); @@ -161,8 +160,7 @@ fn real_main() -> Result<(), failure::Error> { .expect("No keyring specified.") { // Load the keyring. - let tpks : Vec<TPK> = TPKParser::from_reader( - openpgp::Reader::from_file(filename)?)? + let tpks : Vec<TPK> = TPKParser::from_file(filename)? .unvalidated_tpk_filter(|tpk, _| { for &(_, ref issuer, _) in &sigs { if tpk_has_key(tpk, issuer) { diff --git a/tool/src/commands/mod.rs b/tool/src/commands/mod.rs index 8bc233ea..a92b84ef 100644 --- a/tool/src/commands/mod.rs +++ b/tool/src/commands/mod.rs @@ -112,9 +112,8 @@ fn sign_data(input: &mut io::Read, output_path: Option<&str>, if detached && append && output_path.is_some() { // First, read the existing signatures. let mut sigs = Vec::new(); - let reader = openpgp::Reader::from_file(output_path.unwrap())?; - let mut ppr - = openpgp::parse::PacketParser::from_reader(reader)?; + let mut ppr = + openpgp::parse::PacketParser::from_file(output_path.unwrap())?; while let PacketParserResult::Some(mut pp) = ppr { let (packet, ppr_tmp) = pp.recurse()?; @@ -213,9 +212,7 @@ fn sign_message(input: &mut io::Read, output_path: Option<&str>, // Create a parser for the message to be notarized. let mut ppr - = openpgp::parse::PacketParser::from_reader( - openpgp::Reader::from_reader(input) - .context("Failed to build reader")?) + = openpgp::parse::PacketParser::from_reader(input) .context("Failed to build parser")?; // Once we see a signature, we can no longer strip compression. diff --git a/tool/src/sq.rs b/tool/src/sq.rs index 4b229fe6..0720b5a1 100644 --- a/tool/src/sq.rs +++ b/tool/src/sq.rs @@ -51,11 +51,7 @@ fn load_tpks<'a, I>(files: I) -> openpgp::Result<Vec<TPK>> { let mut tpks = vec![]; for f in files { - tpks.push(TPK::from_reader( - // Use an openpgp::Reader so that we accept both armored - // and plain PGP data. - openpgp::Reader::from_file(f) - .context(format!("Failed to open key file {:?}", f))?) + tpks.push(TPK::from_file(f) .context(format!("Failed to load key from file {:?}", f))?); } Ok(tpks) @@ -99,9 +95,8 @@ fn real_main() -> Result<(), failure::Error> { match matches.subcommand() { ("decrypt", Some(m)) => { - let input = open_or_stdin(m.value_of("input"))?; + let mut input = open_or_stdin(m.value_of("input"))?; let mut output = create_or_stdout(m.value_of("output"))?; - let mut input = openpgp::Reader::from_reader(input)?; let signatures: usize = m.value_of("signatures").unwrap_or("0").parse()?; let tpks = m.values_of("public-key-file") @@ -210,14 +205,13 @@ fn real_main() -> Result<(), failure::Error> { }, ("dump", Some(m)) => { - let input = open_or_stdin(m.value_of("input"))?; + let mut input = open_or_stdin(m.value_of("input"))?; let mut output = create_or_stdout(m.value_of("output"))?; - let mut input = openpgp::Reader::from_reader(input)?; commands::dump(&mut input, &mut output, m.is_present("mpis"), m.is_present("hex"))?; }, ("split", Some(m)) => { - let input = open_or_stdin(m.value_of("input"))?; + let mut input = open_or_stdin(m.value_of("input"))?; let prefix = // The prefix is either specified explicitly... m.value_of("prefix").map(|p| p.to_owned()) @@ -232,7 +226,6 @@ fn real_main() -> Result<(), failure::Error> { .unwrap_or(String::from("output")) // ... finally, add a hyphen to the derived prefix. + "-"); - let mut input = openpgp::Reader::from_reader(input)?; commands::split(&mut input, &prefix)?; }, ("keyserver", Some(m)) => { @@ -269,9 +262,7 @@ fn real_main() -> Result<(), failure::Error> { .context("Failed to serialize key")?; }, ("send", Some(m)) => { - let input = open_or_stdin(m.value_of("input"))?; - let mut input = openpgp::Reader::from_reader(input)?; - + let mut input = open_or_stdin(m.value_of("input"))?; let tpk = TPK::from_reader(&mut input). context("Malformed key")?; @@ -300,9 +291,7 @@ fn real_main() -> Result<(), failure::Error> { ("import", Some(m)) => { let label = m.value_of("label").unwrap(); help_warning(label); - let input = open_or_stdin(m.value_of("input"))?; - let mut input = openpgp::Reader::from_reader(input)?; - + let mut input = open_or_stdin(m.value_of("input"))?; let tpk = TPK::from_reader(&mut input)?; store.import(label, &tpk)?; }, diff --git a/tool/tests/sq-sign.rs b/tool/tests/sq-sign.rs index 0089a9a8..696f662e 100644 --- a/tool/tests/sq-sign.rs +++ b/tool/tests/sq-sign.rs @@ -7,7 +7,7 @@ extern crate tempfile; use tempfile::TempDir; extern crate sequoia_openpgp as openpgp; -use openpgp::{Packet, PacketPile, Reader, TPK}; +use openpgp::{Packet, PacketPile, TPK}; use openpgp::constants::{CompressionAlgorithm, DataFormat, SignatureType}; use openpgp::serialize::stream::{Message, Signer, Compressor, LiteralWriter}; @@ -35,8 +35,7 @@ fn sq_sign() { // Check that the content is sane. let packets: Vec<Packet> = - PacketPile::from_reader(Reader::from_file(&sig).unwrap()) - .unwrap().into_children().collect(); + PacketPile::from_file(&sig).unwrap().into_children().collect(); assert_eq!(packets.len(), 3); if let Packet::OnePassSig(ref ops) = packets[0] { assert!(ops.last()); @@ -90,8 +89,7 @@ fn sq_sign_append() { // Check that the content is sane. let packets: Vec<Packet> = - PacketPile::from_reader(Reader::from_file(&sig0).unwrap()) - .unwrap().into_children().collect(); + PacketPile::from_file(&sig0).unwrap().into_children().collect(); assert_eq!(packets.len(), 3); if let Packet::OnePassSig(ref ops) = packets[0] { assert!(ops.last()); @@ -141,8 +139,7 @@ fn sq_sign_append() { // Check that the content is sane. let packets: Vec<Packet> = - PacketPile::from_reader(Reader::from_file(&sig1).unwrap()) - .unwrap().into_children().collect(); + PacketPile::from_file(&sig1).unwrap().into_children().collect(); assert_eq!(packets.len(), 5); if let Packet::OnePassSig(ref ops) = packets[0] { assert!(! ops.last()); @@ -225,8 +222,7 @@ fn sq_sign_append_on_compress_then_sign() { // Check that the content is sane. let packets: Vec<Packet> = - PacketPile::from_reader(Reader::from_file(&sig0).unwrap()) - .unwrap().into_children().collect(); + PacketPile::from_file(&sig0).unwrap().into_children().collect(); assert_eq!(packets.len(), 3); if let Packet::OnePassSig(ref ops) = packets[0] { assert!(ops.last()); @@ -277,8 +273,7 @@ fn sq_sign_append_on_compress_then_sign() { // Check that the content is sane. let packets: Vec<Packet> = - PacketPile::from_reader(Reader::from_file(&sig1).unwrap()) - .unwrap().into_children().collect(); + PacketPile::from_file(&sig1).unwrap().into_children().collect(); assert_eq!(packets.len(), 5); if let Packet::OnePassSig(ref ops) = packets[0] { assert!(! ops.last()); @@ -355,8 +350,7 @@ fn sq_sign_detached() { // Check that the content is sane. let packets: Vec<Packet> = - PacketPile::from_reader(Reader::from_file(&sig).unwrap()) - .unwrap().into_children().collect(); + PacketPile::from_file(&sig).unwrap().into_children().collect(); assert_eq!(packets.len(), 1); if let Packet::Signature(ref sig) = packets[0] { assert_eq!(sig.sigtype(), SignatureType::Binary); @@ -400,8 +394,7 @@ fn sq_sign_detached_append() { // Check that the content is sane. let packets: Vec<Packet> = - PacketPile::from_reader(Reader::from_file(&sig).unwrap()) - .unwrap().into_children().collect(); + PacketPile::from_file(&sig).unwrap().into_children().collect(); assert_eq!(packets.len(), 1); if let Packet::Signature(ref sig) = packets[0] { assert_eq!(sig.sigtype(), SignatureType::Binary); @@ -455,8 +448,7 @@ fn sq_sign_detached_append() { // Check that the content is sane. let packets: Vec<Packet> = - PacketPile::from_reader(Reader::from_file(&sig).unwrap()) - .unwrap().into_children().collect(); + PacketPile::from_file(&sig).unwrap().into_children().collect(); assert_eq!(packets.len(), 2); if let Packet::Signature(ref sig) = packets[0] { assert_eq!(sig.sigtype(), SignatureType::Binary); @@ -510,8 +502,7 @@ fn sq_sign_detached_append() { // Check that the content is still sane. let packets: Vec<Packet> = - PacketPile::from_reader(Reader::from_file(&sig).unwrap()) - .unwrap().into_children().collect(); + PacketPile::from_file(&sig).unwrap().into_children().collect(); assert_eq!(packets.len(), 2); if let Packet::Signature(ref sig) = packets[0] { assert_eq!(sig.sigtype(), SignatureType::Binary); @@ -548,8 +539,7 @@ fn sq_sign_append_a_notarization() { // Check that the content is sane. let packets: Vec<Packet> = - PacketPile::from_reader(Reader::from_file(&sig0).unwrap()) - .unwrap().into_children().collect(); + PacketPile::from_file(&sig0).unwrap().into_children().collect(); assert_eq!(packets.len(), 7); if let Packet::OnePassSig(ref ops) = packets[0] { assert!(! ops.last()); @@ -647,8 +637,7 @@ fn sq_sign_notarize() { // Check that the content is sane. let packets: Vec<Packet> = - PacketPile::from_reader(Reader::from_file(&sig0).unwrap()) - .unwrap().into_children().collect(); + PacketPile::from_file(&sig0).unwrap().into_children().collect(); assert_eq!(packets.len(), 5); if let Packet::OnePassSig(ref ops) = packets[0] { assert!(ops.last()); @@ -725,8 +714,7 @@ fn sq_sign_notarize_a_notarization() { // Check that the content is sane. let packets: Vec<Packet> = - PacketPile::from_reader(Reader::from_file(&sig0).unwrap()) - .unwrap().into_children().collect(); + PacketPile::from_file(&sig0).unwrap().into_children().collect(); assert_eq!(packets.len(), 7); if let Packet::OnePassSig(ref ops) = packets[0] { assert!(ops.last()); |