summaryrefslogtreecommitdiffstats
path: root/openpgp
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-02-06 17:51:51 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-02-06 17:51:51 +0100
commit020ee5d5f420ec47d09f831cb0d7dc5198d3da52 (patch)
treef7e296dcbf36e425d357e4bbb1aba147f083589e /openpgp
parent7e7071cdd64ad387ac82af259a3a44c5488b2392 (diff)
openpgp: Return previous value in setters.
- See #147.
Diffstat (limited to 'openpgp')
-rw-r--r--openpgp/src/packet/aed.rs12
-rw-r--r--openpgp/src/packet/compressed_data.rs4
-rw-r--r--openpgp/src/packet/key.rs12
-rw-r--r--openpgp/src/packet/literal.rs4
-rw-r--r--openpgp/src/packet/one_pass_sig.rs24
-rw-r--r--openpgp/src/packet/pkesk.rs12
-rw-r--r--openpgp/src/packet/signature/mod.rs12
-rw-r--r--openpgp/src/packet/skesk.rs20
-rw-r--r--openpgp/src/packet/unknown.rs8
-rw-r--r--openpgp/src/packet/user_attribute.rs4
-rw-r--r--openpgp/src/packet/userid.rs6
11 files changed, 59 insertions, 59 deletions
diff --git a/openpgp/src/packet/aed.rs b/openpgp/src/packet/aed.rs
index 7bf23bcb..23a34952 100644
--- a/openpgp/src/packet/aed.rs
+++ b/openpgp/src/packet/aed.rs
@@ -70,8 +70,8 @@ impl AED {
}
/// Sets the cipher algorithm.
- pub fn set_cipher(&mut self, cipher: SymmetricAlgorithm) {
- self.cipher = cipher;
+ pub fn set_cipher(&mut self, cipher: SymmetricAlgorithm) -> SymmetricAlgorithm {
+ ::std::mem::replace(&mut self.cipher, cipher)
}
/// Gets the AEAD algorithm.
@@ -80,8 +80,8 @@ impl AED {
}
/// Sets the AEAD algorithm.
- pub fn set_aead(&mut self, aead: AEADAlgorithm) {
- self.aead = aead;
+ pub fn set_aead(&mut self, aead: AEADAlgorithm) -> AEADAlgorithm {
+ ::std::mem::replace(&mut self.aead, aead)
}
/// Gets the chunk size.
@@ -118,8 +118,8 @@ impl AED {
}
/// Sets the initialization vector for the AEAD algorithm.
- pub fn set_iv(&mut self, iv: Box<[u8]>) {
- self.iv = iv;
+ pub fn set_iv(&mut self, iv: Box<[u8]>) -> Box<[u8]> {
+ ::std::mem::replace(&mut self.iv, iv)
}
}
diff --git a/openpgp/src/packet/compressed_data.rs b/openpgp/src/packet/compressed_data.rs
index cda495ba..8a2af0fc 100644
--- a/openpgp/src/packet/compressed_data.rs
+++ b/openpgp/src/packet/compressed_data.rs
@@ -52,8 +52,8 @@ impl CompressedData {
}
/// Sets the compression algorithm.
- pub fn set_algorithm(&mut self, algo: CompressionAlgorithm) {
- self.algo = algo;
+ pub fn set_algorithm(&mut self, algo: CompressionAlgorithm) -> CompressionAlgorithm {
+ ::std::mem::replace(&mut self.algo, algo)
}
/// Adds a new packet to the container.
diff --git a/openpgp/src/packet/key.rs b/openpgp/src/packet/key.rs
index cefb50b2..3dc5deae 100644
--- a/openpgp/src/packet/key.rs
+++ b/openpgp/src/packet/key.rs
@@ -243,8 +243,8 @@ impl Key {
}
/// Sets the key packet's creation time field.
- pub fn set_creation_time(&mut self, timestamp: time::Tm) {
- self.creation_time = timestamp.canonicalize();
+ pub fn set_creation_time(&mut self, timestamp: time::Tm) -> time::Tm {
+ ::std::mem::replace(&mut self.creation_time, timestamp.canonicalize())
}
/// Gets the public key algorithm.
@@ -253,8 +253,8 @@ impl Key {
}
/// Sets the public key algorithm.
- pub fn set_pk_algo(&mut self, pk_algo: PublicKeyAlgorithm) {
- self.pk_algo = pk_algo;
+ pub fn set_pk_algo(&mut self, pk_algo: PublicKeyAlgorithm) -> PublicKeyAlgorithm {
+ ::std::mem::replace(&mut self.pk_algo, pk_algo)
}
/// Gets the key packet's MPIs.
@@ -268,8 +268,8 @@ impl Key {
}
/// Sets the key packet's MPIs.
- pub fn set_mpis(&mut self, mpis: mpis::PublicKey) {
- self.mpis = mpis;
+ pub fn set_mpis(&mut self, mpis: mpis::PublicKey) -> mpis::PublicKey {
+ ::std::mem::replace(&mut self.mpis, mpis)
}
/// Gets the key packet's SecretKey.
diff --git a/openpgp/src/packet/literal.rs b/openpgp/src/packet/literal.rs
index 48b31775..f4d09321 100644
--- a/openpgp/src/packet/literal.rs
+++ b/openpgp/src/packet/literal.rs
@@ -96,8 +96,8 @@ impl Literal {
}
/// Sets the Literal packet's content disposition.
- pub fn set_format(&mut self, format: DataFormat) {
- self.format = format;
+ pub fn set_format(&mut self, format: DataFormat) -> DataFormat {
+ ::std::mem::replace(&mut self.format, format)
}
/// Gets the literal packet's filename.
diff --git a/openpgp/src/packet/one_pass_sig.rs b/openpgp/src/packet/one_pass_sig.rs
index d094bb58..0741c590 100644
--- a/openpgp/src/packet/one_pass_sig.rs
+++ b/openpgp/src/packet/one_pass_sig.rs
@@ -87,8 +87,8 @@ impl OnePassSig {
}
/// Sets the signature type.
- pub fn set_sigtype(&mut self, t: SignatureType) {
- self.sigtype = t;
+ pub fn set_sigtype(&mut self, t: SignatureType) -> SignatureType {
+ ::std::mem::replace(&mut self.sigtype, t)
}
/// Gets the public key algorithm.
@@ -97,8 +97,8 @@ impl OnePassSig {
}
/// Sets the public key algorithm.
- pub fn set_pk_algo(&mut self, algo: PublicKeyAlgorithm) {
- self.pk_algo = algo;
+ pub fn set_pk_algo(&mut self, algo: PublicKeyAlgorithm) -> PublicKeyAlgorithm {
+ ::std::mem::replace(&mut self.pk_algo, algo)
}
/// Gets the hash algorithm.
@@ -107,8 +107,8 @@ impl OnePassSig {
}
/// Sets the hash algorithm.
- pub fn set_hash_algo(&mut self, algo: HashAlgorithm) {
- self.hash_algo = algo;
+ pub fn set_hash_algo(&mut self, algo: HashAlgorithm) -> HashAlgorithm {
+ ::std::mem::replace(&mut self.hash_algo, algo)
}
/// Gets the issuer.
@@ -117,8 +117,8 @@ impl OnePassSig {
}
/// Sets the issuer.
- pub fn set_issuer(&mut self, issuer: KeyID) {
- self.issuer = issuer;
+ pub fn set_issuer(&mut self, issuer: KeyID) -> KeyID {
+ ::std::mem::replace(&mut self.issuer, issuer)
}
/// Gets the last flag.
@@ -127,8 +127,8 @@ impl OnePassSig {
}
/// Sets the last flag.
- pub fn set_last(&mut self, last: bool) {
- self.last = if last { 1 } else { 0 };
+ pub fn set_last(&mut self, last: bool) -> bool {
+ ::std::mem::replace(&mut self.last, if last { 1 } else { 0 }) > 0
}
/// Gets the raw value of the last flag.
@@ -137,8 +137,8 @@ impl OnePassSig {
}
/// Sets the raw value of the last flag.
- pub fn set_last_raw(&mut self, last: u8) {
- self.last = last;
+ pub fn set_last_raw(&mut self, last: u8) -> u8 {
+ ::std::mem::replace(&mut self.last, last)
}
}
diff --git a/openpgp/src/packet/pkesk.rs b/openpgp/src/packet/pkesk.rs
index 63d68182..26924858 100644
--- a/openpgp/src/packet/pkesk.rs
+++ b/openpgp/src/packet/pkesk.rs
@@ -120,8 +120,8 @@ impl PKESK {
}
/// Sets the recipient.
- pub fn set_recipient(&mut self, recipient: KeyID) {
- self.recipient = recipient;
+ pub fn set_recipient(&mut self, recipient: KeyID) -> KeyID {
+ ::std::mem::replace(&mut self.recipient, recipient)
}
/// Gets the public key algorithm.
@@ -130,8 +130,8 @@ impl PKESK {
}
/// Sets the public key algorithm.
- pub fn set_pk_algo(&mut self, algo: PublicKeyAlgorithm) {
- self.pk_algo = algo;
+ pub fn set_pk_algo(&mut self, algo: PublicKeyAlgorithm) -> PublicKeyAlgorithm {
+ ::std::mem::replace(&mut self.pk_algo, algo)
}
/// Gets the encrypted session key.
@@ -140,8 +140,8 @@ impl PKESK {
}
/// Sets the encrypted session key.
- pub fn set_esk(&mut self, esk: Ciphertext) {
- self.esk = esk;
+ pub fn set_esk(&mut self, esk: Ciphertext) -> Ciphertext {
+ ::std::mem::replace(&mut self.esk, esk)
}
/// Decrypts the ESK and returns the session key and symmetric algorithm
diff --git a/openpgp/src/packet/signature/mod.rs b/openpgp/src/packet/signature/mod.rs
index cbee74e7..dfb3059c 100644
--- a/openpgp/src/packet/signature/mod.rs
+++ b/openpgp/src/packet/signature/mod.rs
@@ -389,8 +389,8 @@ impl Signature {
}
/// Sets the hash prefix.
- pub fn set_hash_prefix(&mut self, prefix: [u8; 2]) {
- self.hash_prefix = prefix;
+ pub fn set_hash_prefix(&mut self, prefix: [u8; 2]) -> [u8; 2] {
+ ::std::mem::replace(&mut self.hash_prefix, prefix)
}
/// Gets the signature packet's MPIs.
@@ -399,8 +399,8 @@ impl Signature {
}
/// Sets the signature packet's MPIs.
- pub fn set_mpis(&mut self, mpis: mpis::Signature) {
- self.mpis = mpis;
+ pub fn set_mpis(&mut self, mpis: mpis::Signature) -> mpis::Signature {
+ ::std::mem::replace(&mut self.mpis, mpis)
}
/// Gets the computed hash value.
@@ -428,8 +428,8 @@ impl Signature {
/// A level of 0 indicates that the signature is directly over the
/// data, a level of 1 means that the signature is a notarization
/// over all level 0 signatures and the data, and so on.
- pub fn set_level(&mut self, level: usize) {
- self.level = level;
+ pub fn set_level(&mut self, level: usize) -> usize {
+ ::std::mem::replace(&mut self.level, level)
}
/// Gets the issuer.
diff --git a/openpgp/src/packet/skesk.rs b/openpgp/src/packet/skesk.rs
index f0515cc4..b5d9eba0 100644
--- a/openpgp/src/packet/skesk.rs
+++ b/openpgp/src/packet/skesk.rs
@@ -146,8 +146,8 @@ impl SKESK4 {
}
/// Sets the symmetric encryption algorithm.
- pub fn set_symmetric_algo(&mut self, algo: SymmetricAlgorithm) {
- self.symm_algo = algo;
+ pub fn set_symmetric_algo(&mut self, algo: SymmetricAlgorithm) -> SymmetricAlgorithm {
+ ::std::mem::replace(&mut self.symm_algo, algo)
}
/// Gets the key derivation method.
@@ -156,8 +156,8 @@ impl SKESK4 {
}
/// Sets the key derivation method.
- pub fn set_s2k(&mut self, s2k: S2K) {
- self.s2k = s2k;
+ pub fn set_s2k(&mut self, s2k: S2K) -> S2K {
+ ::std::mem::replace(&mut self.s2k, s2k)
}
/// Gets the encrypted session key.
@@ -360,8 +360,8 @@ impl SKESK5 {
}
/// Sets the AEAD algorithm.
- pub fn set_aead_algo(&mut self, algo: AEADAlgorithm) {
- self.aead_algo = algo;
+ pub fn set_aead_algo(&mut self, algo: AEADAlgorithm) -> AEADAlgorithm {
+ ::std::mem::replace(&mut self.aead_algo, algo)
}
/// Gets the AEAD initialization vector.
@@ -370,8 +370,8 @@ impl SKESK5 {
}
/// Sets the AEAD initialization vector.
- pub fn set_aead_iv(&mut self, iv: Box<[u8]>) {
- self.aead_iv = iv;
+ pub fn set_aead_iv(&mut self, iv: Box<[u8]>) -> Box<[u8]> {
+ ::std::mem::replace(&mut self.aead_iv, iv)
}
/// Gets the AEAD digest.
@@ -380,8 +380,8 @@ impl SKESK5 {
}
/// Sets the AEAD digest.
- pub fn set_aead_digest(&mut self, digest: Box<[u8]>) {
- self.aead_digest = digest;
+ pub fn set_aead_digest(&mut self, digest: Box<[u8]>) -> Box<[u8]> {
+ ::std::mem::replace(&mut self.aead_digest, digest)
}
}
diff --git a/openpgp/src/packet/unknown.rs b/openpgp/src/packet/unknown.rs
index 77c7ff3c..86dd937a 100644
--- a/openpgp/src/packet/unknown.rs
+++ b/openpgp/src/packet/unknown.rs
@@ -63,8 +63,8 @@ impl Unknown {
}
/// Sets the unknown packet's tag.
- pub fn set_tag(&mut self, tag: Tag) {
- self.tag = tag;
+ pub fn set_tag(&mut self, tag: Tag) -> Tag {
+ ::std::mem::replace(&mut self.tag, tag)
}
/// Gets the unknown packet's error.
@@ -95,8 +95,8 @@ impl Unknown {
/// This is the raw packet content not include the CTB and length
/// information, and not encoded using something like OpenPGP's
/// partial body encoding.
- pub fn set_body(&mut self, data: Vec<u8>) {
- self.common.body = Some(data);
+ pub fn set_body(&mut self, data: Vec<u8>) -> Option<Vec<u8>> {
+ ::std::mem::replace(&mut self.common.body, Some(data))
}
}
diff --git a/openpgp/src/packet/user_attribute.rs b/openpgp/src/packet/user_attribute.rs
index 38007a8c..bd8fe1da 100644
--- a/openpgp/src/packet/user_attribute.rs
+++ b/openpgp/src/packet/user_attribute.rs
@@ -59,8 +59,8 @@ impl UserAttribute {
}
/// Sets the user attribute packet's value from a byte sequence.
- pub fn set_user_attribute(&mut self, value: &[u8]) {
- self.value = value.to_vec();
+ pub fn set_user_attribute(&mut self, value: &[u8]) -> Vec<u8> {
+ ::std::mem::replace(&mut self.value, value.to_vec())
}
}
diff --git a/openpgp/src/packet/userid.rs b/openpgp/src/packet/userid.rs
index e3dcf625..50708a5a 100644
--- a/openpgp/src/packet/userid.rs
+++ b/openpgp/src/packet/userid.rs
@@ -75,12 +75,12 @@ impl UserID {
}
/// Sets the user ID packet's value from a byte sequence.
- pub fn set_userid_from_bytes(&mut self, userid: &[u8]) {
- self.value = userid.to_vec();
+ pub fn set_userid_from_bytes(&mut self, userid: &[u8]) -> Vec<u8> {
+ ::std::mem::replace(&mut self.value, userid.to_vec())
}
/// Sets the user ID packet's value from a UTF-8 encoded string.
- pub fn set_userid(&mut self, userid: &str) {
+ pub fn set_userid(&mut self, userid: &str) -> Vec<u8> {
self.set_userid_from_bytes(userid.as_bytes())
}
}