blib/lib/Crypt/Digest/MD5.pm

filter: Statementstmt 97.3% 36 / 37 Branchbran n/a Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 93.7% 15 / 16 Podpod 100% 11 / 11 totaltotal 91.3% 63 / 69 CC 2 SCAR 1.8
CC
2
Cov
92%
clone
2.1
md5_file_b64u
2.0
BEGIN
1.0
CRAP 1.2
« blib/lib/Crypt/Digest/MD4.pm ↑ Summary blib/lib/Crypt/Digest/RIPEMD128.pm »
1 package Crypt::Digest::MD5;
2  
3 ### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 our $VERSION = '0.091';
8  
9 2 ▶use base qw(Crypt::Digest Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 our %EXPORT_TAGS = ( all => [qw( md5 md5_hex md5_b64 md5_b64u md5_file md5_file_hex md5_file_b64 md5_file_b64u )] );
11 2 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
12 2 our @EXPORT = qw();
13  
14 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 $Carp::Internal{(__PACKAGE__)}++;
16 2 ▶use Crypt::Digest;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 21 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
19 21 my ($class) = @_;
20 21 my $obj = Crypt::Digest->new('MD5');
21 21 return bless $obj, $class;
22 }
23  
24 3 ▶sub clone {
Subroutine clone: called CC=2 SCAR=7.6
Pod documented
25 3 my ($self) = @_;
26 3 my $obj = Crypt::Digest::clone($self);
27 3 ▶ return bless $obj, ref($self) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
300
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
28 }
29  
30 3 ▶sub hashsize { Crypt::Digest::hashsize('MD5') }
Subroutine hashsize: called CC=1 SCAR=0.0
Pod documented
31 4 ▶sub md5 { Crypt::Digest::digest_data('MD5', @_) }
Subroutine md5: called CC=1 SCAR=0.0
Pod documented
32 4 ▶sub md5_hex { Crypt::Digest::digest_data_hex('MD5', @_) }
Subroutine md5_hex: called CC=1 SCAR=0.0
Pod documented
33 4 ▶sub md5_b64 { Crypt::Digest::digest_data_b64('MD5', @_) }
Subroutine md5_b64: called CC=1 SCAR=0.0
Pod documented
34 1 ▶sub md5_b64u { Crypt::Digest::digest_data_b64u('MD5', @_) }
Subroutine md5_b64u: called CC=1 SCAR=0.0
Pod documented
35 4 ▶sub md5_file { Crypt::Digest::digest_file('MD5', @_) }
Subroutine md5_file: called CC=1 SCAR=0.0
Pod documented
36 4 ▶sub md5_file_hex { Crypt::Digest::digest_file_hex('MD5', @_) }
Subroutine md5_file_hex: called CC=1 SCAR=0.0
Pod documented
37 4 ▶sub md5_file_b64 { Crypt::Digest::digest_file_b64('MD5', @_) }
Subroutine md5_file_b64: called CC=1 SCAR=0.0
Pod documented
38 0 ▶sub md5_file_b64u { Crypt::Digest::digest_file_b64u('MD5', @_) }
Subroutine md5_file_b64u: not called CC=1 SCAR=6.9
Pod documented
39  
40 2 1;
41  
42 =pod
43  
44 =head1 NAME
45  
46 Crypt::Digest::MD5 - Hash function MD5 [size: 128 bits]
47  
48 =head1 SYNOPSIS
49  
50 ### Functional interface:
51 use Crypt::Digest::MD5 qw( md5 md5_hex md5_b64 md5_b64u
52 md5_file md5_file_hex md5_file_b64 md5_file_b64u );
53  
54 # calculate digest from string/buffer
55 my $data = 'data string';
56 my $md5_raw = md5($data);
57 my $md5_hex = md5_hex($data);
58 my $md5_b64 = md5_b64($data);
59 my $md5_b64u = md5_b64u($data);
60 # or from file
61 my $md5_file_raw = md5_file('filename.dat');
62 my $md5_file_hex = md5_file_hex('filename.dat');
63 my $md5_file_b64 = md5_file_b64('filename.dat');
64 my $md5_file_b64u = md5_file_b64u('filename.dat');
65 # or from filehandle
66 my $filehandle = ...; # existing binary-mode filehandle
67 my $md5_fh_raw = md5_file($filehandle);
68 my $md5_fh_hex = md5_file_hex($filehandle);
69 my $md5_fh_b64 = md5_file_b64($filehandle);
70 my $md5_fh_b64u = md5_file_b64u($filehandle);
71  
72 ### OO interface:
73 use Crypt::Digest::MD5;
74  
75 my $d = Crypt::Digest::MD5->new;
76 $d->add('any data');
77 my $result_raw = $d->digest; # raw bytes
78 my $result_hex = $d->hexdigest; # hexadecimal form
79 my $result_b64 = $d->b64digest; # Base64 form
80 my $result_b64u = $d->b64udigest; # Base64 URL-safe form
81  
82 # or hash a file instead
83 my $file_result_raw = Crypt::Digest::MD5->new->addfile('filename.dat')->digest;
84  
85 =head1 DESCRIPTION
86  
87 Provides an interface to the MD5 digest algorithm.
88  
89 =head1 EXPORT
90  
91 Nothing is exported by default.
92  
93 You can export selected functions:
94  
95 use Crypt::Digest::MD5 qw(md5 md5_hex md5_b64 md5_b64u
96 md5_file md5_file_hex md5_file_b64 md5_file_b64u);
97  
98 Or all of them at once:
99  
100 use Crypt::Digest::MD5 ':all';
101  
102 =head1 FUNCTIONS
103  
104 =head2 md5
105  
106 Joins all arguments into a single string and returns its MD5 digest encoded as a binary string.
107  
108 Data arguments for the functional helpers are converted to byte strings using
109 Perl's usual scalar stringification. Defined scalars, including numbers and
110 string-overloaded objects, are accepted. C<undef> is treated as an empty
111 string and may emit Perl's usual "uninitialized value" warning. The same
112 rules apply to C<md5_hex>, C<md5_b64>, and
113 C<md5_b64u>.
114  
115 my $md5_raw = md5('data string');
116 #or
117 my $md5_raw = md5('any data', 'more data', 'even more data');
118  
119 =head2 md5_hex
120  
121 Joins all arguments into a single string and returns its MD5 digest encoded as a hexadecimal string.
122  
123 my $md5_hex = md5_hex('data string');
124 #or
125 my $md5_hex = md5_hex('any data', 'more data', 'even more data');
126  
127 =head2 md5_b64
128  
129 Joins all arguments into a single string and returns its MD5 digest encoded as a Base64 string, B<with> trailing '=' padding.
130  
131 my $md5_b64 = md5_b64('data string');
132 #or
133 my $md5_b64 = md5_b64('any data', 'more data', 'even more data');
134  
135 =head2 md5_b64u
136  
137 Joins all arguments into a single string and returns its MD5 digest encoded as a Base64 URL-safe string (see RFC 4648 section 5).
138  
139 my $md5_b64url = md5_b64u('data string');
140 #or
141 my $md5_b64url = md5_b64u('any data', 'more data', 'even more data');
142  
143 =head2 md5_file
144  
145 Reads a file given by a filename or filehandle and returns its MD5 digest encoded as a binary string.
146  
147 my $md5_raw = md5_file('filename.dat');
148 #or
149 my $filehandle = ...; # existing binary-mode filehandle
150 my $md5_raw = md5_file($filehandle);
151  
152 =head2 md5_file_hex
153  
154 Reads a file given by a filename or filehandle and returns its MD5 digest encoded as a hexadecimal string.
155  
156 my $md5_hex = md5_file_hex('filename.dat');
157 #or
158 my $filehandle = ...; # existing binary-mode filehandle
159 my $md5_hex = md5_file_hex($filehandle);
160  
161 B<Note:> The filehandle must be in binary mode before you pass it to C<addfile()>.
162  
163 =head2 md5_file_b64
164  
165 Reads a file given by a filename or filehandle and returns its MD5 digest encoded as a Base64 string, B<with> trailing '=' padding.
166  
167 my $md5_b64 = md5_file_b64('filename.dat');
168 #or
169 my $filehandle = ...; # existing binary-mode filehandle
170 my $md5_b64 = md5_file_b64($filehandle);
171  
172 =head2 md5_file_b64u
173  
174 Reads a file given by a filename or filehandle and returns its MD5 digest encoded as a Base64 URL-safe string (see RFC 4648 section 5).
175  
176 my $md5_b64url = md5_file_b64u('filename.dat');
177 #or
178 my $filehandle = ...; # existing binary-mode filehandle
179 my $md5_b64url = md5_file_b64u($filehandle);
180  
181 =head1 METHODS
182  
183 The OO interface provides the same set of functions as L<Crypt::Digest>.
184 Unless noted otherwise, assume C<$d> is an existing digest object created via
185 C<new>, for example:
186  
187 my $d = Crypt::Digest::MD5->new();
188  
189 =head2 new
190  
191 my $d = Crypt::Digest::MD5->new();
192  
193 =head2 clone
194  
195 $d->clone();
196  
197 =head2 reset
198  
199 $d->reset();
200  
201 =head2 add
202  
203 Appends data to the message. Returns the object itself (for chaining).
204  
205 Each argument is converted to bytes using Perl's usual scalar stringification.
206 Defined scalars, including numbers and string-overloaded objects, are
207 accepted. C<undef> is treated as an empty string and may emit Perl's usual
208 "uninitialized value" warning.
209  
210 $d->add('any data');
211 #or
212 $d->add('any data', 'more data', 'even more data');
213  
214 =head2 addfile
215  
216 Reads the file content and appends it to the message. Returns the object itself (for chaining).
217  
218 $d->addfile('filename.dat');
219 #or
220 my $filehandle = ...; # existing binary-mode filehandle
221 $d->addfile($filehandle);
222  
223 =head2 hashsize
224  
225 $d->hashsize;
226 #or
227 Crypt::Digest::MD5->hashsize();
228 #or
229 Crypt::Digest::MD5::hashsize();
230  
231 =head2 digest
232  
233 Returns the binary digest (raw bytes).
234 The first call finalizes the digest object. Any later C<add()>,
235 C<addfile()>, C<digest()>, C<hexdigest()>, C<b64digest()>, or
236 C<b64udigest()> call will fail until you call C<reset()>.
237  
238 my $result_raw = $d->digest();
239  
240 =head2 hexdigest
241  
242 Returns the digest encoded as a lowercase hexadecimal string.
243 Like C<digest()>, the first call finalizes the digest object.
244  
245 my $result_hex = $d->hexdigest();
246  
247 =head2 b64digest
248  
249 Returns the digest encoded as a Base64 string with trailing C<=> padding.
250 Like C<digest()>, the first call finalizes the digest object.
251  
252 my $result_b64 = $d->b64digest();
253  
254 =head2 b64udigest
255  
256 Returns the digest encoded as a Base64 URL-safe string (no trailing C<=>).
257 Like C<digest()>, the first call finalizes the digest object.
258  
259 my $result_b64url = $d->b64udigest();
260  
261 =head1 SEE ALSO
262  
263 =over
264  
265 =item * L<CryptX>, L<Crypt::Digest>
266  
267 =item * L<https://en.wikipedia.org/wiki/MD5>
268  
269 =back
270  
271 =cut
« blib/lib/Crypt/Digest/MD4.pm ↑ Summary blib/lib/Crypt/Digest/RIPEMD128.pm »