diff --git a/Cargo.lock b/Cargo.lock index 082761ee..77c88eae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -344,9 +344,9 @@ dependencies = [ [[package]] name = "buffered-reader" -version = "1.3.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b9b0a25eb06e83579bc985d836e1e3b957a7201301b48538764d2b2e78090d4" +checksum = "cd098763fdb64579407a8c83cf0d751e6d4a7e161d0114c89cc181a2ca760ec8" dependencies = [ "bzip2", "flate2", diff --git a/Cargo.toml b/Cargo.toml index 8d66fae4..927c7a6e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ gitlab = { repository = "sequoia-pgp/sequoia-sq" } maintenance = { status = "actively-developed" } [dependencies] -buffered-reader = { version = "1.0.0", default-features = false, features = ["compression"] } +buffered-reader = { version = "1.3.1", default-features = false, features = ["compression"] } dirs = "5" dot-writer = { version = "0.1.3", optional = true } sequoia-openpgp = { version = "1.18", default-features = false, features = ["compression"] } diff --git a/src/commands/autocrypt.rs b/src/commands/autocrypt.rs index 238f625e..2f717a90 100644 --- a/src/commands/autocrypt.rs +++ b/src/commands/autocrypt.rs @@ -1,13 +1,13 @@ use anyhow::Context; -use buffered_reader::{BufferedReader, Dup, Generic}; +use buffered_reader::{BufferedReader, Dup}; use sequoia_openpgp as openpgp; use openpgp::{ Cert, Result, armor, packet::UserID, - parse::{Parse, stream::DecryptorBuilder}, + parse::{Cookie, Parse, stream::DecryptorBuilder}, serialize::Serialize, }; use sequoia_autocrypt as autocrypt; @@ -43,8 +43,7 @@ fn import<'store, 'rstore>(mut config: Config<'store, 'rstore>, let mut acc = Vec::new(); // First, get the Autocrypt headers from the outside. - let input = Generic::new(input, None); - let mut dup = Dup::new(input); + let mut dup = Dup::with_cookie(input, Cookie::default()); let ac = autocrypt::AutocryptHeaders::from_reader(&mut dup)?; let from = UserID::from( ac.from.as_ref().ok_or(anyhow::anyhow!("no From: header"))? @@ -102,8 +101,7 @@ fn import<'store, 'rstore>(mut config: Config<'store, 'rstore>, helper.quiet(true); let policy = config.policy.clone(); - let mut decryptor = match - DecryptorBuilder::from_reader(input)? + let mut decryptor = match DecryptorBuilder::from_buffered_reader(input)? .with_policy(&policy, None, helper) .context("Decryption failed") { @@ -178,7 +176,7 @@ fn encode_sender(config: Config, command: &cli::autocrypt::EncodeSenderCommand) { let input = command.input.open()?; let mut output = command.output.create_safe(config.force)?; - let cert = Cert::from_reader(input)?; + let cert = Cert::from_buffered_reader(input)?; let addr = command.address.clone() .or_else(|| { cert.with_policy(config.policy, None) diff --git a/src/commands/cert/import.rs b/src/commands/cert/import.rs index d8d81f5a..c5615d54 100644 --- a/src/commands/cert/import.rs +++ b/src/commands/cert/import.rs @@ -36,7 +36,7 @@ where 'store: 'rstore let inner = || -> Result<()> { for input in inputs.into_iter() { let input = FileOrStdin::from(input).open()?; - let raw_certs = RawCertParser::from_reader(input)?; + let raw_certs = RawCertParser::from_buffered_reader(input)?; let policy = config.policy.clone(); let time = config.time; diff --git a/src/commands/cert/lint.rs b/src/commands/cert/lint.rs index 2d9f647a..727f74d8 100644 --- a/src/commands/cert/lint.rs +++ b/src/commands/cert/lint.rs @@ -267,7 +267,7 @@ pub fn lint(config: Config, mut args: Command) -> Result<()> { Some(path) => path.display().to_string(), None => "/dev/stdin".to_string(), }; - let certp = CertParser::from_reader(&mut input_reader)?; + let certp = CertParser::from_buffered_reader(&mut input_reader)?; 'next_cert: for (certi, certo) in certp.enumerate() { match certo { Err(err) => { diff --git a/src/commands/inspect.rs b/src/commands/inspect.rs index d2d4ba77..65d7cf3a 100644 --- a/src/commands/inspect.rs +++ b/src/commands/inspect.rs @@ -58,7 +58,7 @@ pub fn dispatch(config: Config, c: inspect::Command) } } - openpgp::parse::PacketParser::from_reader(input.open()?)? + openpgp::parse::PacketParser::from_buffered_reader(input.open()?)? } else { let cert_store = config.cert_store_or_else()?; for cert in c.cert.into_iter() { diff --git a/src/commands/key/adopt.rs b/src/commands/key/adopt.rs index fc4c94bc..d4dc396e 100644 --- a/src/commands/key/adopt.rs +++ b/src/commands/key/adopt.rs @@ -26,7 +26,7 @@ use crate::decrypt_key; pub fn adopt(config: Config, command: cli::key::AdoptCommand) -> Result<()> { let input = command.certificate.open()?; - let cert = Cert::from_reader(input)?; + let cert = Cert::from_buffered_reader(input)?; let mut wanted: Vec<( KeyHandle, Option<( diff --git a/src/commands/key/attest_certifications.rs b/src/commands/key/attest_certifications.rs index 813f076d..042978cc 100644 --- a/src/commands/key/attest_certifications.rs +++ b/src/commands/key/attest_certifications.rs @@ -16,7 +16,7 @@ pub fn attest_certifications( let all = !command.none; // All is the default. let input = command.key.open()?; - let key = Cert::from_reader(input)?; + let key = Cert::from_buffered_reader(input)?; // Get a signer. let mut passwords = Vec::new(); diff --git a/src/commands/key/expire.rs b/src/commands/key/expire.rs index 0c9d8143..b2895eeb 100644 --- a/src/commands/key/expire.rs +++ b/src/commands/key/expire.rs @@ -31,7 +31,7 @@ pub fn dispatch(config: Config, command: cli::key::expire::Command) }; let input = command.input.open()?; - let key = Cert::from_reader(input)?; + let key = Cert::from_buffered_reader(input)?; if ! key.is_tsk() { return Err(anyhow::anyhow!("Certificate has no secrets")); } diff --git a/src/commands/key/password.rs b/src/commands/key/password.rs index 66e3d0a7..2c5f547e 100644 --- a/src/commands/key/password.rs +++ b/src/commands/key/password.rs @@ -15,7 +15,7 @@ pub fn password( command: cli::key::PasswordCommand, ) -> Result<()> { let input = command.input.open()?; - let key = Cert::from_reader(input)?; + let key = Cert::from_buffered_reader(input)?; if !key.is_tsk() { return Err(anyhow::anyhow!("Certificate has no secrets")); diff --git a/src/commands/key/subkey.rs b/src/commands/key/subkey.rs index e45f590d..62e0f503 100644 --- a/src/commands/key/subkey.rs +++ b/src/commands/key/subkey.rs @@ -228,7 +228,7 @@ fn subkey_add( command: SubkeyAddCommand, ) -> Result<()> { let input = command.input.open()?; - let cert = Cert::from_reader(input)?; + let cert = Cert::from_buffered_reader(input)?; let valid_cert = cert.with_policy(config.policy, config.time)?; let validity = command diff --git a/src/commands/key/userid.rs b/src/commands/key/userid.rs index 2fdf0b2c..23207972 100644 --- a/src/commands/key/userid.rs +++ b/src/commands/key/userid.rs @@ -228,7 +228,7 @@ fn userid_add( command: cli::key::UseridAddCommand, ) -> Result<()> { let input = command.input.open()?; - let key = Cert::from_reader(input)?; + let key = Cert::from_buffered_reader(input)?; // Make sure the user IDs are in canonical form. If not, and // `--allow-non-canonical-userids` is not set, error out. @@ -393,7 +393,7 @@ fn userid_strip( command: cli::key::UseridStripCommand, ) -> Result<()> { let input = command.input.open()?; - let key = Cert::from_reader(input)?; + let key = Cert::from_buffered_reader(input)?; let orig_cert_valid = key.with_policy(config.policy, None).is_ok(); diff --git a/src/commands/network.rs b/src/commands/network.rs index dbb1c83a..b58022a7 100644 --- a/src/commands/network.rs +++ b/src/commands/network.rs @@ -924,7 +924,7 @@ pub fn dispatch_keyserver(mut config: Config, })?, Publish(c) => rt.block_on(async { let mut input = c.input.open()?; - let cert = Arc::new(Cert::from_reader(&mut input). + let cert = Arc::new(Cert::from_buffered_reader(&mut input). context("Malformed key")?); let mut requests = tokio::task::JoinSet::new(); @@ -1048,7 +1048,7 @@ pub fn dispatch_wkd(mut config: Config, c: cli::network::wkd::Command) } else { wkd::Variant::Advanced }; - let parser = CertParser::from_reader(f)?; + let parser = CertParser::from_buffered_reader(f)?; let certs: Vec = parser.filter_map(|cert| cert.ok()) .collect(); for cert in certs { @@ -1081,7 +1081,7 @@ pub fn dispatch_dane(mut config: Config, c: cli::network::dane::Command) use crate::cli::network::dane::Subcommands::*; match c.subcommand { Generate(c) => { - for cert in CertParser::from_reader(c.input.open()?)? { + for cert in CertParser::from_buffered_reader(c.input.open()?)? { let cert = cert?; let vc = match cert.with_policy(config.policy, config.time) { Ok(vc) => vc, diff --git a/src/commands/toolbox/armor.rs b/src/commands/toolbox/armor.rs index 29f62f2f..4701cd32 100644 --- a/src/commands/toolbox/armor.rs +++ b/src/commands/toolbox/armor.rs @@ -29,7 +29,7 @@ fn detect_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) { + let kind = match PacketParser::from_buffered_reader(&mut limitor) { Ok(PacketParserResult::Some(pp)) => match pp.next() { Ok((Packet::Signature(_), _)) => armor::Kind::Signature, Ok((Packet::SecretKey(_), _)) => armor::Kind::SecretKey, @@ -59,9 +59,9 @@ pub fn dispatch(config: Config, command: cli::toolbox::armor::Command) dup, ARMOR_DETECTION_LIMIT, Cookie::default()); let (already_armored, have_kind) = { let mut reader = - armor::Reader::from_reader( + armor::Reader::from_buffered_reader( &mut limitor, - armor::ReaderMode::Tolerant(None)); + armor::ReaderMode::Tolerant(None))?; (reader.data(8).is_ok(), reader.kind()) }; let mut input = @@ -91,9 +91,9 @@ pub fn dispatch(config: Config, command: cli::toolbox::armor::Command) if already_armored { // Dearmor and copy to change the type. let mut reader = - armor::Reader::from_reader( + armor::Reader::from_buffered_reader( input, - armor::ReaderMode::Tolerant(None)); + armor::ReaderMode::Tolerant(None))?; io::copy(&mut reader, &mut output)?; } else { io::copy(&mut input, &mut output)?; diff --git a/src/commands/toolbox/dearmor.rs b/src/commands/toolbox/dearmor.rs index 5b2e6928..6e0153ad 100644 --- a/src/commands/toolbox/dearmor.rs +++ b/src/commands/toolbox/dearmor.rs @@ -14,7 +14,7 @@ pub fn dispatch(config: Config, command: cli::toolbox::dearmor::Command) let mut input = command.input.open()?; let mut output = command.output.create_safe(config.force)?; - let mut filter = armor::Reader::from_reader(&mut input, None); + let mut filter = armor::Reader::from_buffered_reader(&mut input, None)?; io::copy(&mut filter, &mut output)?; Ok(()) diff --git a/src/commands/toolbox/extract_cert.rs b/src/commands/toolbox/extract_cert.rs index 7b2697cb..5f4c201a 100644 --- a/src/commands/toolbox/extract_cert.rs +++ b/src/commands/toolbox/extract_cert.rs @@ -16,7 +16,7 @@ pub fn dispatch( let input = command.input.open()?; let mut output = command.output.create_safe(config.force)?; - let cert = Cert::from_reader(input)?; + let cert = Cert::from_buffered_reader(input)?; if command.binary { cert.serialize(&mut output)?; } else { diff --git a/src/commands/toolbox/packet.rs b/src/commands/toolbox/packet.rs index f0aff7f3..4e26287a 100644 --- a/src/commands/toolbox/packet.rs +++ b/src/commands/toolbox/packet.rs @@ -110,7 +110,7 @@ pub fn split(_config: Config, c: SplitCommand) -> Result<()> // We (ab)use the mapping feature to create byte-accurate dumps of // nested packets. let mut ppr = - openpgp::parse::PacketParserBuilder::from_reader(input)? + openpgp::parse::PacketParserBuilder::from_buffered_reader(input)? .map(true).build()?; fn join(pos: &[usize], delimiter: &str) -> String { diff --git a/src/common.rs b/src/common.rs index aa148f7d..4d836136 100644 --- a/src/common.rs +++ b/src/common.rs @@ -29,7 +29,7 @@ pub const NULL_POLICY: &NullPolicy = &NullPolicy::new(); pub fn read_cert(input: Option<&Path>) -> Result { let input = FileOrStdin::from(input).open()?; - let cert = CertParser::from_reader(input)?.collect::>(); + let cert = CertParser::from_buffered_reader(input)?.collect::>(); let cert = match cert.len() { 0 => Err(anyhow!("No certificates provided."))?, 1 => cert.into_iter().next().expect("have one")?,