summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-03-17 15:14:16 +0100
committerJustus Winter <justus@sequoia-pgp.org>2020-03-20 16:08:02 +0100
commitda56ad1df73c5a4b247a8fda99bcf8dc016d92ea (patch)
tree1415da8e9e9ffc25b711083107a0b65770ff3a60
parent857845f523ab090638693d5498c8753e1e41cf36 (diff)
openpgp: Add test demonstrating partial reads of literal packets.
-rw-r--r--openpgp/src/packet/literal.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/openpgp/src/packet/literal.rs b/openpgp/src/packet/literal.rs
index 74123b76..d9e71e3b 100644
--- a/openpgp/src/packet/literal.rs
+++ b/openpgp/src/packet/literal.rs
@@ -209,4 +209,38 @@ mod tests {
true
}
}
+
+ /// Checks that partially read packets are still considered equal.
+ #[test]
+ fn partial_read_eq() -> Result<()> {
+ use buffered_reader::BufferedReader;
+ use crate::parse::PacketParserBuilder;
+
+ let mut l0 = Literal::new(Default::default());
+ l0.set_body(vec![0, 0]);
+ let l0 = Packet::from(l0);
+ let l0bin = l0.to_vec()?;
+ // Sanity check.
+ assert_eq!(l0, Packet::from_bytes(&l0bin)?);
+
+ for &buffer_unread_content in &[false, true] {
+ for read_n in 0..3 {
+ eprintln!("buffer_unread_content: {:?}, read_n: {}",
+ buffer_unread_content, read_n);
+
+ let mut b = PacketParserBuilder::from_bytes(&l0bin)?;
+ if buffer_unread_content {
+ b = b.buffer_unread_content();
+ }
+ let mut pp = b.finalize()?.unwrap();
+ let d = pp.steal(read_n)?;
+ d.into_iter().for_each(|b| assert_eq!(b, 0));
+ let l = pp.finish()?;
+ assert_eq!(&l0, l);
+ let l = pp.next()?.0;
+ assert_eq!(l0, l);
+ }
+ }
+ Ok(())
+ }
}