summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/src/lib.rs21
-rw-r--r--ffi/src/core.rs4
-rw-r--r--openpgp/src/packet/literal.rs29
-rw-r--r--openpgp/src/packet/mod.rs6
-rw-r--r--openpgp/src/packet/signature/mod.rs3
-rw-r--r--openpgp/src/packet/skesk.rs10
6 files changed, 44 insertions, 29 deletions
diff --git a/core/src/lib.rs b/core/src/lib.rs
index e261c64e..955496a1 100644
--- a/core/src/lib.rs
+++ b/core/src/lib.rs
@@ -233,8 +233,8 @@ impl Config {
}
/// Sets the directory containing shared state.
- pub fn set_home<P: AsRef<Path>>(&mut self, home: P) {
- self.0.home = PathBuf::new().join(home);
+ pub fn set_home<P: AsRef<Path>>(&mut self, home: P) -> PathBuf {
+ ::std::mem::replace(&mut self.0.home, PathBuf::new().join(home))
}
/// Sets the directory containing backend servers.
@@ -244,8 +244,8 @@ impl Config {
}
/// Sets the directory containing shared state.
- pub fn set_lib<P: AsRef<Path>>(&mut self, lib: P) {
- self.0.lib = PathBuf::new().join(lib);
+ pub fn set_lib<P: AsRef<Path>>(&mut self, lib: P) -> PathBuf {
+ ::std::mem::replace(&mut self.0.lib, PathBuf::new().join(lib))
}
/// Sets the network policy.
@@ -255,8 +255,9 @@ impl Config {
}
/// Sets the network policy.
- pub fn set_network_policy(&mut self, policy: NetworkPolicy) {
- self.0.network_policy = policy;
+ pub fn set_network_policy(&mut self, policy: NetworkPolicy) -> NetworkPolicy
+ {
+ ::std::mem::replace(&mut self.0.network_policy, policy)
}
/// Sets the IPC policy.
@@ -266,8 +267,8 @@ impl Config {
}
/// Sets the IPC policy.
- pub fn set_ipc_policy(&mut self, policy: IPCPolicy) {
- self.0.ipc_policy = policy;
+ pub fn set_ipc_policy(&mut self, policy: IPCPolicy) -> IPCPolicy {
+ ::std::mem::replace(&mut self.0.ipc_policy, policy)
}
/// Makes this context ephemeral.
@@ -277,8 +278,8 @@ impl Config {
}
/// Makes this context ephemeral.
- pub fn set_ephemeral(&mut self) {
- self.0.ephemeral = true;
+ pub fn set_ephemeral(&mut self) -> bool {
+ ::std::mem::replace(&mut self.0.ephemeral, true)
}
}
diff --git a/ffi/src/core.rs b/ffi/src/core.rs
index 12ff469d..8ad3a655 100644
--- a/ffi/src/core.rs
+++ b/ffi/src/core.rs
@@ -177,7 +177,7 @@ pub extern "system" fn sq_config_home(cfg: *mut Config,
home: *const c_char) {
let cfg = ffi_param_ref_mut!(cfg);
let home = ffi_param_cstr!(home).to_string_lossy();
- cfg.set_home(home.as_ref())
+ cfg.set_home(home.as_ref());
}
/// Set the directory containing backend servers.
@@ -186,7 +186,7 @@ pub extern "system" fn sq_config_lib(cfg: *mut Config,
lib: *const c_char) {
let cfg = ffi_param_ref_mut!(cfg);
let lib = ffi_param_cstr!(lib).to_string_lossy();
- cfg.set_lib(&lib.as_ref())
+ cfg.set_lib(&lib.as_ref());
}
/// Sets the network policy.
diff --git a/openpgp/src/packet/literal.rs b/openpgp/src/packet/literal.rs
index 85b90be4..e892ea2b 100644
--- a/openpgp/src/packet/literal.rs
+++ b/openpgp/src/packet/literal.rs
@@ -86,8 +86,8 @@ impl Literal {
}
/// Sets the Literal packet's body to the provided byte string.
- pub fn set_body(&mut self, data: Vec<u8>) {
- self.common.set_body(data);
+ pub fn set_body(&mut self, data: Vec<u8>) -> Vec<u8> {
+ self.common.set_body(data)
}
/// Gets the Literal packet's content disposition.
@@ -117,15 +117,15 @@ impl Literal {
/// Note: when a literal data packet is protected by a signature,
/// only the literal data packet's body is protected, not the
/// meta-data. As such, this field should not be used.
- pub fn set_filename_from_bytes(&mut self, filename: &[u8]) -> Result<()> {
- self.filename = match filename.len() {
+ pub fn set_filename_from_bytes(&mut self, filename: &[u8])
+ -> Result<Option<Vec<u8>>> {
+ Ok(::std::mem::replace(&mut self.filename, match filename.len() {
0 => None,
1...255 => Some(filename.to_vec()),
n => return
Err(Error::InvalidArgument(
format!("filename too long: {} bytes", n)).into()),
- };
- Ok(())
+ }))
}
/// Sets the literal packet's filename field from a UTF-8 encoded
@@ -137,7 +137,8 @@ impl Literal {
/// Note: when a literal data packet is protected by a signature,
/// only the literal data packet's body is protected, not the
/// meta-data. As such, this field should not be used.
- pub fn set_filename(&mut self, filename: &str) -> Result<()> {
+ pub fn set_filename(&mut self, filename: &str)
+ -> Result<Option<Vec<u8>>> {
self.set_filename_from_bytes(filename.as_bytes())
}
@@ -159,9 +160,17 @@ impl Literal {
/// Note: when a literal data packet is protected by a signature,
/// only the literal data packet's body is protected, not the
/// meta-data. As such, this field should not be used.
- pub fn set_date(&mut self, timestamp: Option<time::Tm>) {
- self.date = timestamp.map(|t| t.canonicalize())
- .unwrap_or(time::Tm::from_pgp(0));
+ pub fn set_date(&mut self, timestamp: Option<time::Tm>) -> Option<time::Tm>
+ {
+ let old = ::std::mem::replace(
+ &mut self.date,
+ timestamp.map(|t| t.canonicalize())
+ .unwrap_or(time::Tm::from_pgp(0)));
+ if old == time::Tm::from_pgp(0) {
+ None
+ } else {
+ Some(old)
+ }
}
}
diff --git a/openpgp/src/packet/mod.rs b/openpgp/src/packet/mod.rs
index 7f8e1007..6f1bacf8 100644
--- a/openpgp/src/packet/mod.rs
+++ b/openpgp/src/packet/mod.rs
@@ -342,9 +342,11 @@ impl Common {
///
/// Setting the body clears the old body, or any of the packet's
/// descendants.
- pub fn set_body(&mut self, data: Vec<u8>) {
+ pub fn set_body(&mut self, data: Vec<u8>) -> Vec<u8> {
self.children = None;
- self.body = if data.len() == 0 { None } else { Some(data) };
+ ::std::mem::replace(&mut self.body,
+ if data.len() == 0 { None } else { Some(data) })
+ .unwrap_or(Vec::new())
}
}
diff --git a/openpgp/src/packet/signature/mod.rs b/openpgp/src/packet/signature/mod.rs
index 8097d149..f207a535 100644
--- a/openpgp/src/packet/signature/mod.rs
+++ b/openpgp/src/packet/signature/mod.rs
@@ -411,8 +411,9 @@ impl Signature {
/// Sets the computed hash value.
pub fn set_computed_hash(&mut self, hash: Option<(HashAlgorithm, Vec<u8>)>)
+ -> Option<(HashAlgorithm, Vec<u8>)>
{
- self.computed_hash = hash;
+ ::std::mem::replace(&mut self.computed_hash, hash)
}
/// Gets the signature level.
diff --git a/openpgp/src/packet/skesk.rs b/openpgp/src/packet/skesk.rs
index 5a929f25..256a1c8d 100644
--- a/openpgp/src/packet/skesk.rs
+++ b/openpgp/src/packet/skesk.rs
@@ -166,10 +166,12 @@ impl SKESK4 {
}
/// Sets the encrypted session key.
- pub fn set_esk(&mut self, esk: Option<Vec<u8>>) {
- self.esk = esk.and_then(|esk| {
- if esk.len() == 0 { None } else { Some(esk) }
- });
+ pub fn set_esk(&mut self, esk: Option<Vec<u8>>) -> Option<Vec<u8>> {
+ ::std::mem::replace(
+ &mut self.esk,
+ esk.and_then(|esk| {
+ if esk.len() == 0 { None } else { Some(esk) }
+ }))
}
/// Convert the `SKESK4` struct to a `Packet`.