summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2021-04-07 15:14:41 +0200
committerJustus Winter <justus@sequoia-pgp.org>2021-04-08 12:56:15 +0200
commit6f677cf5d3110ae9e7b062de7bd7474c3c409764 (patch)
tree40e860ce62e0ef882e65cece4433b9249c95f8fa
parent13b52fb5e05846bd110f3baeab1a157a68325d43 (diff)
openpgp: New test for SerializeInto::serialized_len.
-rw-r--r--openpgp/src/serialize.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/openpgp/src/serialize.rs b/openpgp/src/serialize.rs
index 8c16c18b..2b7ca32d 100644
--- a/openpgp/src/serialize.rs
+++ b/openpgp/src/serialize.rs
@@ -3516,4 +3516,21 @@ mod test {
.unwrap_err();
(&pp as &dyn MarshalInto).export_to_vec().unwrap_err();
}
+
+ quickcheck! {
+ /// Checks that SerializeInto::serialized_len computes the
+ /// exact size (except for CompressedData packets where we may
+ /// overestimate the size).
+ fn packet_serialized_len(p: Packet) -> bool {
+ let p_as_vec = SerializeInto::to_vec(&p).unwrap();
+ if let Packet::CompressedData(_) = p {
+ // serialized length may be an over-estimate
+ assert!(SerializeInto::serialized_len(&p) >= p_as_vec.len());
+ } else {
+ // serialized length should be exact
+ assert_eq!(SerializeInto::serialized_len(&p), p_as_vec.len());
+ }
+ true
+ }
+ }
}