summaryrefslogtreecommitdiffstats
path: root/openpgp/src/serialize.rs
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-08-20 18:08:10 +0200
committerJustus Winter <justus@sequoia-pgp.org>2020-08-20 18:08:10 +0200
commitfa888a60114c60f2babc311f15aff8e14f196025 (patch)
treecf534d6639b8ccae6677829897c0a7ba5efdad6f /openpgp/src/serialize.rs
parent96c3ebd47138ea4ee044fea9fc4dc967c76f263f (diff)
openpgp: Add optional parameters to unknown S2K variants.
- This mirrors how we handle other unknown variants. However, since we do not know the length of the parameters for unknown S2K variants, we cannot parse them back. To work around that, the parameter field is optional, and will be `None` when an unknown S2K is parsed. The data is not lost, but stored in the packet containing the S2K object, so that we can serialize it again. - Carefully preserve the invariant that we can parse any packet we can serialize by comparing the serialized form of the packet fragments containing the S2K and any fields the parameters of unknown variants bleed into on parsing. - Unfortunately, this means that S2K on its own no longer roundtrips. Remove that test accordingly.
Diffstat (limited to 'openpgp/src/serialize.rs')
-rw-r--r--openpgp/src/serialize.rs12
1 files changed, 9 insertions, 3 deletions
diff --git a/openpgp/src/serialize.rs b/openpgp/src/serialize.rs
index c2c8b84f..800dceb7 100644
--- a/openpgp/src/serialize.rs
+++ b/openpgp/src/serialize.rs
@@ -1261,8 +1261,12 @@ impl Marshal for S2K {
w.write_all(&salt[..])?;
w.write_all(&[S2K::encode_count(hash_bytes)?])?;
}
- &S2K::Private(s2k) | &S2K::Unknown(s2k) => {
- w.write_all(&[s2k])?;
+ S2K::Private { tag, parameters }
+ | S2K::Unknown { tag, parameters} => {
+ w.write_all(&[*tag])?;
+ if let Some(p) = parameters.as_ref() {
+ w.write_all(p)?;
+ }
}
S2K::__Nonexhaustive => unreachable!(),
}
@@ -1278,7 +1282,9 @@ impl MarshalInto for S2K {
&S2K::Simple{ .. } => 2,
&S2K::Salted{ .. } => 2 + 8,
&S2K::Iterated{ .. } => 2 + 8 + 1,
- &S2K::Private(_) | &S2K::Unknown(_) => 1,
+ S2K::Private { parameters, .. }
+ | S2K::Unknown { parameters, .. } =>
+ 1 + parameters.as_ref().map(|p| p.len()).unwrap_or(0),
S2K::__Nonexhaustive => unreachable!(),
}
}