summaryrefslogtreecommitdiffstats
path: root/openpgp
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2018-08-24 13:05:17 +0200
committerJustus Winter <justus@sequoia-pgp.org>2018-08-24 13:05:17 +0200
commita42e294ee6a241f911ab14364439b6f11d76ea73 (patch)
tree30f60c03a7ad08ef862f424728dc5ba1813d7060 /openpgp
parent4a5554331f454a7a1b3068ec17a9e56f07d3a5f8 (diff)
openpgp: Make struct PKESK opaque, add getters and setters.
- See #57.
Diffstat (limited to 'openpgp')
-rw-r--r--openpgp/examples/decrypt-with.rs2
-rw-r--r--openpgp/src/pkesk.rs45
2 files changed, 41 insertions, 6 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)