line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::DSA::Key; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
13
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
121
|
|
4
|
3
|
|
|
3
|
|
15
|
use Math::BigInt 1.78 try => 'GMP, Pari'; |
|
3
|
|
|
|
|
60
|
|
|
3
|
|
|
|
|
25
|
|
5
|
3
|
|
|
3
|
|
4428
|
use Carp qw( croak ); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
185
|
|
6
|
3
|
|
|
3
|
|
1672
|
use Crypt::DSA::Util qw( bitsize ); |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
223
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
18
|
use vars qw{$VERSION}; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
127
|
|
11
|
|
|
|
|
|
|
BEGIN { |
12
|
3
|
|
|
3
|
|
409
|
$VERSION = '1.17'; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
17
|
0
|
|
|
|
|
|
my %param = @_; |
18
|
0
|
|
|
|
|
|
my $key = bless { }, $class; |
19
|
|
|
|
|
|
|
|
20
|
0
|
0
|
0
|
|
|
|
if ($param{Filename} || $param{Content}) { |
21
|
0
|
0
|
0
|
|
|
|
if ($param{Filename} && $param{Content}) { |
22
|
0
|
|
|
|
|
|
croak "Filename and Content are mutually exclusive."; |
23
|
|
|
|
|
|
|
} |
24
|
0
|
|
|
|
|
|
return $key->read(%param); |
25
|
|
|
|
|
|
|
} |
26
|
0
|
|
|
|
|
|
$key; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
0
|
1
|
|
sub size { bitsize($_[0]->p) } |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
BEGIN { |
32
|
3
|
|
|
3
|
|
16
|
no strict 'refs'; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
845
|
|
33
|
3
|
|
|
3
|
|
10
|
for my $meth (qw( p q g pub_key priv_key r kinv )) { |
34
|
|
|
|
|
|
|
*$meth = sub { |
35
|
0
|
|
|
0
|
|
|
my($key, $value) = @_; |
36
|
0
|
0
|
0
|
|
|
|
if (ref $value eq 'Math::Pari') { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
$key->{$meth} = Math::Pari::pari2pv($value); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
elsif (ref $value) { |
40
|
0
|
|
|
|
|
|
$key->{$meth} = "$value"; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
elsif ($value) { |
43
|
0
|
0
|
|
|
|
|
if ($value =~ /^0x/) { |
44
|
0
|
|
|
|
|
|
$key->{$meth} = Math::BigInt->new($value)->bstr; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
else { |
47
|
0
|
|
|
|
|
|
$key->{$meth} = $value; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} elsif (@_ > 1 && !defined $value) { |
50
|
0
|
|
|
|
|
|
delete $key->{$meth}; |
51
|
|
|
|
|
|
|
} |
52
|
0
|
|
0
|
|
|
|
my $ret = $key->{$meth} || ""; |
53
|
0
|
0
|
|
|
|
|
$ret = Math::BigInt->new("$ret") if $ret =~ /^\d+$/; |
54
|
0
|
|
|
|
|
|
$ret; |
55
|
21
|
|
|
|
|
2090
|
}; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub read { |
60
|
0
|
|
|
0
|
0
|
|
my $key = shift; |
61
|
0
|
|
|
|
|
|
my %param = @_; |
62
|
0
|
0
|
|
|
|
|
my $type = $param{Type} or croak "read: Need a key file 'Type'"; |
63
|
0
|
|
|
|
|
|
my $class = join '::', __PACKAGE__, $type; |
64
|
0
|
|
|
|
|
|
eval "use $class;"; |
65
|
0
|
0
|
|
|
|
|
croak "Invalid key file type '$type': $@" if $@; |
66
|
0
|
|
|
|
|
|
bless $key, $class; |
67
|
0
|
|
|
|
|
|
local *FH; |
68
|
0
|
0
|
|
|
|
|
if (my $fname = delete $param{Filename}) { |
69
|
0
|
0
|
|
|
|
|
open FH, $fname or return; |
70
|
0
|
|
|
|
|
|
my $blob = do { local $/; }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
close FH; |
72
|
0
|
|
|
|
|
|
$param{Content} = $blob; |
73
|
|
|
|
|
|
|
} |
74
|
0
|
|
|
|
|
|
$key->deserialize(%param); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub write { |
78
|
0
|
|
|
0
|
1
|
|
my $key = shift; |
79
|
0
|
|
|
|
|
|
my %param = @_; |
80
|
0
|
|
|
|
|
|
my $type; |
81
|
0
|
0
|
|
|
|
|
unless ($type = $param{Type}) { |
82
|
0
|
|
|
|
|
|
my $pkg = __PACKAGE__; |
83
|
0
|
|
|
|
|
|
($type) = ref($key) =~ /^${pkg}::(\w+)$/; |
84
|
|
|
|
|
|
|
} |
85
|
0
|
0
|
|
|
|
|
croak "write: Need a key file 'Type'" unless $type; |
86
|
0
|
|
|
|
|
|
my $class = join '::', __PACKAGE__, $type; |
87
|
0
|
|
|
|
|
|
eval "use $class;"; |
88
|
0
|
0
|
|
|
|
|
croak "Invalid key file type '$type': $@" if $@; |
89
|
0
|
|
|
|
|
|
bless $key, $class; |
90
|
0
|
|
|
|
|
|
my $blob = $key->serialize(%param); |
91
|
0
|
0
|
|
|
|
|
if (my $fname = delete $param{Filename}) { |
92
|
0
|
|
|
|
|
|
local *FH; |
93
|
0
|
0
|
|
|
|
|
open FH, ">$fname" or croak "Can't open $fname: $!"; |
94
|
0
|
|
|
|
|
|
print FH $blob; |
95
|
0
|
|
|
|
|
|
close FH; |
96
|
|
|
|
|
|
|
} |
97
|
0
|
|
|
|
|
|
$blob; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
__END__ |