Crypt::OpenPGP::PacketFactory(3p)

NAME
Crypt::OpenPGP::PacketFactory - Parse and save PGP packet streams

SYNOPSIS
    use Crypt::OpenPGP::PacketFactory;

    my $buf = Crypt::OpenPGP::Buffer->new;
    while (my $packet = Crypt::OpenPGP::PacketFactory->parse($buf)) {
        ## Do something with $packet
    }

    my @packets;
    my $serialized = Crypt::OpenPGP::PacketFactory->save(@packets);

DESCRIPTION
Crypt::OpenPGP::PacketFactory parses PGP buffers (objects of type Crypt::OpenPGP::Buffer) and generates packet objects of various packet classes (for example, Crypt::OpenPGP::Certificate objects, Crypt::OpenPGP::Signature objects, etc.). It also takes lists of packets, serializes each of them, and adds type/length headers to them, forming a stream of packets suitable for armouring, writing to disk, sending through email, etc.

USAGE

  Crypt::OpenPGP::PacketFactory->parse($buffer [, $find ])
Given a buffer object $buffer of type Crypt::OpenPGP::Buffer, iterates through the packets serialized in the buffer, parsing each one, and returning each packet one by one. In other words, given a buffer, it acts as a standard iterator.

By default parse parses and returns all packets in the buffer, of any packet type. If you are only looking for packets of a specific type, though, it makes no sense to return every packet; you can control which packets parse parses and returns with $find, which should be a reference to a list of packet types to find in the buffer. Only packets of those types will be parsed and returned to you. You can get the packet type constants from Crypt::OpenPGP::Constants by importing the ":packet" tag.

Returns the next packet in the buffer until the end of the buffer is reached (or until there are no more of the packets which you wish to find), at which point returns a false value.

  Crypt::OpenPGP::PacketFactory->save(@packets)
Given a list of packets @packets, serializes each packet, then adds a type/length header on to each one, resulting in a string of octets representing the serialized packets, suitable for passing in to parse, or for writing to disk, or anywhere else.

AUTHOR & COPYRIGHTS
Please see the Crypt::OpenPGP manpage for author, copyright, and license information.