summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2020-01-10 13:11:45 +0100
committerNeal H. Walfield <neal@pep.foundation>2020-01-10 13:56:11 +0100
commit71fc2c6afbcbf4cc4e060dd59300e8065e699323 (patch)
treec1b4ae762fcea2a137bb8c585d9e47bc86402357
parentb64d45cf84cb7baee3a88a12f1cbf52ad3fb74d3 (diff)
openpgp: Pass MessageStructure by value, not reference.
- Instead of passing MessageStructure to VerificationHelper::check by reference, pass it by value. - After calling VerificationHelper::check, it is dropped. Passing it by value allows the caller to avoid some cloning.
-rw-r--r--guide/src/chapter_01.md8
-rw-r--r--guide/src/chapter_02.md8
-rw-r--r--ipc/examples/gpg-agent-decrypt.rs2
-rw-r--r--ipc/tests/gpg-agent.rs4
-rw-r--r--openpgp-ffi/src/parse/stream.rs4
-rw-r--r--openpgp/examples/decrypt-with.rs2
-rw-r--r--openpgp/examples/generate-encrypt-decrypt.rs2
-rw-r--r--openpgp/examples/generate-sign-verify.rs2
-rw-r--r--openpgp/src/parse/stream.rs16
-rw-r--r--openpgp/src/serialize/stream.rs6
-rw-r--r--tool/src/commands/decrypt.rs2
-rw-r--r--tool/src/commands/mod.rs2
12 files changed, 29 insertions, 29 deletions
diff --git a/guide/src/chapter_01.md b/guide/src/chapter_01.md
index 78978161..fa4b505c 100644
--- a/guide/src/chapter_01.md
+++ b/guide/src/chapter_01.md
@@ -102,7 +102,7 @@ fn main() {
# Ok(vec![self.cert.clone()])
# }
#
-# fn check(&mut self, structure: &MessageStructure)
+# fn check(&mut self, structure: MessageStructure)
# -> openpgp::Result<()> {
# // In this function, we implement our signature verification
# // policy.
@@ -247,7 +247,7 @@ fn generate() -> openpgp::Result<openpgp::Cert> {
# Ok(vec![self.cert.clone()])
# }
#
-# fn check(&mut self, structure: &MessageStructure)
+# fn check(&mut self, structure: MessageStructure)
# -> openpgp::Result<()> {
# // In this function, we implement our signature verification
# // policy.
@@ -392,7 +392,7 @@ fn sign(sink: &mut Write, plaintext: &str, tsk: &openpgp::Cert)
# Ok(vec![self.cert.clone()])
# }
#
-# fn check(&mut self, structure: &MessageStructure)
+# fn check(&mut self, structure: MessageStructure)
# -> openpgp::Result<()> {
# // In this function, we implement our signature verification
# // policy.
@@ -548,7 +548,7 @@ impl<'a> VerificationHelper for Helper<'a> {
Ok(vec![self.cert.clone()])
}
- fn check(&mut self, structure: &MessageStructure)
+ fn check(&mut self, structure: MessageStructure)
-> openpgp::Result<()> {
// In this function, we implement our signature verification
// policy.
diff --git a/guide/src/chapter_02.md b/guide/src/chapter_02.md
index f6cb4b48..c9c22961 100644
--- a/guide/src/chapter_02.md
+++ b/guide/src/chapter_02.md
@@ -109,7 +109,7 @@ fn main() {
# Ok(Vec::new())
# }
#
-# fn check(&mut self, _structure: &MessageStructure)
+# fn check(&mut self, _structure: MessageStructure)
# -> openpgp::Result<()> {
# // Implement your signature verification policy here.
# Ok(())
@@ -250,7 +250,7 @@ fn generate() -> openpgp::Result<openpgp::Cert> {
# Ok(Vec::new())
# }
#
-# fn check(&mut self, _structure: &MessageStructure)
+# fn check(&mut self, _structure: MessageStructure)
# -> openpgp::Result<()> {
# // Implement your signature verification policy here.
# Ok(())
@@ -391,7 +391,7 @@ fn encrypt(sink: &mut Write, plaintext: &str, recipient: &openpgp::Cert)
# Ok(Vec::new())
# }
#
-# fn check(&mut self, _structure: &MessageStructure)
+# fn check(&mut self, _structure: MessageStructure)
# -> openpgp::Result<()> {
# // Implement your signature verification policy here.
# Ok(())
@@ -546,7 +546,7 @@ impl<'a> VerificationHelper for Helper<'a> {
Ok(Vec::new())
}
- fn check(&mut self, _structure: &MessageStructure)
+ fn check(&mut self, _structure: MessageStructure)
-> openpgp::Result<()> {
// Implement your signature verification policy here.
Ok(())
diff --git a/ipc/examples/gpg-agent-decrypt.rs b/ipc/examples/gpg-agent-decrypt.rs
index e76028ec..fe692689 100644
--- a/ipc/examples/gpg-agent-decrypt.rs
+++ b/ipc/examples/gpg-agent-decrypt.rs
@@ -116,7 +116,7 @@ impl<'a> VerificationHelper for Helper<'a> {
-> failure::Fallible<Vec<openpgp::Cert>> {
Ok(Vec::new()) // Feed the Certs to the verifier here.
}
- fn check(&mut self, structure: &MessageStructure)
+ fn check(&mut self, structure: MessageStructure)
-> failure::Fallible<()> {
use self::VerificationResult::*;
for layer in structure.iter() {
diff --git a/ipc/tests/gpg-agent.rs b/ipc/tests/gpg-agent.rs
index bc2967a2..6555f3a3 100644
--- a/ipc/tests/gpg-agent.rs
+++ b/ipc/tests/gpg-agent.rs
@@ -147,7 +147,7 @@ fn sign() {
Ok(vec![self.cert.clone()])
}
- fn check(&mut self, structure: &MessageStructure)
+ fn check(&mut self, structure: MessageStructure)
-> openpgp::Result<()> {
// In this function, we implement our signature verification
// policy.
@@ -258,7 +258,7 @@ fn decrypt() {
Ok(Vec::new())
}
- fn check(&mut self, _structure: &MessageStructure)
+ fn check(&mut self, _structure: MessageStructure)
-> openpgp::Result<()> {
// Implement your signature verification policy here.
Ok(())
diff --git a/openpgp-ffi/src/parse/stream.rs b/openpgp-ffi/src/parse/stream.rs
index 49778ad1..9780da0c 100644
--- a/openpgp-ffi/src/parse/stream.rs
+++ b/openpgp-ffi/src/parse/stream.rs
@@ -381,7 +381,7 @@ impl VerificationHelper for VHelper {
Ok(certs)
}
- fn check(&mut self, structure: &stream::MessageStructure)
+ fn check(&mut self, structure: stream::MessageStructure)
-> Result<(), failure::Error>
{
let result = (self.check_signatures_cb)(self.cookie,
@@ -666,7 +666,7 @@ impl VerificationHelper for DHelper {
self.vhelper.get_public_keys(ids)
}
- fn check(&mut self, structure: &stream::MessageStructure)
+ fn check(&mut self, structure: stream::MessageStructure)
-> Result<(), failure::Error>
{
self.vhelper.check(structure)
diff --git a/openpgp/examples/decrypt-with.rs b/openpgp/examples/decrypt-with.rs
index c28dbe1c..35393924 100644
--- a/openpgp/examples/decrypt-with.rs
+++ b/openpgp/examples/decrypt-with.rs
@@ -105,7 +105,7 @@ impl VerificationHelper for Helper {
-> failure::Fallible<Vec<openpgp::Cert>> {
Ok(Vec::new()) // Feed the Certs to the verifier here.
}
- fn check(&mut self, structure: &MessageStructure)
+ fn check(&mut self, structure: MessageStructure)
-> failure::Fallible<()> {
use self::VerificationResult::*;
for layer in structure.iter() {
diff --git a/openpgp/examples/generate-encrypt-decrypt.rs b/openpgp/examples/generate-encrypt-decrypt.rs
index d431e99c..4d456193 100644
--- a/openpgp/examples/generate-encrypt-decrypt.rs
+++ b/openpgp/examples/generate-encrypt-decrypt.rs
@@ -100,7 +100,7 @@ impl<'a> VerificationHelper for Helper<'a> {
Ok(Vec::new())
}
- fn check(&mut self, _structure: &MessageStructure)
+ fn check(&mut self, _structure: MessageStructure)
-> openpgp::Result<()> {
// Implement your signature verification policy here.
Ok(())
diff --git a/openpgp/examples/generate-sign-verify.rs b/openpgp/examples/generate-sign-verify.rs
index f238d368..fa75ed6d 100644
--- a/openpgp/examples/generate-sign-verify.rs
+++ b/openpgp/examples/generate-sign-verify.rs
@@ -93,7 +93,7 @@ impl<'a> VerificationHelper for Helper<'a> {
Ok(vec![self.cert.clone()])
}
- fn check(&mut self, structure: &MessageStructure)
+ fn check(&mut self, structure: MessageStructure)
-> openpgp::Result<()> {
// In this function, we implement our signature verification
// policy.
diff --git a/openpgp/src/parse/stream.rs b/openpgp/src/parse/stream.rs
index 3926299f..eddd54e2 100644
--- a/openpgp/src/parse/stream.rs
+++ b/openpgp/src/parse/stream.rs
@@ -89,7 +89,7 @@ const BUFFER_SIZE: usize = 25 * 1024 * 1024;
/// fn get_public_keys(&mut self, _ids: &[openpgp::KeyHandle]) -> Result<Vec<Cert>> {
/// Ok(Vec::new()) // Feed the Certs to the verifier here...
/// }
-/// fn check(&mut self, structure: &MessageStructure) -> Result<()> {
+/// fn check(&mut self, structure: MessageStructure) -> Result<()> {
/// Ok(()) // Implement your verification policy here.
/// }
/// }
@@ -450,7 +450,7 @@ pub trait VerificationHelper {
/// be called again. As such, any error returned by this function
/// will abort reading, and the error will be propagated via the
/// `io::Read` operation.
- fn check(&mut self, structure: &MessageStructure) -> Result<()>;
+ fn check(&mut self, structure: MessageStructure) -> Result<()>;
}
impl<'a, H: VerificationHelper> Verifier<'a, H> {
@@ -720,7 +720,7 @@ impl<'a, H: VerificationHelper> Verifier<'a, H> {
}
}
- self.helper.check(&results)
+ self.helper.check(results)
}
// If the amount of remaining data does not exceed the reserve,
@@ -1019,7 +1019,7 @@ impl<'a> io::Read for Transformer<'a> {
/// fn get_public_keys(&mut self, _ids: &[openpgp::KeyHandle]) -> Result<Vec<Cert>> {
/// Ok(Vec::new()) // Feed the Certs to the verifier here...
/// }
-/// fn check(&mut self, structure: &MessageStructure) -> Result<()> {
+/// fn check(&mut self, structure: MessageStructure) -> Result<()> {
/// Ok(()) // Implement your verification policy here.
/// }
/// }
@@ -1163,7 +1163,7 @@ impl DetachedVerifier {
/// fn get_public_keys(&mut self, _ids: &[openpgp::KeyHandle]) -> Result<Vec<Cert>> {
/// Ok(Vec::new()) // Feed the Certs to the verifier here...
/// }
-/// fn check(&mut self, structure: &MessageStructure) -> Result<()> {
+/// fn check(&mut self, structure: MessageStructure) -> Result<()> {
/// Ok(()) // Implement your verification policy here.
/// }
/// }
@@ -1635,7 +1635,7 @@ impl<'a, H: VerificationHelper + DecryptionHelper> Decryptor<'a, H> {
}
}
- self.helper.check(&results)
+ self.helper.check(results)
}
/// Like `io::Read::read()`, but returns our `Result`.
@@ -1747,7 +1747,7 @@ mod test {
Ok(self.keys.clone())
}
- fn check(&mut self, structure: &MessageStructure) -> Result<()> {
+ fn check(&mut self, structure: MessageStructure) -> Result<()> {
use self::VerificationResult::*;
for layer in structure.iter() {
match layer {
@@ -1869,7 +1869,7 @@ mod test {
Ok(Vec::new())
}
- fn check(&mut self, structure: &MessageStructure) -> Result<()> {
+ fn check(&mut self, structure: MessageStructure) -> Result<()> {
assert_eq!(structure.iter().count(), 2);
for (i, layer) in structure.iter().enumerate() {
match layer {
diff --git a/openpgp/src/serialize/stream.rs b/openpgp/src/serialize/stream.rs
index cabe130b..9c5977c9 100644
--- a/openpgp/src/serialize/stream.rs
+++ b/openpgp/src/serialize/stream.rs
@@ -252,7 +252,7 @@ impl<'a> Signer<'a> {
/// Ok(vec![self.0.clone()])
/// }
///
- /// fn check(&mut self, structure: &MessageStructure)
+ /// fn check(&mut self, structure: MessageStructure)
/// -> openpgp::Result<()> {
/// if let MessageLayer::SignatureGroup { ref results } =
/// structure.iter().nth(0).unwrap()
@@ -359,7 +359,7 @@ impl<'a> Signer<'a> {
/// Ok(vec![self.0.clone()])
/// }
///
- /// fn check(&mut self, structure: &MessageStructure)
+ /// fn check(&mut self, structure: MessageStructure)
/// -> openpgp::Result<()> {
/// if let MessageLayer::SignatureGroup { ref results } =
/// structure.iter().nth(0).unwrap()
@@ -1665,7 +1665,7 @@ mod test {
-> Result<Vec<Cert>> {
Ok(Vec::new())
}
- fn check(&mut self, _structure: &MessageStructure) -> Result<()> {
+ fn check(&mut self, _structure: MessageStructure) -> Result<()> {
Ok(())
}
}
diff --git a/tool/src/commands/decrypt.rs b/tool/src/commands/decrypt.rs
index 2ab0f32c..325a657d 100644
--- a/tool/src/commands/decrypt.rs
+++ b/tool/src/commands/decrypt.rs
@@ -130,7 +130,7 @@ impl<'a> VerificationHelper for Helper<'a> {
fn get_public_keys(&mut self, ids: &[openpgp::KeyHandle]) -> Result<Vec<Cert>> {
self.vhelper.get_public_keys(ids)
}
- fn check(&mut self, structure: &MessageStructure) -> Result<()> {
+ fn check(&mut self, structure: MessageStructure) -> Result<()> {
self.vhelper.check(structure)
}
}
diff --git a/tool/src/commands/mod.rs b/tool/src/commands/mod.rs
index 12ca6c6a..25b94198 100644
--- a/tool/src/commands/mod.rs
+++ b/tool/src/commands/mod.rs
@@ -356,7 +356,7 @@ impl<'a> VerificationHelper for VHelper<'a> {
Ok(certs)
}
- fn check(&mut self, structure: &MessageStructure) -> Result<()> {
+ fn check(&mut self, structure: MessageStructure) -> Result<()> {
for layer in structure.iter() {
match layer {
MessageLayer::Compression { algo } =>