line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::OpenPGP::Digest; |
2
|
1
|
|
|
1
|
|
804
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
48
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
639
|
use Crypt::OpenPGP::ErrorHandler; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
40
|
|
5
|
1
|
|
|
1
|
|
7
|
use base qw( Crypt::OpenPGP::ErrorHandler ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
181
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use vars qw( %ALG %ALG_BY_NAME ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
440
|
|
8
|
|
|
|
|
|
|
%ALG = ( |
9
|
|
|
|
|
|
|
1 => 'MD5', |
10
|
|
|
|
|
|
|
2 => 'SHA1', |
11
|
|
|
|
|
|
|
3 => 'RIPEMD160', |
12
|
|
|
|
|
|
|
); |
13
|
|
|
|
|
|
|
%ALG_BY_NAME = map { $ALG{$_} => $_ } keys %ALG; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
2
|
|
|
2
|
1
|
218
|
my $class = shift; |
17
|
2
|
|
|
|
|
4
|
my $alg = shift; |
18
|
2
|
|
33
|
|
|
7
|
$alg = $ALG{$alg} || $alg; |
19
|
2
|
50
|
|
|
|
8
|
return $class->error("Unsupported digest algorithm '$alg'") |
20
|
|
|
|
|
|
|
unless $alg =~ /^\D/; |
21
|
2
|
|
|
|
|
5
|
my $pkg = join '::', $class, $alg; |
22
|
2
|
|
|
|
|
9
|
my $dig = bless { __alg => $alg, |
23
|
|
|
|
|
|
|
__alg_id => $ALG_BY_NAME{$alg} }, $pkg; |
24
|
2
|
|
|
|
|
7
|
$dig->init(@_); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
0
|
0
|
0
|
sub init { $_[0] } |
28
|
0
|
|
|
0
|
1
|
0
|
sub hash { $_[0]->{md}->($_[1]) } |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub alg { |
31
|
0
|
0
|
|
0
|
1
|
0
|
return $_[0]->{__alg} if ref($_[0]); |
32
|
0
|
0
|
|
|
|
0
|
$ALG{$_[1]} || $_[1]; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub alg_id { |
36
|
0
|
0
|
|
0
|
1
|
0
|
return $_[0]->{__alg_id} if ref($_[0]); |
37
|
0
|
0
|
|
|
|
0
|
$ALG_BY_NAME{$_[1]} || $_[1]; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub supported { |
41
|
0
|
|
|
0
|
0
|
0
|
my $class = shift; |
42
|
0
|
|
|
|
|
0
|
my %s; |
43
|
0
|
|
|
|
|
0
|
for my $did (keys %ALG) { |
44
|
0
|
|
|
|
|
0
|
my $digest = $class->new($did); |
45
|
0
|
0
|
|
|
|
0
|
$s{$did} = $digest->alg if $digest; |
46
|
|
|
|
|
|
|
} |
47
|
0
|
|
|
|
|
0
|
\%s; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
package Crypt::OpenPGP::Digest::MD5; |
51
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
32
|
|
52
|
1
|
|
|
1
|
|
6
|
use base qw( Crypt::OpenPGP::Digest ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
138
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub init { |
55
|
1
|
|
|
1
|
|
3
|
my $dig = shift; |
56
|
1
|
|
|
|
|
5
|
require Digest::MD5; |
57
|
1
|
|
|
|
|
9
|
$dig->{md} = \&Digest::MD5::md5; |
58
|
1
|
|
|
|
|
4
|
$dig; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
package Crypt::OpenPGP::Digest::SHA1; |
62
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
63
|
1
|
|
|
1
|
|
5
|
use base qw( Crypt::OpenPGP::Digest ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
145
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub init { |
66
|
1
|
|
|
1
|
|
2
|
my $dig = shift; |
67
|
1
|
|
|
|
|
2256
|
require Digest::SHA1; |
68
|
0
|
|
|
|
|
|
$dig->{md} = \&Digest::SHA1::sha1; |
69
|
0
|
|
|
|
|
|
$dig; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
package Crypt::OpenPGP::Digest::RIPEMD160; |
73
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
74
|
1
|
|
|
1
|
|
4
|
use base qw( Crypt::OpenPGP::Digest ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
163
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub init { |
77
|
0
|
|
|
0
|
|
|
my $dig = shift; |
78
|
0
|
|
|
|
|
|
require Crypt::RIPEMD160; |
79
|
0
|
|
|
0
|
|
|
$dig->{md} = sub { Crypt::RIPEMD160->hash($_[0]) }; |
|
0
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
$dig; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
__END__ |