Crypt-OpenPGP
view release on metacpan or search on metacpan
lib/Crypt/OpenPGP.pm view on Meta::CPAN
)
or return;
} else {
my $pt = Crypt::OpenPGP::Plaintext->new( Data => $data,
$param{Filename} ? (Filename => $param{Filename}) : () );
$ptdata = Crypt::OpenPGP::PacketFactory->save($pt);
}
if (my $alg = $param{Compress}) {
require Crypt::OpenPGP::Compressed;
$alg = Crypt::OpenPGP::Compressed->alg_id($alg);
my $cdata = Crypt::OpenPGP::Compressed->new( Data => $ptdata,
Alg => $alg ) or return $pgp->error("Compression error: " .
Crypt::OpenPGP::Compressed->errstr);
$ptdata = Crypt::OpenPGP::PacketFactory->save($cdata);
}
my $key_data = Crypt::OpenPGP::Util::get_random_bytes(32);
my $sym_alg = $param{Cipher} ?
Crypt::OpenPGP::Cipher->alg_id($param{Cipher}) : DEFAULT_CIPHER;
my(@sym_keys);
if ($param{Recipients} && !ref($param{Recipients})) {
$param{Recipients} = [ $param{Recipients} ];
}
if (my $kid = delete $param{KeyID}) {
my @kid = ref $kid eq 'ARRAY' ? @$kid : $kid;
lib/Crypt/OpenPGP/Compressed.pm view on Meta::CPAN
=head1 NAME
Crypt::OpenPGP::Compressed - Compressed data packets
=head1 SYNOPSIS
use Crypt::OpenPGP::Compressed;
my $data = 'serialized openpgp packets';
my $cdata = Crypt::OpenPGP::Compressed->new( Data => $data );
my $serialized = $cdata->save;
=head1 DESCRIPTION
I<Crypt::OpenPGP::Compressed> implements compressed data packets,
providing both compression and decompression functionality, for all
supported compression algorithms (C<Zlib> and C<ZIP>). This class
uses I<Compress::Zlib> for all compression/decompression needs for
both algorithms: C<ZIP> is simply C<Zlib> with a different setting
for the I<WindowBits> parameter.
lib/Crypt/OpenPGP/Compressed.pm view on Meta::CPAN
=item * Alg
The name (or ID) of a supported PGP compression algorithm. Valid
names are C<Zlib> and C<ZIP>.
This argument is optional; by default I<Crypt::OpenPGP::Compressed> will
use C<ZIP>.
=back
=head2 $cdata->save
Returns the serialized compressed data packet, which consists of
a one-octet compression algorithm ID, followed by the compressed
data.
=head2 Crypt::OpenPGP::Compressed->parse($buffer)
Given I<$buffer>, a I<Crypt::OpenPGP::Buffer> object holding (or with
offset pointing to) a compressed data packet, returns a new
I<Crypt::OpenPGP::Compressed> object, initialized with the data from
the buffer.
=head2 $cdata->decompress
Decompresses the compressed data in the I<Crypt::OpenPGP::Compressed>
object I<$cdata> and returns the decompressed data.
=head1 AUTHOR & COPYRIGHTS
Please see the Crypt::OpenPGP manpage for author, copyright, and
license information.
=cut
t/08-compress.t view on Meta::CPAN
TEXT
my %TESTS;
BEGIN {
%TESTS = %Crypt::OpenPGP::Compressed::ALG;
my $num_tests = 4 * scalar keys %TESTS;
plan tests => $num_tests;
}
for my $cid ( sort { $a <=> $b } keys %TESTS ) {
my $cdata = Crypt::OpenPGP::Compressed->new(
Data => $data,
Alg => $cid
);
isa_ok $cdata, 'Crypt::OpenPGP::Compressed';
is $cdata->alg, $TESTS{ $cid }, 'alg matches';
is $cdata->alg_id, $cid, 'alg_id matches';
my $decomp = $cdata->decompress;
is $decomp, $data, 'decompressed data matches original';
}
( run in 0.635 second using v1.01-cache-2.11-cpan-454fe037f31 )