//! Streaming decryption and verification.
//!
//! This module provides convenient filters for decryption and
//! verification of OpenPGP messages.
use std::cmp;
use std::collections::HashMap;
use std::io::{self, Read};
use std::path::Path;
use buffered_reader::{
BufferedReader, BufferedReaderGeneric, BufferedReaderMemory,
BufferedReaderFile,
};
use {
Error,
Fingerprint,
constants::SymmetricAlgorithm,
packet::{Key, PKESK, SKESK},
KeyID,
Packet,
Result,
packet,
packet::Signature,
TPK,
mpis,
Password,
SessionKey,
};
use parse::{
Cookie,
PacketParser,
PacketParserBuilder,
PacketParserResult,
};
/// How much data to buffer before giving it to the caller.
const BUFFER_SIZE: usize = 25 * 1024 * 1024;
/// Verifies a signed OpenPGP message.
///
/// Signature verification requires processing the whole message
/// first. Therefore, OpenPGP implementations supporting streaming
/// operations necessarily must output unverified data. This has been
/// a source of problems in the past. To alleviate this, we buffer up
/// to 25 megabytes of net message data first, and verify the
/// signatures if the message fits into our buffer. Nevertheless it
/// is important to treat the data as unverified and untrustworthy
/// until you have seen a positive verification.
///
/// # Example
///
/// ```
/// #[macro_use] extern crate openpgp;
/// extern crate failure;
/// use std::io::Read;
/// use openpgp::{KeyID, TPK, Result};
/// use openpgp::parse::stream::*;
/// # fn main() { f().unwrap(); }
/// # fn f() -> Result<()> {
///
/// // This fetches keys and computes the validity of the verification.
/// struct Helper {};
/// impl VerificationHelper for Helper {
/// f