Struct sequoia_openpgp::Message [−][src]
pub struct Message { /* fields omitted */ }
A message.
An OpenPGP message is a structured sequence of OpenPGP packets. Basically, it’s an optionally encrypted, optionally signed literal data packet. The exact structure is defined in Section 11.3 of RFC 4880.
ASCII Armored Messages are wrapped in -----BEGIN PGP MESSAGE-----
header
and -----END PGP MESSAGE-----
tail lines:
-----BEGIN PGP MESSAGE-----
xA0DAAoW5saJekzviSQByxBiAAAAAADYtdiv2KfZgtipwnUEABYKACcFglwJHYoW
IQRnpIdTo4Cms7fffcXmxol6TO+JJAkQ5saJekzviSQAAIJ6APwK6FxtHXn8txDl
tBFsIXlOSLOs4BvArlZzZSMomIyFLAEAwCLJUChMICDxWXRlHxORqU5x6hlO3DdW
sl/1DAbnRgI=
=AqoO
-----END PGP MESSAGE-----
Examples
Creating a Message encrypted with a password.
use std::io::Write; use openpgp::serialize::stream::{Message, Encryptor, LiteralWriter}; let mut sink = vec![]; let message = Encryptor::with_passwords( Message::new(&mut sink), Some("ściśle tajne")).build()?; let mut w = LiteralWriter::new(message).build()?; w.write_all(b"Hello world.")?; w.finalize()?;
Implementations
impl Message
[src]
impl Message
[src]pub fn body(&self) -> Option<&Literal>
[src]
pub fn body(&self) -> Option<&Literal>
[src]Returns the body of the message.
Returns None
if no literal data packet is found. This
happens if a SEIP container has not been decrypted.
Examples
use std::io; use std::io::Read; use openpgp::Message; use openpgp::armor::{Reader, ReaderMode}; use openpgp::parse::Parse; let data = "yxJiAAAAAABIZWxsbyB3b3JsZCE="; // base64 over literal data packet let mut cursor = io::Cursor::new(&data); let mut reader = Reader::new(&mut cursor, ReaderMode::VeryTolerant); let mut buf = Vec::new(); reader.read_to_end(&mut buf)?; let message = Message::from_bytes(&buf)?; assert_eq!(message.body().unwrap().body(), b"Hello world!");
Methods from Deref<Target = PacketPile>
pub fn pretty_print(&self)
[src]
pub fn pretty_print(&self)
[src]Pretty prints the message to stderr.
This function is primarily intended for debugging purposes.
pub fn path_ref(&self, pathspec: &[usize]) -> Option<&Packet>
[src]
pub fn path_ref(&self, pathspec: &[usize]) -> Option<&Packet>
[src]Returns a reference to the packet at the location described by
pathspec
.
pathspec
is a slice of the form [0, 1, 2]
. Each element
is the index of packet in a container. Thus, the previous
path specification means: return the third child of the second
child of the first top-level packet. In other words, the
starred packet in the following tree:
PacketPile
/ | \
0 1 2 ...
/ \
/ \
0 1 ...
/ | \ ...
0 1 2
*
And, [10]
means return the 11th top-level packet.
Note: there is no packet at the root. Thus, the path []
returns None.
Examples
let pile = PacketPile::from(packets); if let Some(packet) = pile.path_ref(&[0]) { // There is a packet at this path. } if let None = pile.path_ref(&[0, 1, 2]) { // But none here. }
pub fn descendants(&self) -> Iter<'_>ⓘ
[src]
pub fn descendants(&self) -> Iter<'_>ⓘ
[src]Returns an iterator over all of the packet’s descendants, in depth-first order.
let mut lit = Literal::new(DataFormat::Text); lit.set_body(b"test".to_vec()); let pile = PacketPile::from(vec![lit.into()]); for packet in pile.descendants() { assert_eq!(packet.tag(), Tag::Literal); }
pub fn children(
&self
) -> impl Iterator<Item = &Packet> + ExactSizeIterator + Send + Sync
[src]
pub fn children(
&self
) -> impl Iterator<Item = &Packet> + ExactSizeIterator + Send + Sync
[src]Returns an iterator over the top-level packets.
let mut lit = Literal::new(DataFormat::Text); lit.set_body(b"test".to_vec()); let pile = PacketPile::from(vec![lit.into()]); assert_eq!(pile.children().len(), 1);
Trait Implementations
impl Deref for Message
[src]
impl Deref for Message
[src]type Target = PacketPile
type Target = PacketPile
The resulting type after dereferencing.
impl MarshalInto for Message
[src]
impl MarshalInto for Message
[src]impl<'a> Parse<'a, Message> for Message
[src]
impl<'a> Parse<'a, Message> for Message
[src]fn from_reader<R: 'a + Read + Send + Sync>(reader: R) -> Result<Self>
[src]
fn from_reader<R: 'a + Read + Send + Sync>(reader: R) -> Result<Self>
[src]Reads a Message
from the specified reader.
See Message::try_from
for more details.
impl SerializeInto for Message
[src]
impl SerializeInto for Message
[src]impl TryFrom<PacketPile> for Message
[src]
impl TryFrom<PacketPile> for Message
[src]fn try_from(pile: PacketPile) -> Result<Self>
[src]
fn try_from(pile: PacketPile) -> Result<Self>
[src]Converts the PacketPile
to a Message
.
Converting a PacketPile
to a Message
doesn’t change the
packets; it asserts that the packet sequence is an optionally
encrypted, optionally signed, optionally compressed literal
data packet. The exact grammar is defined in Section 11.3 of
RFC 4880.
Caveats: this function assumes that any still encrypted parts or still compressed parts are valid messages.
impl StructuralPartialEq for Message
[src]
Auto Trait Implementations
impl !RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl !UnwindSafe for Message
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
type Output = T
Should always be Self