diff options
-rw-r--r-- | openpgp/examples/decrypt-with.rs | 2 | ||||
-rw-r--r-- | openpgp/src/pkesk.rs | 45 | ||||
-rw-r--r-- | tool/src/commands.rs | 2 |
3 files changed, 42 insertions, 7 deletions
diff --git a/openpgp/examples/decrypt-with.rs b/openpgp/examples/decrypt-with.rs index bed1677c..e023bcb9 100644 --- a/openpgp/examples/decrypt-with.rs +++ b/openpgp/examples/decrypt-with.rs @@ -59,7 +59,7 @@ pub fn main() { Packet::SEIP(_) => { let mut state = None; for pkesk in pkesks.iter() { - if let Some(tsk) = keys.get(&pkesk.recipient) { + if let Some(tsk) = keys.get(&pkesk.recipient()) { if let Some(SecretKey::Unencrypted{ref mpis}) = tsk.secret() { diff --git a/openpgp/src/pkesk.rs b/openpgp/src/pkesk.rs index f697757c..05e947ad 100644 --- a/openpgp/src/pkesk.rs +++ b/openpgp/src/pkesk.rs @@ -18,15 +18,15 @@ use packet; #[derive(PartialEq, Clone, Debug)] pub struct PKESK { /// CTB header fields. - pub common: packet::Common, + pub(crate) common: packet::Common, /// Packet version. Must be 3. - pub version: u8, + pub(crate) version: u8, /// Key ID of the key this is encrypted to. - pub recipient: KeyID, + pub(crate) recipient: KeyID, /// Public key algorithm used to encrypt the session key. - pub pk_algo: PublicKeyAlgorithm, + pub(crate) pk_algo: PublicKeyAlgorithm, /// The encrypted session key. - pub esk: MPIs, + pub(crate) esk: MPIs, } impl PKESK { @@ -92,6 +92,41 @@ impl PKESK { }) } + /// Gets the version. + pub fn version(&self) -> u8 { + self.version + } + + /// Gets the recipient. + pub fn recipient(&self) -> &KeyID { + &self.recipient + } + + /// Sets the recipient. + pub fn set_recipient(&mut self, recipient: KeyID) { + self.recipient = recipient; + } + + /// Gets the public key algorithm. + pub fn pk_algo(&self) -> PublicKeyAlgorithm { + self.pk_algo + } + + /// Sets the public key algorithm. + pub fn set_pk_algo(&mut self, algo: PublicKeyAlgorithm) { + self.pk_algo = algo; + } + + /// Gets the encrypted session key. + pub fn esk(&self) -> &MPIs { + &self.esk + } + + /// Sets the encrypted session key. + pub fn set_esk(&mut self, esk: MPIs) { + self.esk = esk; + } + /// Decrypts the ESK and returns the session key and symmetric algorithm /// used to encrypt the following payload. pub fn decrypt(&self, recipient: &Key, recipient_sec: &MPIs) diff --git a/tool/src/commands.rs b/tool/src/commands.rs index 46c44899..0c8d8755 100644 --- a/tool/src/commands.rs +++ b/tool/src/commands.rs @@ -78,7 +78,7 @@ pub fn decrypt(input: &mut io::Read, output: &mut io::Write, Packet::SEIP(_) => { let mut decrypted = false; for pkesk in pkesks.iter() { - if let Some(tsk) = keys.get(&pkesk.recipient) { + if let Some(tsk) = keys.get(pkesk.recipient()) { // XXX: Deal with encrypted keys. if let Some(SecretKey::Unencrypted{ref mpis}) = tsk.secret() |