OpenPGP/Compressed.pm

filter: Statementstmt 90.5% 67 / 74 Branchbran 53.8% 14 / 26 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 92.3% 12 / 13 Podpod 57.1% 4 / 7 totaltotal 76.1% 99 / 130 CC 16 SCAR 16.6
CC
16
Cov
78%
init
9.6
alg
5.7
alg_id
5.7
CRAP 5.2
« OpenPGP/KeyServer.pm ↑ Summary OpenPGP/Message.pm »
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
BranchTrueFalseTotal
if ref $_[0] 2 0 2
17 0 ▶ $ALG{$_[1]} || $_[1];
Branch: 1 branch
BranchTrueFalseTotal
$Crypt::OpenPGP::Compressed::ALG{$_[1]} or $_[1] 0 0 0
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
BranchTrueFalseTotal
if ref $_[0] 2 0 2
22 0 ▶ $ALG_BY_NAME{$_[1]} || $_[1];
Branch: 1 branch
BranchTrueFalseTotal
$Crypt::OpenPGP::Compressed::ALG_BY_NAME{$_[1]} or $_[1] 0 0 0
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
BranchTrueFalseTotal
if (my $data = $param{"Data"}) 2 1 3
34 2 ▶ my $alg = $param{Alg} || DEFAULT_COMPRESS;
Condition33%1/3
$param{'Alg'} || &DEFAULT_COMPRESS()
l!l&&r!l&&!r
200
MC/DC0%0/2
$param{'Alg'} || &DEFAULT_COMPRESS()
$param{'Alg'} &DEFAULT_COMPRESS()
Truth table33%1/3
A || B
A= $param{'Alg'}B= &DEFAULT_COMPRESS()
ABresult
1X1
011
000
35 2 ▶ $alg = $ALG{$alg} || $alg;
Condition33%1/3
$Crypt::OpenPGP::Compressed::ALG{$alg} || $alg
l!l&&r!l&&!r
200
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if ($comp->{"__alg_id"} == 1) 1 1 2
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
BranchTrueFalseTotal
unless $status == Compress::Zlib::Z_OK() 0 2 2
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
BranchTrueFalseTotal
unless $status == Compress::Zlib::Z_OK() 0 2 2
50 2 ($out, $status) = $d->flush();
51 2 ▶ last unless $status == Compress::Zlib::Z_OK();
Branch: 1 branch
BranchTrueFalseTotal
unless $status == Compress::Zlib::Z_OK() 0 2 2
52 2 $compressed = $output . $out;
53 }
54 2 ▶ return (ref $comp)->error("Zlib deflation error: $status")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $compressed 0 2 2
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
BranchTrueFalseTotal
if ($comp->{"__alg_id"} == 1) 2 1 3
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
BranchTrueFalseTotal
unless $status == Compress::Zlib::Z_OK() 0 3 3
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
BranchTrueFalseTotal
unless defined $out 0 3 3
91 unless defined $out;
92 3 $out;
93 }
94  
95 2 1;
96 __END__
« OpenPGP/KeyServer.pm ↑ Summary OpenPGP/Message.pm »