| 1 | package Crypt::OpenPGP::Compressed; | ||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 2 | our $VERSION = '1.21'; # VERSION | |||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 2 | ▶ | use Compress::Zlib; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 2 | ▶ | use Crypt::OpenPGP::Buffer; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 2 | ▶ | use Crypt::OpenPGP::Constants qw( DEFAULT_COMPRESS ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 2 | ▶ | use parent qw( Crypt::OpenPGP::ErrorHandler ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 2 | our %ALG = ( 1 => 'ZIP', 2 => 'Zlib' ); | |||||||||||||||||||
| 13 | 2 | our %ALG_BY_NAME = map { $ALG{$_} => $_ } keys %ALG; | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 2 | ▶ | sub alg { | ||||||||||||||||||
|
Subroutine
alg: called CC=3 SCAR=17.3
Pod
undocumented
| |||||||||||||||||||||
| 16 | 2 | ▶ | return $_[0]->{__alg} if ref($_[0]); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 17 | 0 | ▶ | $ALG{$_[1]} || $_[1]; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 18 | } | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 2 | ▶ | sub alg_id { | ||||||||||||||||||
|
Subroutine
alg_id: called CC=3 SCAR=17.3
Pod
undocumented
| |||||||||||||||||||||
| 21 | 2 | ▶ | return $_[0]->{__alg_id} if ref($_[0]); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 22 | 0 | ▶ | $ALG_BY_NAME{$_[1]} || $_[1]; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 23 | } | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 3 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 26 | 3 | my $comp = bless { }, shift; | |||||||||||||||||||
| 27 | 3 | $comp->init(@_); | |||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 3 | ▶ | sub init { | ||||||||||||||||||
|
Subroutine
init: called CC=9 SCAR=22.6
Pod
undocumented
| |||||||||||||||||||||
| 31 | 3 | my $comp = shift; | |||||||||||||||||||
| 32 | 3 | my %param = @_; | |||||||||||||||||||
| 33 | 3 | ▶ | if (my $data = $param{Data}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | 2 | ▶ | my $alg = $param{Alg} || DEFAULT_COMPRESS; | ||||||||||||||||||
|
Condition33%1/3
$param{'Alg'} || &DEFAULT_COMPRESS()
MC/DC0%0/2
$param{'Alg'} || &DEFAULT_COMPRESS()
$param{'Alg'}
&DEFAULT_COMPRESS()
Truth table33%1/3
A || B
A= $param{'Alg'}B= &DEFAULT_COMPRESS()
| |||||||||||||||||||||
| 35 | 2 | ▶ | $alg = $ALG{$alg} || $alg; | ||||||||||||||||||
|
Condition33%1/3
$Crypt::OpenPGP::Compressed::ALG{$alg} || $alg
MC/DC0%0/2
$Crypt::OpenPGP::Compressed::ALG{$alg} || $alg
$Crypt::OpenPGP::Compressed::ALG{$alg}
$alg
Truth table33%1/3
A || B
A= $Crypt::OpenPGP::Compressed::ALG{$alg}B= $alg
| |||||||||||||||||||||
| 36 | 2 | $comp->{__alg} = $alg; | |||||||||||||||||||
| 37 | 2 | $comp->{__alg_id} = $ALG_BY_NAME{$alg}; | |||||||||||||||||||
| 38 | 2 | my %args; | |||||||||||||||||||
| 39 | 2 | ▶ | if ($comp->{__alg_id} == 1) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 40 | 1 | %args = (-WindowBits => -13, -MemLevel => 8); | |||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | 2 | my($d, $status, $compressed); | |||||||||||||||||||
| 43 | 2 | ($d, $status) = deflateInit(\%args); | |||||||||||||||||||
| 44 | 2 | ▶ | return (ref $comp)->error("Zlib deflateInit error: $status") | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | unless $status == Compress::Zlib::Z_OK(); | ||||||||||||||||||||
| 46 | { | ||||||||||||||||||||
| 47 | 2 | my($output, $out); | |||||||||||||||||||
| 48 | 2 | ($output, $status) = $d->deflate($data); | |||||||||||||||||||
| 49 | 2 | ▶ | last unless $status == Compress::Zlib::Z_OK(); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | 2 | ($out, $status) = $d->flush(); | |||||||||||||||||||
| 51 | 2 | ▶ | last unless $status == Compress::Zlib::Z_OK(); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | 2 | $compressed = $output . $out; | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | 2 | ▶ | return (ref $comp)->error("Zlib deflation error: $status") | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 55 | unless defined $compressed; | ||||||||||||||||||||
| 56 | 2 | $comp->{data} = $compressed; | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | 3 | $comp; | |||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 1 | ▶ | sub parse { | ||||||||||||||||||
|
Subroutine
parse: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 62 | 1 | my $class = shift; | |||||||||||||||||||
| 63 | 1 | my($buf) = @_; | |||||||||||||||||||
| 64 | 1 | my $comp = $class->new; | |||||||||||||||||||
| 65 | 1 | $comp->{__alg_id} = $buf->get_int8; | |||||||||||||||||||
| 66 | 1 | $comp->{__alg} = $ALG{ $comp->{__alg_id} }; | |||||||||||||||||||
| 67 | 1 | $comp->{data} = $buf->get_bytes($buf->length - $buf->offset); | |||||||||||||||||||
| 68 | 1 | $comp; | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 0 | ▶ | sub save { | ||||||||||||||||||
|
Subroutine
save: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 72 | 0 | my $comp = shift; | |||||||||||||||||||
| 73 | 0 | my $buf = Crypt::OpenPGP::Buffer->new; | |||||||||||||||||||
| 74 | 0 | $buf->put_int8($comp->{__alg_id}); | |||||||||||||||||||
| 75 | 0 | $buf->put_bytes($comp->{data}); | |||||||||||||||||||
| 76 | 0 | $buf->bytes; | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 3 | ▶ | sub decompress { | ||||||||||||||||||
|
Subroutine
decompress: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||
| 80 | 3 | my $comp = shift; | |||||||||||||||||||
| 81 | 3 | my %args; | |||||||||||||||||||
| 82 | 3 | ▶ | if ($comp->{__alg_id} == 1) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 83 | 2 | %args = (-WindowBits => -13); | |||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | 3 | my($i, $status, $out); | |||||||||||||||||||
| 86 | 3 | ($i, $status) = inflateInit(\%args); | |||||||||||||||||||
| 87 | 3 | ▶ | return $comp->error("Zlib inflateInit error: $status") | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 88 | unless $status == Compress::Zlib::Z_OK(); | ||||||||||||||||||||
| 89 | 3 | ($out, $status) = $i->inflate($comp->{data}); | |||||||||||||||||||
| 90 | 3 | ▶ | return $comp->error("Zlib inflate error: $status") | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 91 | unless defined $out; | ||||||||||||||||||||
| 92 | 3 | $out; | |||||||||||||||||||
| 93 | } | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 2 | 1; | |||||||||||||||||||
| 96 | __END__ | ||||||||||||||||||||