blib/lib/Crypt/Checksum/Adler32.pm

filter: Statementstmt 100% 28 / 28 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 3 / 3 totaltotal 100% 39 / 39 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/Crypt/AuthEnc/SIV.pm ↑ Summary blib/lib/Crypt/Checksum/CRC32.pm »
1 package Crypt::Checksum::Adler32;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 our $VERSION = '0.091';
6  
7 2 ▶use base qw(Crypt::Checksum Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 our %EXPORT_TAGS = ( all => [qw( adler32_data adler32_data_hex adler32_data_int adler32_file adler32_file_hex adler32_file_int )] );
9 2 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
10 2 our @EXPORT = qw();
11  
12 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 $Carp::Internal{(__PACKAGE__)}++;
14 2 ▶use CryptX;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 ▶sub adler32_file { local $SIG{__DIE__} = \&CryptX::_croak; Crypt::Checksum::Adler32->new->addfile(@_)->digest }
Subroutine adler32_file: called CC=1 SCAR=0.0
Pod documented
17 4 ▶sub adler32_file_hex { local $SIG{__DIE__} = \&CryptX::_croak; Crypt::Checksum::Adler32->new->addfile(@_)->hexdigest }
Subroutine adler32_file_hex: called CC=1 SCAR=0.0
Pod documented
18 1 ▶sub adler32_file_int { local $SIG{__DIE__} = \&CryptX::_croak; Crypt::Checksum::Adler32->new->addfile(@_)->intdigest }
Subroutine adler32_file_int: called CC=1 SCAR=0.0
Pod documented
19  
20 2 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 my $data = 'data string';
35 my $checksum_raw = adler32_data($data);
36 my $checksum_hex = adler32_data_hex($data);
37 my $checksum_int = adler32_data_int($data);
38 # or from file
39 my $checksum_file_raw = adler32_file('filename.dat');
40 my $checksum_file_hex = adler32_file_hex('filename.dat');
41 my $checksum_file_int = adler32_file_int('filename.dat');
42 # or from filehandle
43 my $filehandle = ...; # existing binary-mode filehandle
44 my $checksum_fh_raw = adler32_file($filehandle);
45 my $checksum_fh_hex = adler32_file_hex($filehandle);
46 my $checksum_fh_int = adler32_file_int($filehandle);
47  
48 ### OO interface:
49 use Crypt::Checksum::Adler32;
50  
51 my $d = Crypt::Checksum::Adler32->new;
52 $d->add('any data');
53 $d->add('another data');
54 my $checksum_raw = $d->digest; # raw 4 bytes
55 my $checksum_hex = $d->hexdigest; # hexadecimal form
56 my $checksum_int = $d->intdigest; # 32-bit unsigned integer
57  
58 # or checksum a file instead
59 my $checksum_file_raw = Crypt::Checksum::Adler32->new->addfile('filename.dat')->digest;
60  
61 =head1 DESCRIPTION
62  
63 Computes Adler-32 checksums.
64  
65 I<Updated: v0.057>
66  
67 =head1 EXPORT
68  
69 Nothing is exported by default.
70  
71 You can export selected functions:
72  
73 use Crypt::Checksum::Adler32 qw(adler32_data adler32_data_hex adler32_data_int adler32_file adler32_file_hex adler32_file_int);
74  
75 Or all of them at once:
76  
77 use Crypt::Checksum::Adler32 ':all';
78  
79 =head1 FUNCTIONS
80  
81 =head2 adler32_data
82  
83 Returns the checksum as raw octets.
84  
85 my $checksum_raw = adler32_data('data string');
86 #or
87 my $checksum_raw = adler32_data('any data', 'more data', 'even more data');
88  
89 =head2 adler32_data_hex
90  
91 Returns checksum as a hexadecimal string.
92  
93 my $checksum_hex = adler32_data_hex('data string');
94 #or
95 my $checksum_hex = adler32_data_hex('any data', 'more data', 'even more data');
96  
97 =head2 adler32_data_int
98  
99 Returns checksum as unsigned 32-bit integer.
100  
101 my $checksum_int = adler32_data_int('data string');
102 #or
103 my $checksum_int = adler32_data_int('any data', 'more data', 'even more data');
104  
105 Each C<adler32_data*> function converts its data arguments to bytes using
106 Perl's usual scalar stringification. Defined scalars, including numbers and
107 string-overloaded objects, are accepted. C<undef> is treated as an empty
108 string and may emit Perl's usual "uninitialized value" warning.
109  
110 =head2 adler32_file
111  
112 Returns the checksum as raw octets.
113  
114 my $checksum_raw = adler32_file('filename.dat');
115 #or
116 my $filehandle = ...; # existing binary-mode filehandle
117 my $checksum_raw = adler32_file($filehandle);
118  
119 =head2 adler32_file_hex
120  
121 Returns checksum as a hexadecimal string.
122  
123 my $checksum_hex = adler32_file_hex('filename.dat');
124 #or
125 my $filehandle = ...; # existing binary-mode filehandle
126 my $checksum_hex = adler32_file_hex($filehandle);
127  
128 =head2 adler32_file_int
129  
130 Returns checksum as unsigned 32-bit integer.
131  
132 my $checksum_int = adler32_file_int('filename.dat');
133 #or
134 my $filehandle = ...; # existing binary-mode filehandle
135 my $checksum_int = adler32_file_int($filehandle);
136  
137 =head1 METHODS
138  
139 =head2 new
140  
141 Constructor, returns a reference to the checksum object.
142  
143 my $d = Crypt::Checksum::Adler32->new;
144  
145 =head2 clone
146  
147 Creates a copy of the checksum object state and returns a reference to the copy.
148  
149 $d->clone();
150  
151 =head2 reset
152  
153 Reinitialize the checksum object state and returns a reference to the checksum object.
154  
155 $d->reset();
156  
157 =head2 add
158  
159 All arguments are appended to the message we calculate checksum for.
160 The return value is the checksum object itself.
161  
162 Each argument is converted to bytes using Perl's usual scalar stringification.
163 Defined scalars, including numbers and string-overloaded objects, are accepted.
164 C<undef> is treated as an empty string and may emit Perl's usual
165 "uninitialized value" warning.
166  
167 $d->add('any data');
168 #or
169 $d->add('any data', 'more data', 'even more data');
170  
171 =head2 addfile
172  
173 The content of the file (or filehandle) is appended to the message we calculate checksum for.
174 The return value is the checksum object itself.
175  
176 $d->addfile('filename.dat');
177 #or
178 my $filehandle = ...; # existing binary-mode filehandle
179 $d->addfile($filehandle);
180  
181 B<Note:> The filehandle must be in binary mode before you pass it to C<addfile()>.
182  
183 =head2 digest
184  
185 Returns the binary checksum (raw bytes).
186 This method does not alter the object state, so you can call it
187 repeatedly and continue with C<add()> or C<addfile()> afterwards.
188  
189 my $result_raw = $d->digest();
190  
191 =head2 hexdigest
192  
193 Returns the checksum encoded as a hexadecimal string.
194 Like C<digest()>, this method does not alter the object state.
195  
196 my $result_hex = $d->hexdigest();
197  
198 =head2 intdigest
199  
200 Returns the checksum encoded as unsigned 32-bit integer.
201 Like C<digest()>, this method does not alter the object state.
202  
203 my $result_int = $d->intdigest();
204  
205 =head1 SEE ALSO
206  
207 =over
208  
209 =item * L<CryptX>
210  
211 =item * L<https://en.wikipedia.org/wiki/Adler-32>
212  
213 =back
214  
215 =cut
« blib/lib/Crypt/AuthEnc/SIV.pm ↑ Summary blib/lib/Crypt/Checksum/CRC32.pm »