//! OpenPGP Message support.
//!
//! An OpenPGP message is a sequence of OpenPGP packets that
//! corresponds to an optionally signed, optionally encrypted,
//! optionally compressed literal data packet. The exact format of an
//! OpenPGP message is described in [Section 11.3 of RFC 4880].
//!
//! This module provides support for validating and working with
//! OpenPGP messages.
//!
//! [Section 11.3 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-11.3
use std::fmt;
use std::io;
use std::path::Path;
use failure;
use Result;
use Error;
use Packet;
use PacketPile;
use Message;
use packet::Literal;
use packet::Tag;
mod lexer;
mod grammar;
use self::lexer::{Lexer, LexicalError};
pub use self::lexer::Token;
use lalrpop_util::ParseError;
use self::grammar::MessageParser;
/// Errors that MessageValidator::check may return.
#[derive(Debug, Clone)]
pub enum MessageParserError {
/// A parser error.
Parser(ParseError<usize, Token, LexicalError>),
/// An OpenPGP error.
OpenPGP(Error),
}
impl From<MessageParserError> for failure::Error {
fn from(err: MessageParserError) -> Self {
match err {
MessageParserError::Parser(p) => p.into(),
MessageParserError::OpenPGP(p) => p.into(),
}
}
}
/// Whether a packet sequence is a valid OpenPGP Message.
#[derive(Debug)]
pub enum MessageValidity {
/// The packet sequence is a valid OpenPGP message.
Message,
/// The packet sequence appears to be a valid OpenPGP message that
/// has been truncated, i.e., the packet sequence is a valid
/// prefix of an OpenPGP message.
MessagePrefix,
/// The message is definitely not valid.
Error(failure::Error),
}
impl MessageValidity {
/// Returns whether the packet sequence is a valid message.
///
/// Note: a `MessageValidator` will only return this after
/// `MessageValidator::finish` has been called.
pub fn is_message(&self) -> bool {
if let MessageValidity::Message = self {
true