line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Digest::base; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
use strict; |
4
|
|
|
|
|
|
|
use warnings; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = "1.20"; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# subclass is supposed to implement at least these |
9
|
|
|
|
|
|
|
sub new; |
10
|
|
|
|
|
|
|
sub clone; |
11
|
|
|
|
|
|
|
sub add; |
12
|
|
|
|
|
|
|
sub digest; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub reset { |
15
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
16
|
0
|
|
|
|
|
|
$self->new(@_); # ugly |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub addfile { |
20
|
0
|
|
|
0
|
0
|
|
my ( $self, $handle ) = @_; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
my $n; |
23
|
0
|
|
|
|
|
|
my $buf = ""; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
while ( ( $n = read( $handle, $buf, 4 * 1024 ) ) ) { |
26
|
0
|
|
|
|
|
|
$self->add($buf); |
27
|
|
|
|
|
|
|
} |
28
|
0
|
0
|
|
|
|
|
unless ( defined $n ) { |
29
|
0
|
|
|
|
|
|
require Carp; |
30
|
0
|
|
|
|
|
|
Carp::croak("Read failed: $!"); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
$self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub add_bits { |
37
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
38
|
0
|
|
|
|
|
|
my $bits; |
39
|
|
|
|
|
|
|
my $nbits; |
40
|
0
|
0
|
|
|
|
|
if ( @_ == 1 ) { |
41
|
0
|
|
|
|
|
|
my $arg = shift; |
42
|
0
|
|
|
|
|
|
$bits = pack( "B*", $arg ); |
43
|
0
|
|
|
|
|
|
$nbits = length($arg); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
else { |
46
|
0
|
|
|
|
|
|
( $bits, $nbits ) = @_; |
47
|
|
|
|
|
|
|
} |
48
|
0
|
0
|
|
|
|
|
if ( ( $nbits % 8 ) != 0 ) { |
49
|
0
|
|
|
|
|
|
require Carp; |
50
|
0
|
|
|
|
|
|
Carp::croak("Number of bits must be multiple of 8 for this algorithm"); |
51
|
|
|
|
|
|
|
} |
52
|
0
|
|
|
|
|
|
return $self->add( substr( $bits, 0, $nbits / 8 ) ); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub hexdigest { |
56
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
57
|
0
|
|
|
|
|
|
return unpack( "H*", $self->digest(@_) ); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub b64digest { |
61
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
62
|
0
|
|
|
|
|
|
my $b64 = $self->base64_padded_digest; |
63
|
0
|
|
|
|
|
|
$b64 =~ s/=+$//; |
64
|
0
|
|
|
|
|
|
return $b64; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub base64_padded_digest { |
68
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
69
|
0
|
|
|
|
|
|
require MIME::Base64; |
70
|
0
|
|
|
|
|
|
return MIME::Base64::encode( $self->digest(@_), "" ); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__END__ |