summaryrefslogtreecommitdiffstats
path: root/openpgp/src
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2018-12-13 12:13:47 +0100
committerJustus Winter <justus@sequoia-pgp.org>2018-12-13 13:21:58 +0100
commit56ee713f3510f81a04ff36132c8aaf7555396b2b (patch)
tree233291afcff9023e7fa1a73984a59914cc5fcc03 /openpgp/src
parentdfa222df2014cb59dff37e69866f02ad510e2882 (diff)
openpgp: Make fields of PKESK private.
Diffstat (limited to 'openpgp/src')
-rw-r--r--openpgp/src/message/mod.rs11
-rw-r--r--openpgp/src/packet/pkesk.rs21
-rw-r--r--openpgp/src/parse/parse.rs10
-rw-r--r--openpgp/src/serialize/mod.rs12
4 files changed, 30 insertions, 24 deletions
diff --git a/openpgp/src/message/mod.rs b/openpgp/src/message/mod.rs
index cee9d4c1..c90cc4ca 100644
--- a/openpgp/src/message/mod.rs
+++ b/openpgp/src/message/mod.rs
@@ -1053,13 +1053,10 @@ mod tests {
#[allow(deprecated)]
packets.insert(
1,
- Packet::PKESK(PKESK {
- common: Default::default(),
- version: 0,
- recipient: KeyID::from_hex("0000111122223333").unwrap(),
- pk_algo: PublicKeyAlgorithm::RSAEncrypt,
- esk: Ciphertext::RSA { c: MPI::new(&[]) },
- }));
+ Packet::PKESK(PKESK::new_(
+ KeyID::from_hex("0000111122223333").unwrap(),
+ PublicKeyAlgorithm::RSAEncrypt,
+ Ciphertext::RSA { c: MPI::new(&[]) }).unwrap()));
assert!(packets.iter().map(|p| p.tag()).collect::<Vec<Tag>>()
== [ Tag::SKESK, Tag::PKESK, Tag::SKESK, Tag::SEIP ]);
diff --git a/openpgp/src/packet/pkesk.rs b/openpgp/src/packet/pkesk.rs
index 2b41e66d..cd27f18c 100644
--- a/openpgp/src/packet/pkesk.rs
+++ b/openpgp/src/packet/pkesk.rs
@@ -22,17 +22,30 @@ pub struct PKESK {
/// CTB header fields.
pub(crate) common: packet::Common,
/// Packet version. Must be 3.
- pub(crate) version: u8,
+ version: u8,
/// Key ID of the key this is encrypted to.
- pub(crate) recipient: KeyID,
+ recipient: KeyID,
/// Public key algorithm used to encrypt the session key.
- pub(crate) pk_algo: PublicKeyAlgorithm,
+ pk_algo: PublicKeyAlgorithm,
/// The encrypted session key.
- pub(crate) esk: Ciphertext,
+ esk: Ciphertext,
}
impl PKESK {
/// Creates a new PKESK packet.
+ pub fn new_(recipient: KeyID, pk_algo: PublicKeyAlgorithm,
+ encrypted_session_key: Ciphertext)
+ -> Result<PKESK> {
+ Ok(PKESK {
+ common: Default::default(),
+ version: 3,
+ recipient: recipient,
+ pk_algo: pk_algo,
+ esk: encrypted_session_key,
+ })
+ }
+
+ /// Creates a new PKESK packet.
///
/// The given symmetric algorithm must match the algorithm that is
/// used to encrypt the payload.
diff --git a/openpgp/src/parse/parse.rs b/openpgp/src/parse/parse.rs
index f1c74320..26a2c92b 100644
--- a/openpgp/src/parse/parse.rs
+++ b/openpgp/src/parse/parse.rs
@@ -2046,13 +2046,9 @@ impl PKESK {
}
let mpis = crypto::mpis::Ciphertext::parse(pk_algo, &mut php)?;
- php.ok(Packet::PKESK(PKESK {
- common: Default::default(),
- version: version,
- pk_algo: pk_algo,
- recipient: KeyID::from_bytes(&keyid),
- esk: mpis,
- }))
+ let pkesk = php_try!(PKESK::new_(KeyID::from_bytes(&keyid),
+ pk_algo, mpis));
+ php.ok(Packet::PKESK(pkesk))
}
}
diff --git a/openpgp/src/serialize/mod.rs b/openpgp/src/serialize/mod.rs
index 3ded65c5..20cf3a50 100644
--- a/openpgp/src/serialize/mod.rs
+++ b/openpgp/src/serialize/mod.rs
@@ -1010,7 +1010,7 @@ impl Serialize for PKESK {
///
/// [`Error::InvalidArgument`]: ../enum.Error.html#variant.InvalidArgument
fn serialize<W: io::Write>(&self, o: &mut W) -> Result<()> {
- if self.version != 3 {
+ if self.version() != 3 {
return Err(Error::InvalidArgument(
"Don't know how to serialize \
non-version 3 packets.".into()).into());
@@ -1020,15 +1020,15 @@ impl Serialize for PKESK {
1 // Version
+ 8 // Recipient's key id
+ 1 // Algo
- + self.esk.serialized_len(); // ESK.
+ + self.esk().serialized_len(); // ESK.
CTB::new(Tag::PKESK).serialize(o)?;
BodyLength::Full(len as u32).serialize(o)?;
- write_byte(o, self.version)?;
- self.recipient.serialize(o)?;
- write_byte(o, self.pk_algo.into())?;
- self.esk.serialize(o)?;
+ write_byte(o, self.version())?;
+ self.recipient().serialize(o)?;
+ write_byte(o, self.pk_algo().into())?;
+ self.esk().serialize(o)?;
Ok(())
}