diff options
Diffstat (limited to 'openpgp')
-rw-r--r-- | openpgp/examples/encrypt-for.rs | 4 | ||||
-rw-r--r-- | openpgp/examples/generate-encrypt-decrypt.rs | 3 | ||||
-rw-r--r-- | openpgp/examples/generate-sign-verify.rs | 3 | ||||
-rw-r--r-- | openpgp/examples/notarize.rs | 3 | ||||
-rw-r--r-- | openpgp/examples/pad.rs | 4 | ||||
-rw-r--r-- | openpgp/examples/sign.rs | 3 | ||||
-rw-r--r-- | openpgp/examples/wrap-literal.rs | 4 | ||||
-rw-r--r-- | openpgp/src/autocrypt.rs | 3 | ||||
-rw-r--r-- | openpgp/src/parse/stream.rs | 3 | ||||
-rw-r--r-- | openpgp/src/serialize/padding.rs | 11 | ||||
-rw-r--r-- | openpgp/src/serialize/stream.rs | 43 |
11 files changed, 38 insertions, 46 deletions
diff --git a/openpgp/examples/encrypt-for.rs b/openpgp/examples/encrypt-for.rs index 327cb56d..47fb703d 100644 --- a/openpgp/examples/encrypt-for.rs +++ b/openpgp/examples/encrypt-for.rs @@ -6,7 +6,6 @@ use std::io; extern crate sequoia_openpgp as openpgp; use crate::openpgp::armor; -use crate::openpgp::constants::DataFormat; use crate::openpgp::packet::KeyFlags; use crate::openpgp::parse::Parse; use crate::openpgp::serialize::stream::{ @@ -57,8 +56,7 @@ fn main() { &recipients, None, None) .expect("Failed to create encryptor"); - let mut literal_writer = LiteralWriter::new(encryptor, DataFormat::Binary, - None, None) + let mut literal_writer = LiteralWriter::new(encryptor, None, None, None) .expect("Failed to create literal writer"); // Copy stdin to our writer stack to encrypt the data. diff --git a/openpgp/examples/generate-encrypt-decrypt.rs b/openpgp/examples/generate-encrypt-decrypt.rs index c0c4c4ed..6157019f 100644 --- a/openpgp/examples/generate-encrypt-decrypt.rs +++ b/openpgp/examples/generate-encrypt-decrypt.rs @@ -60,8 +60,7 @@ fn encrypt(sink: &mut Write, plaintext: &str, recipient: &openpgp::TPK) None, None)?; // Emit a literal data packet. - let mut literal_writer = LiteralWriter::new( - encryptor, openpgp::constants::DataFormat::Binary, None, None)?; + let mut literal_writer = LiteralWriter::new(encryptor, None, None, None)?; // Encrypt the data. literal_writer.write_all(plaintext.as_bytes())?; diff --git a/openpgp/examples/generate-sign-verify.rs b/openpgp/examples/generate-sign-verify.rs index 36582e6b..8625e4ea 100644 --- a/openpgp/examples/generate-sign-verify.rs +++ b/openpgp/examples/generate-sign-verify.rs @@ -50,8 +50,7 @@ fn sign(sink: &mut Write, plaintext: &str, tsk: &openpgp::TPK) let signer = Signer::new(message, vec![&mut keypair], None)?; // Emit a literal data packet. - let mut literal_writer = LiteralWriter::new( - signer, openpgp::constants::DataFormat::Binary, None, None)?; + let mut literal_writer = LiteralWriter::new(signer, None, None, None)?; // Sign the data. literal_writer.write_all(plaintext.as_bytes())?; diff --git a/openpgp/examples/notarize.rs b/openpgp/examples/notarize.rs index 271e9b42..eedcc01e 100644 --- a/openpgp/examples/notarize.rs +++ b/openpgp/examples/notarize.rs @@ -9,7 +9,6 @@ use crate::openpgp::{ armor, crypto, Packet, - constants::DataFormat, parse::{Parse, PacketParserResult}, serialize::Serialize, }; @@ -90,7 +89,7 @@ fn main() { // Then, create a literal writer to wrap the data in a // literal message packet. let mut literal = - LiteralWriter::new(signer, DataFormat::Binary, None, None) + LiteralWriter::new(signer, None, None, None) .expect("Failed to create literal writer"); // Copy all the data. diff --git a/openpgp/examples/pad.rs b/openpgp/examples/pad.rs index a959786d..681bfe53 100644 --- a/openpgp/examples/pad.rs +++ b/openpgp/examples/pad.rs @@ -6,7 +6,6 @@ use std::io; extern crate sequoia_openpgp as openpgp; use crate::openpgp::armor; -use crate::openpgp::constants::DataFormat; use crate::openpgp::KeyID; use crate::openpgp::packet::KeyFlags; use crate::openpgp::parse::Parse; @@ -63,8 +62,7 @@ fn main() { let padder = Padder::new(encryptor, padme) .expect("Failed to create padder"); - let mut literal_writer = LiteralWriter::new(padder, DataFormat::Binary, - None, None) + let mut literal_writer = LiteralWriter::new(padder, None, None, None) .expect("Failed to create literal writer"); // Copy stdin to our writer stack to encrypt the data. diff --git a/openpgp/examples/sign.rs b/openpgp/examples/sign.rs index bdb29c4c..7a7bcd91 100644 --- a/openpgp/examples/sign.rs +++ b/openpgp/examples/sign.rs @@ -6,7 +6,6 @@ use std::io; extern crate sequoia_openpgp as openpgp; use crate::openpgp::armor; use crate::openpgp::crypto; -use crate::openpgp::constants::DataFormat; use crate::openpgp::parse::Parse; use crate::openpgp::serialize::stream::{Message, LiteralWriter, Signer}; @@ -67,7 +66,7 @@ fn main() { // Then, create a literal writer to wrap the data in a literal // message packet. - let mut literal = LiteralWriter::new(signer, DataFormat::Binary, None, None) + let mut literal = LiteralWriter::new(signer, None, None, None) .expect("Failed to create literal writer"); // Copy all the data. diff --git a/openpgp/examples/wrap-literal.rs b/openpgp/examples/wrap-literal.rs index e50b8de7..d3eed376 100644 --- a/openpgp/examples/wrap-literal.rs +++ b/openpgp/examples/wrap-literal.rs @@ -8,7 +8,6 @@ use std::io; extern crate sequoia_openpgp as openpgp; use crate::openpgp::armor; -use crate::openpgp::constants::DataFormat; use crate::openpgp::serialize::stream::{Message, LiteralWriter}; fn main() { @@ -29,8 +28,7 @@ fn main() { // Then, create a literal writer to wrap the data in a literal // message packet. - let mut literal = LiteralWriter::new(message, DataFormat::Binary, - None, None) + let mut literal = LiteralWriter::new(message, None, None, None) .expect("Failed to create literal writer"); // Copy all the data. diff --git a/openpgp/src/autocrypt.rs b/openpgp/src/autocrypt.rs index 5995640e..e2ccf8e3 100644 --- a/openpgp/src/autocrypt.rs +++ b/openpgp/src/autocrypt.rs @@ -34,7 +34,6 @@ use crate::serialize::Serialize; use crate::serialize::stream::{ Message, LiteralWriter, Encryptor, }; -use crate::constants::DataFormat; use crate::crypto::Password; /// Version of Autocrypt to use. `Autocrypt::default()` always returns the @@ -473,7 +472,7 @@ impl AutocryptSetupMessage { &[], None, None)?; - let mut w = LiteralWriter::new(w, DataFormat::Binary, + let mut w = LiteralWriter::new(w, None, /* filename*/ None, /* date */ None)?; // The inner message is an ASCII-armored encoded TPK. diff --git a/openpgp/src/parse/stream.rs b/openpgp/src/parse/stream.rs index 6d7b7c64..f75e89bf 100644 --- a/openpgp/src/parse/stream.rs +++ b/openpgp/src/parse/stream.rs @@ -1804,7 +1804,6 @@ mod test { #[test] fn verify_long_message() { - use crate::constants::DataFormat; use crate::tpk::{TPKBuilder, CipherSuite}; use crate::serialize::stream::{LiteralWriter, Signer, Message}; use std::io::Write; @@ -1822,7 +1821,7 @@ mod test { let m = Message::new(&mut buf); let signer = Signer::new(m, vec![&mut keypair], None).unwrap(); - let mut ls = LiteralWriter::new(signer, DataFormat::Binary, None, None).unwrap(); + let mut ls = LiteralWriter::new(signer, None, None, None).unwrap(); ls.write_all(&mut vec![42u8; 30 * 1024 * 1024]).unwrap(); ls.finalize().unwrap(); diff --git a/openpgp/src/serialize/padding.rs b/openpgp/src/serialize/padding.rs index 7513aea8..23c72038 100644 --- a/openpgp/src/serialize/padding.rs +++ b/openpgp/src/serialize/padding.rs @@ -90,7 +90,6 @@ use crate::constants::{ /// ``` /// extern crate sequoia_openpgp as openpgp; /// use std::io::Write; -/// use openpgp::constants::DataFormat; /// use openpgp::serialize::stream::{Message, LiteralWriter}; /// use openpgp::serialize::padding::{Padder, padme}; /// use openpgp::constants::CompressionAlgorithm; @@ -103,7 +102,7 @@ use crate::constants::{ /// let message = Message::new(&mut unpadded); /// // XXX: Insert Encryptor here. /// // XXX: Insert Signer here. -/// let mut w = LiteralWriter::new(message, DataFormat::Text, None, None)?; +/// let mut w = LiteralWriter::new(message, None, None, None)?; /// w.write_all(b"Hello world.")?; /// w.finalize()?; /// } @@ -114,7 +113,7 @@ use crate::constants::{ /// // XXX: Insert Encryptor here. /// let padder = Padder::new(message, padme)?; /// // XXX: Insert Signer here. -/// let mut w = LiteralWriter::new(padder, DataFormat::Text, None, None)?; +/// let mut w = LiteralWriter::new(padder, None, None, None)?; /// w.write_all(b"Hello world.")?; /// w.finalize()?; /// } @@ -332,7 +331,6 @@ mod test { #[test] fn roundtrip() { use std::io::Write; - use crate::constants::DataFormat; use crate::parse::Parse; use crate::serialize::stream::*; @@ -344,7 +342,7 @@ mod test { let message = Message::new(&mut padded); let padder = Padder::new(message, padme).unwrap(); let mut w = - LiteralWriter::new(padder, DataFormat::Binary, None, None) + LiteralWriter::new(padder, None, None, None) .unwrap(); w.write_all(&msg).unwrap(); w.finalize().unwrap(); @@ -362,14 +360,13 @@ mod test { #[test] fn no_compression() { use std::io::Write; - use crate::constants::DataFormat; use crate::serialize::stream::*; const MSG: &[u8] = b"@@@@@@@@@@@@@@"; let mut padded = vec![]; { let message = Message::new(&mut padded); let padder = Padder::new(message, padme).unwrap(); - let mut w = LiteralWriter::new(padder, DataFormat::Text, None, None) + let mut w = LiteralWriter::new(padder, None, None, None) .unwrap(); w.write_all(MSG).unwrap(); w.finalize().unwrap(); diff --git a/openpgp/src/serialize/stream.rs b/openpgp/src/serialize/stream.rs index 66fd9366..7d94616c 100644 --- a/openpgp/src/serialize/stream.rs +++ b/openpgp/src/serialize/stream.rs @@ -225,7 +225,6 @@ impl<'a, R> Signer<'a, R> /// ``` /// extern crate sequoia_openpgp as openpgp; /// use std::io::{Read, Write}; - /// use openpgp::constants::DataFormat; /// use openpgp::serialize::stream::{Message, Signer, LiteralWriter}; /// # use openpgp::{Result, TPK}; /// # use openpgp::packet::prelude::*; @@ -244,7 +243,7 @@ impl<'a, R> Signer<'a, R> /// { /// let message = Message::new(&mut o); /// let signer = Signer::new(message, vec![&mut signing_keypair], None)?; - /// let mut ls = LiteralWriter::new(signer, DataFormat::Text, None, None)?; + /// let mut ls = LiteralWriter::new(signer, None, None, None)?; /// ls.write_all(b"Make it so, number one!")?; /// ls.finalize()?; /// } @@ -553,7 +552,6 @@ impl<'a, R> writer::Stackable<'a, Cookie> for Signer<'a, R> /// ``` /// extern crate sequoia_openpgp as openpgp; /// use std::io::Write; -/// use openpgp::constants::DataFormat; /// use openpgp::serialize::stream::{Message, LiteralWriter}; /// # use openpgp::Result; /// # f().unwrap(); @@ -562,11 +560,11 @@ impl<'a, R> writer::Stackable<'a, Cookie> for Signer<'a, R> /// let mut o = vec![]; /// { /// let message = Message::new(&mut o); -/// let mut w = LiteralWriter::new(message, DataFormat::Text, None, None)?; +/// let mut w = LiteralWriter::new(message, None, None, None)?; /// w.write_all(b"Hello world.")?; /// w.finalize()?; /// } -/// assert_eq!(b"\xcb\x12t\x00\x00\x00\x00\x00Hello world.", o.as_slice()); +/// assert_eq!(b"\xcb\x12b\x00\x00\x00\x00\x00Hello world.", o.as_slice()); /// # Ok(()) /// # } /// ``` @@ -586,10 +584,22 @@ impl<'a> LiteralWriter<'a> { /// /// If `date` is `None`, then the earliest representable time will /// be used as a dummy value. - pub fn new(inner: writer::Stack<'a, Cookie>, - format: DataFormat, - filename: Option<&[u8]>, - date: Option<time::Tm>) + pub fn new<'f, D, F, T>(inner: writer::Stack<'a, Cookie>, + format: D, filename: F, date: T) + -> Result<writer::Stack<'a, Cookie>> + where D: Into<Option<DataFormat>>, + F: Into<Option<&'f [u8]>>, + T: Into<Option<time::Tm>> + { + Self::make(inner, + format.into().unwrap_or_default(), + filename.into(), date.into()) + } + + fn make(inner: writer::Stack<'a, Cookie>, + format: DataFormat, + filename: Option<&[u8]>, + date: Option<time::Tm>) -> Result<writer::Stack<'a, Cookie>> { let mut inner = writer::BoxStack::from(inner); let level = inner.cookie_ref().level + 1; @@ -721,7 +731,6 @@ impl<'a> writer::Stackable<'a, Cookie> for LiteralWriter<'a> { /// ``` /// extern crate sequoia_openpgp as openpgp; /// use std::io::Write; -/// use openpgp::constants::DataFormat; /// use openpgp::serialize::stream::{Message, Compressor, LiteralWriter}; /// use openpgp::constants::CompressionAlgorithm; /// # use openpgp::Result; @@ -733,11 +742,11 @@ impl<'a> writer::Stackable<'a, Cookie> for LiteralWriter<'a> { /// let message = Message::new(&mut o); /// let w = Compressor::new(message, /// CompressionAlgorithm::Uncompressed, None)?; -/// let mut w = LiteralWriter::new(w, DataFormat::Text, None, None)?; +/// let mut w = LiteralWriter::new(w, None, None, None)?; /// w.write_all(b"Hello world.")?; /// w.finalize()?; /// } -/// assert_eq!(b"\xc8\x15\x00\xcb\x12t\x00\x00\x00\x00\x00Hello world.", +/// assert_eq!(b"\xc8\x15\x00\xcb\x12b\x00\x00\x00\x00\x00Hello world.", /// o.as_slice()); /// # Ok(()) /// # } @@ -910,7 +919,6 @@ impl<'a> Encryptor<'a> { /// ``` /// use std::io::Write; /// extern crate sequoia_openpgp as openpgp; - /// use openpgp::constants::DataFormat; /// use openpgp::packet::KeyFlags; /// use openpgp::serialize::stream::{ /// Message, Encryptor, LiteralWriter, @@ -972,7 +980,7 @@ impl<'a> Encryptor<'a> { /// &[&"совершенно секретно".into()], /// &recipients, None, None) /// .expect("Failed to create encryptor"); - /// let mut w = LiteralWriter::new(encryptor, DataFormat::Text, None, None)?; + /// let mut w = LiteralWriter::new(encryptor, None, None, None)?; /// w.write_all(b"Hello world.")?; /// w.finalize()?; /// # Ok(()) @@ -1348,7 +1356,7 @@ mod test { let m = Message::new(&mut o); let c = Compressor::new(m, CompressionAlgorithm::BZip2, None).unwrap(); - let mut ls = LiteralWriter::new(c, T, None, None).unwrap(); + let mut ls = LiteralWriter::new(c, None, None, None).unwrap(); // Write 64 megabytes of zeroes. for _ in 0 .. 16 { ls.write_all(&zeros).unwrap(); @@ -1389,7 +1397,7 @@ mod test { .collect(), None) .unwrap(); - let mut ls = LiteralWriter::new(signer, T, None, None).unwrap(); + let mut ls = LiteralWriter::new(signer, None, None, None).unwrap(); ls.write_all(b"Tis, tis, tis. Tis is important.").unwrap(); let signer = ls.finalize_one().unwrap().unwrap(); let _ = signer.finalize_one().unwrap().unwrap(); @@ -1426,8 +1434,7 @@ mod test { m, &passwords.iter().collect::<Vec<&Password>>(), &[], None, None) .unwrap(); - let mut literal = LiteralWriter::new(encryptor, DataFormat::Binary, - None, None) + let mut literal = LiteralWriter::new(encryptor, None, None, None) .unwrap(); literal.write_all(message).unwrap(); } |