diff --git a/src/cli/types.rs b/src/cli/types.rs index 82ff5b2e..25a40e09 100644 --- a/src/cli/types.rs +++ b/src/cli/types.rs @@ -25,6 +25,7 @@ use clap::ValueEnum; use sequoia_openpgp as openpgp; use openpgp::armor; use openpgp::fmt::hex; +use openpgp::parse::Cookie; use openpgp::serialize::stream::Armorer; use openpgp::serialize::stream::Message; use openpgp::types::KeyFlags; @@ -132,13 +133,14 @@ impl FileOrStdin { /// Get a boxed BufferedReader for the FileOrStdin /// /// Opens a file if there is Some(PathBuf), else opens stdin. - pub fn open(&self) -> Result>> { + pub fn open<'a>(&self) -> Result + 'a>> { if let Some(path) = self.inner() { Ok(Box::new( - File::open(path) + File::with_cookie(path, Default::default()) .with_context(|| format!("Failed to open {}", self))?)) } else { - Ok(Box::new(Generic::new(stdin(), None))) + Ok(Box::new( + Generic::with_cookie(stdin(), None, Default::default()))) } } } diff --git a/src/commands/toolbox/armor.rs b/src/commands/toolbox/armor.rs index bba47bdb..29f62f2f 100644 --- a/src/commands/toolbox/armor.rs +++ b/src/commands/toolbox/armor.rs @@ -7,6 +7,7 @@ use buffered_reader::Limitor; use sequoia_openpgp as openpgp; use openpgp::Packet; use openpgp::armor; +use openpgp::parse::Cookie; use openpgp::parse::Parse; use openpgp::parse::PacketParser; use openpgp::parse::PacketParserResult; @@ -23,11 +24,12 @@ const ARMOR_DETECTION_LIMIT: u64 = 1 << 24; /// Returns the given reader unchanged. If the detection fails, /// armor::Kind::File is returned as safe default. fn detect_armor_kind( - input: Box>, -) -> (Box>, armor::Kind) { - let mut dup = - Limitor::new(Dup::new(input), ARMOR_DETECTION_LIMIT).into_boxed(); - let kind = match PacketParser::from_reader(&mut dup) { + input: Box>, +) -> (Box>, armor::Kind) { + let dup = Dup::with_cookie(input, Cookie::default()); + let mut limitor = Limitor::with_cookie( + dup, ARMOR_DETECTION_LIMIT, Cookie::default()).into_boxed(); + let kind = match PacketParser::from_reader(&mut limitor) { Ok(PacketParserResult::Some(pp)) => match pp.next() { Ok((Packet::Signature(_), _)) => armor::Kind::Signature, Ok((Packet::SecretKey(_), _)) => armor::Kind::SecretKey, @@ -38,7 +40,7 @@ fn detect_armor_kind( }, _ => armor::Kind::File, }; - (dup.into_inner().unwrap().into_inner().unwrap(), kind) + (limitor.into_inner().unwrap().into_inner().unwrap(), kind) } pub fn dispatch(config: Config, command: cli::toolbox::armor::Command) @@ -52,16 +54,18 @@ pub fn dispatch(config: Config, command: cli::toolbox::armor::Command) // Peek at the data. If it looks like it is armored // data, avoid armoring it again. - let mut dup = Limitor::new(Dup::new(input), ARMOR_DETECTION_LIMIT); + let dup = Dup::with_cookie(input, Cookie::default()); + let mut limitor = Limitor::with_cookie( + dup, ARMOR_DETECTION_LIMIT, Cookie::default()); let (already_armored, have_kind) = { let mut reader = armor::Reader::from_reader( - &mut dup, + &mut limitor, armor::ReaderMode::Tolerant(None)); (reader.data(8).is_ok(), reader.kind()) }; let mut input = - dup.into_boxed().into_inner().unwrap().into_inner().unwrap(); + limitor.into_boxed().into_inner().unwrap().into_inner().unwrap(); if already_armored && (want_kind.is_none() || want_kind == have_kind)