line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::Checksum::Adler32; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
54010
|
use strict; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
48
|
|
4
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
70
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.080'; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
11
|
use base qw(Crypt::Checksum Exporter); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
689
|
|
8
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( all => [qw( adler32_data adler32_data_hex adler32_data_int adler32_file adler32_file_hex adler32_file_int )] ); |
9
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
10
|
|
|
|
|
|
|
our @EXPORT = qw(); |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
12
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
90
|
|
13
|
|
|
|
|
|
|
$Carp::Internal{(__PACKAGE__)}++; |
14
|
2
|
|
|
2
|
|
10
|
use CryptX; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
297
|
|
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
1
|
11107
|
sub adler32_file { local $SIG{__DIE__} = \&CryptX::_croak; Crypt::Checksum::Adler32->new->addfile(@_)->digest } |
|
1
|
|
|
|
|
13
|
|
17
|
4
|
|
|
4
|
1
|
18
|
sub adler32_file_hex { local $SIG{__DIE__} = \&CryptX::_croak; Crypt::Checksum::Adler32->new->addfile(@_)->hexdigest } |
|
4
|
|
|
|
|
26
|
|
18
|
1
|
|
|
1
|
1
|
5
|
sub adler32_file_int { local $SIG{__DIE__} = \&CryptX::_croak; Crypt::Checksum::Adler32->new->addfile(@_)->intdigest } |
|
1
|
|
|
|
|
7
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
1; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=pod |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 NAME |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Crypt::Checksum::Adler32 - Compute Adler32 checksum |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 SYNOPSIS |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
### Functional interface: |
31
|
|
|
|
|
|
|
use Crypt::Checksum::Adler32 ':all'; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# calculate Adler32 checksum from string/buffer |
34
|
|
|
|
|
|
|
$checksum_raw = adler32_data($data); |
35
|
|
|
|
|
|
|
$checksum_hex = adler32_data_hex($data); |
36
|
|
|
|
|
|
|
$checksum_int = adler32_data_int($data); |
37
|
|
|
|
|
|
|
# calculate Adler32 checksum from file |
38
|
|
|
|
|
|
|
$checksum_raw = adler32_file('filename.dat'); |
39
|
|
|
|
|
|
|
$checksum_hex = adler32_file_hex('filename.dat'); |
40
|
|
|
|
|
|
|
$checksum_int = adler32_file_int('filename.dat'); |
41
|
|
|
|
|
|
|
# calculate Adler32 checksum from filehandle |
42
|
|
|
|
|
|
|
$checksum_raw = adler32_file(*FILEHANDLE); |
43
|
|
|
|
|
|
|
$checksum_hex = adler32_file_hex(*FILEHANDLE); |
44
|
|
|
|
|
|
|
$checksum_int = adler32_file_int(*FILEHANDLE); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
### OO interface: |
47
|
|
|
|
|
|
|
use Crypt::Checksum::Adler32; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
$d = Crypt::Checksum::Adler32->new; |
50
|
|
|
|
|
|
|
$d->add('any data'); |
51
|
|
|
|
|
|
|
$d->add('another data'); |
52
|
|
|
|
|
|
|
$d->addfile('filename.dat'); |
53
|
|
|
|
|
|
|
$d->addfile(*FILEHANDLE); |
54
|
|
|
|
|
|
|
$checksum_raw = $d->digest; # raw 4 bytes |
55
|
|
|
|
|
|
|
$checksum_hex = $d->hexdigest; # hexadecimal form |
56
|
|
|
|
|
|
|
$checksum_int = $d->intdigest; # 32bit unsigned integer |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 DESCRIPTION |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Calculating Adler32 checksums. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
I |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 EXPORT |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Nothing is exported by default. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
You can export selected functions: |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
use Crypt::Checksum::Adler32 qw(adler32_data adler32_data_hex adler32_data_int adler32_file adler32_file_hex adler32_file_int); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Or all of them at once: |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
use Crypt::Checksum::Adler32 ':all'; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 FUNCTIONS |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 adler32_data |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Returns checksum as raw octects. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
$checksum_raw = adler32_data('data string'); |
83
|
|
|
|
|
|
|
#or |
84
|
|
|
|
|
|
|
$checksum_raw = adler32_data('any data', 'more data', 'even more data'); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 adler32_data_hex |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Returns checksum as a hexadecimal string. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
$checksum_hex = adler32_data_hex('data string'); |
91
|
|
|
|
|
|
|
#or |
92
|
|
|
|
|
|
|
$checksum_hex = adler32_data_hex('any data', 'more data', 'even more data'); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 adler32_data_int |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Returns checksum as unsigned 32bit integer. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
$checksum_int = adler32_data_int('data string'); |
99
|
|
|
|
|
|
|
#or |
100
|
|
|
|
|
|
|
$checksum_int = adler32_data_int('any data', 'more data', 'even more data'); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 adler32_file |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Returns checksum as raw octects. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
$checksum_raw = adler32_file('filename.dat'); |
107
|
|
|
|
|
|
|
#or |
108
|
|
|
|
|
|
|
$checksum_raw = adler32_file(*FILEHANDLE); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 adler32_file_hex |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Returns checksum as a hexadecimal string. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
$checksum_hex = adler32_file_hex('filename.dat'); |
115
|
|
|
|
|
|
|
#or |
116
|
|
|
|
|
|
|
$checksum_hex = adler32_file_hex(*FILEHANDLE); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 adler32_file_int |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Returns checksum as unsigned 32bit integer. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
$checksum_int = adler32_file_int('filename.dat'); |
123
|
|
|
|
|
|
|
#or |
124
|
|
|
|
|
|
|
$checksum_int = adler32_file_int(*FILEHANDLE); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 METHODS |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 new |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Constructor, returns a reference to the checksum object. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
$d = Crypt::Checksum::Adler32->new; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 clone |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Creates a copy of the checksum object state and returns a reference to the copy. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
$d->clone(); |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 reset |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Reinitialize the checksum object state and returns a reference to the checksum object. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
$d->reset(); |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 add |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
All arguments are appended to the message we calculate checksum for. |
149
|
|
|
|
|
|
|
The return value is the checksum object itself. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
$d->add('any data'); |
152
|
|
|
|
|
|
|
#or |
153
|
|
|
|
|
|
|
$d->add('any data', 'more data', 'even more data'); |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 addfile |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
The content of the file (or filehandle) is appended to the message we calculate checksum for. |
158
|
|
|
|
|
|
|
The return value is the checksum object itself. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
$d->addfile('filename.dat'); |
161
|
|
|
|
|
|
|
#or |
162
|
|
|
|
|
|
|
$d->addfile(*FILEHANDLE); |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
B You have to make sure that the filehandle is in binary mode before you pass it as argument to the addfile() method. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 digest |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Returns the binary checksum (raw bytes). |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
$result_raw = $d->digest(); |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head2 hexdigest |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Returns the checksum encoded as a hexadecimal string. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
$result_hex = $d->hexdigest(); |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head2 intdigest |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Returns the checksum encoded as unsigned 32bit integer. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
$result_int = $d->intdigest(); |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 SEE ALSO |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=over |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item * L |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=item * L |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=back |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=cut |