libcryptx-perl/lib/Crypt/Checksum.pm

70 lines
2.2 KiB
Perl
Raw Normal View History

2018-03-22 15:51:09 +01:00
package Crypt::Checksum;
use strict;
use warnings;
2018-03-22 15:54:03 +01:00
our $VERSION = '0.058_002';
2018-03-22 15:51:09 +01:00
require Exporter; our @ISA = qw(Exporter); ### use Exporter 'import';
2018-03-22 15:54:03 +01:00
our %EXPORT_TAGS = ( all => [qw/ adler32_data adler32_data_hex adler32_data_int adler32_file adler32_file_hex adler32_file_int
crc32_data crc32_data_hex crc32_data_int crc32_file crc32_file_hex crc32_file_int /] );
2018-03-22 15:51:09 +01:00
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = qw();
use Carp;
2018-03-22 15:54:03 +01:00
$Carp::Internal{(__PACKAGE__)}++;
2018-03-22 15:51:09 +01:00
2018-03-22 15:54:03 +01:00
# obsolete since v0.057, only for backwards compatibility
use Crypt::Checksum::CRC32;
use Crypt::Checksum::Adler32;
sub adler32_data { goto \&Crypt::Checksum::Adler32::adler32_data }
sub adler32_data_hex { goto \&Crypt::Checksum::Adler32::adler32_data_hex }
sub adler32_data_int { goto \&Crypt::Checksum::Adler32::adler32_data_int }
sub adler32_file { goto \&Crypt::Checksum::Adler32::adler32_file }
sub adler32_file_hex { goto \&Crypt::Checksum::Adler32::adler32_file_hex }
sub adler32_file_int { goto \&Crypt::Checksum::Adler32::adler32_file_int }
sub crc32_data { goto \&Crypt::Checksum::CRC32::crc32_data }
sub crc32_data_hex { goto \&Crypt::Checksum::CRC32::crc32_data_hex }
sub crc32_data_int { goto \&Crypt::Checksum::CRC32::crc32_data_int }
sub crc32_file { goto \&Crypt::Checksum::CRC32::crc32_file }
sub crc32_file_hex { goto \&Crypt::Checksum::CRC32::crc32_file_hex }
sub crc32_file_int { goto \&Crypt::Checksum::CRC32::crc32_file_int }
sub addfile {
my ($self, $file) = @_;
my $handle;
if (ref(\$file) eq 'SCALAR') { #filename
open($handle, "<", $file) || croak "FATAL: cannot open '$file': $!";
binmode($handle);
}
else { #handle
$handle = $file
}
croak "FATAL: invalid handle" unless defined $handle;
my $n;
my $buf = "";
while (($n = read($handle, $buf, 32*1024))) {
$self->add($buf)
}
croak "FATAL: read failed: $!" unless defined $n;
return $self;
}
sub CLONE_SKIP { 1 } # prevent cloning
2018-03-22 15:51:09 +01:00
1;
=pod
=head1 NAME
2018-03-22 15:54:03 +01:00
Crypt::Checksum - [internal only]
2018-03-22 15:51:09 +01:00
=head1 DESCRIPTION
2018-03-22 15:54:03 +01:00
You are probably looking for L<Crypt::Checksum::CRC32> or L<Crypt::Checksum::Adler32>.
2018-03-22 15:51:09 +01:00
2018-03-22 15:54:03 +01:00
=cut