Alt-Digest-MD5-OpenSSL

 view release on metacpan or  search on metacpan

lib/Digest/MD5.pm  view on Meta::CPAN

163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
message we calculate the digest for.  The return value is the $md5
object itself.
 
The addfile() method will croak() if it fails reading data for some
reason.  If it croaks it is unpredictable what the state of the $md5
object will be in. The addfile() method might have been able to read
the file partially before it failed.  It is probably wise to discard
or reset the $md5 object if this occurs.
 
In most cases you want to make sure that the $io_handle is in
C<binmode> before you pass it as argument to the addfile() method.
 
=item $md5->add_bits($data, $nbits)
 
=item $md5->add_bits($bitstring)
 
Since the MD5 algorithm is byte oriented you might only add bits as
multiples of 8, so you probably want to just use add() instead.  The
add_bits() method is provided for compatibility with other digest
implementations.  See L<Digest> for description of the arguments
that add_bits() take.

lib/Digest/MD5.pm  view on Meta::CPAN

250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
With OO style, you can break the message arbitrarily.  This means that we
are no longer limited to have space for the whole message in memory, i.e.
we can handle messages of any size.
 
This is useful when calculating checksum for files:
 
    use Digest::MD5;
 
    my $filename = shift || "/etc/passwd";
    open (my $fh, '<', $filename) or die "Can't open '$filename': $!";
    binmode($fh);
 
    my $md5 = Digest::MD5->new;
    while (<$fh>) {
        $md5->add($_);
    }
    close($fh);
    print $md5->b64digest, " $filename\n";
 
Or we can use the addfile method for more efficient reading of
the file:
 
    use Digest::MD5;
 
    my $filename = shift || "/etc/passwd";
    open (my $fh, '<', $filename) or die "Can't open '$filename': $!";
    binmode ($fh);
 
    print Digest::MD5->new->addfile($fh)->hexdigest, " $filename\n";
 
Since the MD5 algorithm is only defined for strings of bytes, it can not be
used on strings that contains chars with ordinal number above 255 (Unicode
strings).  The MD5 functions and methods will croak if you try to feed them
such input data:
 
    use Digest::MD5 qw(md5_hex);

t/original/files.t  view on Meta::CPAN

150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
    $digest;
}
 
sub cat_file
{
    my($file) = @_;
    local $/;  # slurp
    open(FILE, $file) or die "Can't open $file: $!";
 
    # For PerlIO in case of UTF-8 locales.
    eval 'binmode(FILE, ":bytes")' if $] >= 5.008;
 
    my $tmp = <FILE>;
    close(FILE);
    $tmp;
}



( run in 0.428 second using v1.01-cache-2.11-cpan-3fc6ead820a )