| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Crypt::OpenPGP::Compressed; |
|
2
|
1
|
|
|
1
|
|
1568
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
49
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
1282
|
use Compress::Zlib; |
|
|
1
|
|
|
|
|
512684
|
|
|
|
1
|
|
|
|
|
402
|
|
|
5
|
1
|
|
|
1
|
|
750
|
use Crypt::OpenPGP::Buffer; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Crypt::OpenPGP::Constants qw( DEFAULT_COMPRESS ); |
|
7
|
|
|
|
|
|
|
use Crypt::OpenPGP::ErrorHandler; |
|
8
|
|
|
|
|
|
|
use base qw( Crypt::OpenPGP::ErrorHandler ); |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use vars qw( %ALG %ALG_BY_NAME ); |
|
11
|
|
|
|
|
|
|
%ALG = ( 1 => 'ZIP', 2 => 'Zlib' ); |
|
12
|
|
|
|
|
|
|
%ALG_BY_NAME = map { $ALG{$_} => $_ } keys %ALG; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub alg { |
|
15
|
|
|
|
|
|
|
return $_[0]->{__alg} if ref($_[0]); |
|
16
|
|
|
|
|
|
|
$ALG{$_[1]} || $_[1]; |
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub alg_id { |
|
20
|
|
|
|
|
|
|
return $_[0]->{__alg_id} if ref($_[0]); |
|
21
|
|
|
|
|
|
|
$ALG_BY_NAME{$_[1]} || $_[1]; |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub new { |
|
25
|
|
|
|
|
|
|
my $comp = bless { }, shift; |
|
26
|
|
|
|
|
|
|
$comp->init(@_); |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub init { |
|
30
|
|
|
|
|
|
|
my $comp = shift; |
|
31
|
|
|
|
|
|
|
my %param = @_; |
|
32
|
|
|
|
|
|
|
if (my $data = $param{Data}) { |
|
33
|
|
|
|
|
|
|
my $alg = $param{Alg} || DEFAULT_COMPRESS; |
|
34
|
|
|
|
|
|
|
$alg = $ALG{$alg} || $alg; |
|
35
|
|
|
|
|
|
|
$comp->{__alg} = $alg; |
|
36
|
|
|
|
|
|
|
$comp->{__alg_id} = $ALG_BY_NAME{$alg}; |
|
37
|
|
|
|
|
|
|
my %args; |
|
38
|
|
|
|
|
|
|
if ($comp->{__alg_id} == 1) { |
|
39
|
|
|
|
|
|
|
%args = (-WindowBits => -13, -MemLevel => 8); |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
my($d, $status, $compressed); |
|
42
|
|
|
|
|
|
|
($d, $status) = deflateInit(\%args); |
|
43
|
|
|
|
|
|
|
return (ref $comp)->error("Zlib deflateInit error: $status") |
|
44
|
|
|
|
|
|
|
unless $status == Compress::Zlib::Z_OK(); |
|
45
|
|
|
|
|
|
|
{ |
|
46
|
|
|
|
|
|
|
my($output, $out); |
|
47
|
|
|
|
|
|
|
($output, $status) = $d->deflate($data); |
|
48
|
|
|
|
|
|
|
last unless $status == Compress::Zlib::Z_OK(); |
|
49
|
|
|
|
|
|
|
($out, $status) = $d->flush(); |
|
50
|
|
|
|
|
|
|
last unless $status == Compress::Zlib::Z_OK(); |
|
51
|
|
|
|
|
|
|
$compressed = $output . $out; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
return (ref $comp)->error("Zlib deflation error: $status") |
|
54
|
|
|
|
|
|
|
unless defined $compressed; |
|
55
|
|
|
|
|
|
|
$comp->{data} = $compressed; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
$comp; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub parse { |
|
61
|
|
|
|
|
|
|
my $class = shift; |
|
62
|
|
|
|
|
|
|
my($buf) = @_; |
|
63
|
|
|
|
|
|
|
my $comp = $class->new; |
|
64
|
|
|
|
|
|
|
$comp->{__alg_id} = $buf->get_int8; |
|
65
|
|
|
|
|
|
|
$comp->{__alg} = $ALG{ $comp->{__alg_id} }; |
|
66
|
|
|
|
|
|
|
$comp->{data} = $buf->get_bytes($buf->length - $buf->offset); |
|
67
|
|
|
|
|
|
|
$comp; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub save { |
|
71
|
|
|
|
|
|
|
my $comp = shift; |
|
72
|
|
|
|
|
|
|
my $buf = Crypt::OpenPGP::Buffer->new; |
|
73
|
|
|
|
|
|
|
$buf->put_int8($comp->{__alg_id}); |
|
74
|
|
|
|
|
|
|
$buf->put_bytes($comp->{data}); |
|
75
|
|
|
|
|
|
|
$buf->bytes; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub decompress { |
|
79
|
|
|
|
|
|
|
my $comp = shift; |
|
80
|
|
|
|
|
|
|
my %args; |
|
81
|
|
|
|
|
|
|
if ($comp->{__alg_id} == 1) { |
|
82
|
|
|
|
|
|
|
%args = (-WindowBits => -13); |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
my($i, $status, $out); |
|
85
|
|
|
|
|
|
|
($i, $status) = inflateInit(\%args); |
|
86
|
|
|
|
|
|
|
return $comp->error("Zlib inflateInit error: $status") |
|
87
|
|
|
|
|
|
|
unless $status == Compress::Zlib::Z_OK(); |
|
88
|
|
|
|
|
|
|
($out, $status) = $i->inflate($comp->{data}); |
|
89
|
|
|
|
|
|
|
return $comp->error("Zlib inflate error: $status") |
|
90
|
|
|
|
|
|
|
unless defined $out; |
|
91
|
|
|
|
|
|
|
$out; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
|
95
|
|
|
|
|
|
|
__END__ |