summaryrefslogtreecommitdiff
path: root/lib/Crypt/Checksum.pm
blob: 043b006b023aff655ac95c00afe651de288eaeb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package Crypt::Checksum;

use strict;
use warnings;
our $VERSION = '0.079_006';

require Exporter; our @ISA = qw(Exporter); ### use Exporter 5.57 'import';
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 /] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = qw();

use Carp;
$Carp::Internal{(__PACKAGE__)}++;

# 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

1;

=pod

=head1 NAME

Crypt::Checksum - [internal only]

=head1 DESCRIPTION

You are probably looking for L<Crypt::Checksum::CRC32> or L<Crypt::Checksum::Adler32>.

=cut