summaryrefslogtreecommitdiffstats
path: root/openpgp
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-05-07 16:30:17 +0200
committerJustus Winter <justus@sequoia-pgp.org>2020-05-07 17:00:52 +0200
commitcf565c026d3a563053f28078eb6c88d4c58e0ba0 (patch)
tree1af6653ab8a3965199496f7eb5de95e171004dff /openpgp
parent3eb554d0980ae788df2a07df609b77e01b7e57ce (diff)
openpgp: Configure mapping in the builder, remove from Helper trait.
- See #498.
Diffstat (limited to 'openpgp')
-rw-r--r--openpgp/src/parse/stream.rs77
1 files changed, 57 insertions, 20 deletions
diff --git a/openpgp/src/parse/stream.rs b/openpgp/src/parse/stream.rs
index 8ed01f94..2f1747e9 100644
--- a/openpgp/src/parse/stream.rs
+++ b/openpgp/src/parse/stream.rs
@@ -509,21 +509,6 @@ enum IMessageLayer {
///
/// [`Map`]: ../map/struct.Map.html
pub trait VerificationHelper {
- /// Turns mapping on or off.
- ///
- /// If this function returns true, the packet parser will create a
- /// [`Map`] of the packets. Note that this buffers the packets
- /// contents, and is not recommended unless you know that the
- /// packets are small. This is called once before parsing the
- /// first packet.
- ///
- /// [`Map`]: ../map/struct.Map.html
- ///
- /// The default implementation returns false.
- fn mapping(&self) -> bool {
- false
- }
-
/// Inspects the message.
///
/// Called once per packet. Can be used to inspect and dump
@@ -782,6 +767,7 @@ pub struct Verifier<'a, H: VerificationHelper> {
/// [`VerifierBuilder::with_policy`]: struct.VerifierBuilder.html#method.with_policy
pub struct VerifierBuilder<'a> {
message: Box<dyn BufferedReader<Cookie> + 'a>,
+ mapping: bool,
}
impl<'a> Parse<'a, VerifierBuilder<'a>>
@@ -815,9 +801,25 @@ impl<'a> VerifierBuilder<'a> {
{
Ok(VerifierBuilder {
message: Box::new(signatures),
+ mapping: false,
})
}
+ /// Enables mapping.
+ ///
+ /// If mapping is enabled, the packet parser will create a [`Map`]
+ /// of the packets that can be inspected in
+ /// [`VerificationHelper::inspect`]. Note that this buffers the
+ /// packets contents, and is not recommended unless you know that
+ /// the packets are small.
+ ///
+ /// [`Map`]: ../map/struct.Map.html
+ /// [`VerificationHelper::inspect`]: trait.VerificationHelper.html#tymethod.inspect
+ pub fn mapping(mut self, enabled: bool) -> Self {
+ self.mapping = enabled;
+ self
+ }
+
/// Creates the `Verifier`.
///
/// Signature verifications are done under the given `policy` and
@@ -837,7 +839,7 @@ impl<'a> VerifierBuilder<'a> {
policy,
self.message,
NoDecryptionHelper { v: helper, },
- t, Mode::Verify)?,
+ t, Mode::Verify, self.mapping)?,
})
}
}
@@ -929,6 +931,7 @@ pub struct DetachedVerifier<'a, H: VerificationHelper> {
/// [`DetachedVerifierBuilder::with_policy`]: struct.DetachedVerifierBuilder.html#method.with_policy
pub struct DetachedVerifierBuilder<'a> {
signatures: Box<dyn BufferedReader<Cookie> + 'a>,
+ mapping: bool,
}
impl<'a> Parse<'a, DetachedVerifierBuilder<'a>>
@@ -962,9 +965,25 @@ impl<'a> DetachedVerifierBuilder<'a> {
{
Ok(DetachedVerifierBuilder {
signatures: Box::new(signatures),
+ mapping: false,
})
}
+ /// Enables mapping.
+ ///
+ /// If mapping is enabled, the packet parser will create a [`Map`]
+ /// of the packets that can be inspected in
+ /// [`VerificationHelper::inspect`]. Note that this buffers the
+ /// packets contents, and is not recommended unless you know that
+ /// the packets are small.
+ ///
+ /// [`Map`]: ../map/struct.Map.html
+ /// [`VerificationHelper::inspect`]: trait.VerificationHelper.html#tymethod.inspect
+ pub fn mapping(mut self, enabled: bool) -> Self {
+ self.mapping = enabled;
+ self
+ }
+
/// Creates the `DetachedVerifier`.
///
/// Signature verifications are done under the given `policy` and
@@ -984,7 +1003,7 @@ impl<'a> DetachedVerifierBuilder<'a> {
policy,
self.signatures,
NoDecryptionHelper { v: helper, },
- t, Mode::VerifyDetached)?,
+ t, Mode::VerifyDetached, self.mapping)?,
})
}
}
@@ -1157,6 +1176,7 @@ pub struct Decryptor<'a, H: VerificationHelper + DecryptionHelper> {
/// [`DecryptorBuilder::with_policy`]: struct.DecryptorBuilder.html#method.with_policy
pub struct DecryptorBuilder<'a> {
message: Box<dyn BufferedReader<Cookie> + 'a>,
+ mapping: bool,
}
impl<'a> Parse<'a, DecryptorBuilder<'a>>
@@ -1190,9 +1210,25 @@ impl<'a> DecryptorBuilder<'a> {
{
Ok(DecryptorBuilder {
message: Box::new(signatures),
+ mapping: false,
})
}
+ /// Enables mapping.
+ ///
+ /// If mapping is enabled, the packet parser will create a [`Map`]
+ /// of the packets that can be inspected in
+ /// [`VerificationHelper::inspect`]. Note that this buffers the
+ /// packets contents, and is not recommended unless you know that
+ /// the packets are small.
+ ///
+ /// [`Map`]: ../map/struct.Map.html
+ /// [`VerificationHelper::inspect`]: trait.VerificationHelper.html#tymethod.inspect
+ pub fn mapping(mut self, enabled: bool) -> Self {
+ self.mapping = enabled;
+ self
+ }
+
/// Creates the `Decryptor`.
///
/// Signature verifications are done under the given `policy` and
@@ -1213,7 +1249,7 @@ impl<'a> DecryptorBuilder<'a> {
policy,
self.message,
helper,
- t, Mode::Decrypt)
+ t, Mode::Decrypt, self.mapping)
}
}
@@ -1399,7 +1435,8 @@ impl<'a, H: VerificationHelper + DecryptionHelper> Decryptor<'a, H> {
policy: &'a dyn Policy,
bio: Box<dyn BufferedReader<Cookie> + 'a>,
helper: H, time: T,
- mode: Mode)
+ mode: Mode,
+ mapping: bool)
-> Result<Decryptor<'a, H>>
where T: Into<Option<time::SystemTime>>
{
@@ -1413,7 +1450,7 @@ impl<'a, H: VerificationHelper + DecryptionHelper> Decryptor<'a, H> {
let time = time.unwrap_or_else(time::SystemTime::now);
let mut ppr = PacketParserBuilder::from_buffered_reader(bio)?
- .map(helper.mapping()).build()?;
+ .map(mapping).build()?;
let mut v = Decryptor {
helper,