View Source OpenPGP.Packet (OpenPGP v0.6.2)
Packet struct represents a generic packet with a packet tag and a
body as a list of body chunks (see OpenPGP.Packet.BodyChunk
). This
abstraction layer operates at Packet Tag and Packet Body level only.
To interpret the contents of a packet, the packet body should be
decoded at another abstraction layer with packet tag-specific
decoders, for exampe OpenPGP.LiteralDataPacket
RFC4880
4.1. Overview
An OpenPGP message is constructed from a number of records that are traditionally called packets. A packet is a chunk of data that has a tag specifying its meaning. An OpenPGP message, keyring, certificate, and so forth consists of a number of packets. Some of those packets may contain other OpenPGP packets (for example, a compressed data packet, when uncompressed, contains OpenPGP packets).
Each packet consists of a packet header, followed by the packet body. The packet header is of variable length.
Summary
Functions
Decode packet given input binary. Return structured packet and remaining binary. Expect input to start with the Packet Tag octet.
Types
@type t() :: %OpenPGP.Packet{ body: [OpenPGP.Packet.BodyChunk.t()] | binary(), tag: OpenPGP.Packet.PacketTag.t() }
Functions
Decode packet given input binary. Return structured packet and remaining binary. Expect input to start with the Packet Tag octet.
Example:
iex> alias OpenPGP.Packet
iex> alias OpenPGP.Packet.PacketTag
iex> alias OpenPGP.Packet.BodyChunk
iex> Packet.decode(<<1::1, 0::1, 2::4, 0::2, 7::8, "Hello, World!!!">>)
{
%Packet{
tag: %PacketTag{format: :old, length_type: {0, "one-octet"}, tag: {2, "Signature Packet"}},
body: [%BodyChunk{chunk_length: {:fixed, 7}, data: "Hello, ", header_length: 1}]
},
"World!!!"
}