line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::DSA::Signature; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
17
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
116
|
|
4
|
3
|
|
|
3
|
|
16
|
use Carp qw( croak ); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
167
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
15
|
use vars qw{$VERSION}; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
136
|
|
7
|
|
|
|
|
|
|
BEGIN { |
8
|
3
|
|
|
3
|
|
286
|
$VERSION = '1.17'; |
9
|
|
|
|
|
|
|
} |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
13
|
0
|
|
|
|
|
|
my %param = @_; |
14
|
0
|
|
|
|
|
|
my $sig = bless { }, $class; |
15
|
0
|
0
|
|
|
|
|
if ($param{Content}) { |
16
|
0
|
|
|
|
|
|
return $sig->deserialize(%param); |
17
|
|
|
|
|
|
|
} |
18
|
0
|
|
|
|
|
|
$sig; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
BEGIN { |
22
|
3
|
|
|
3
|
|
15
|
no strict 'refs'; |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
940
|
|
23
|
3
|
|
|
3
|
|
8
|
for my $meth (qw( r s )) { |
24
|
|
|
|
|
|
|
*$meth = sub { |
25
|
0
|
|
|
0
|
|
|
my($key, $value) = @_; |
26
|
0
|
0
|
|
|
|
|
if (ref $value eq 'Math::Pari') { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
$key->{$meth} = Math::Pari::pari2pv($value); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
elsif (ref $value) { |
30
|
0
|
|
|
|
|
|
$key->{$meth} = "$value"; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
elsif ($value) { |
33
|
0
|
0
|
|
|
|
|
if ($value =~ /^0x/) { |
34
|
0
|
|
|
|
|
|
$key->{$meth} = Math::BigInt->new($value)->bstr; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
else { |
37
|
0
|
|
|
|
|
|
$key->{$meth} = $value; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
0
|
|
0
|
|
|
|
my $ret = $key->{$meth} || ""; |
41
|
0
|
0
|
|
|
|
|
$ret = Math::BigInt->new("$ret") if $ret =~ /^\d+$/; |
42
|
0
|
|
|
|
|
|
$ret; |
43
|
6
|
|
|
|
|
1054
|
}; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub asn { |
48
|
0
|
|
|
0
|
0
|
|
require Convert::ASN1; |
49
|
0
|
|
|
|
|
|
my $asn = Convert::ASN1->new; |
50
|
0
|
0
|
|
|
|
|
$asn->prepare('SEQUENCE { r INTEGER, s INTEGER }') or croak $asn->{error}; |
51
|
0
|
|
|
|
|
|
$asn; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub deserialize { |
55
|
0
|
|
|
0
|
0
|
|
my $sig = shift; |
56
|
0
|
|
|
|
|
|
my %param = @_; |
57
|
0
|
|
|
|
|
|
my $asn = __PACKAGE__->asn; |
58
|
0
|
|
|
|
|
|
my $ref; |
59
|
0
|
|
|
|
|
|
require MIME::Base64; |
60
|
|
|
|
|
|
|
## Turn off warnings, because we're attempting to base64-decode content |
61
|
|
|
|
|
|
|
## that may not be base64-encoded. |
62
|
0
|
|
|
|
|
|
local $^W = 0; |
63
|
0
|
|
|
|
|
|
for ($param{Content}, MIME::Base64::decode_base64($param{Content})) { |
64
|
0
|
|
|
|
|
|
my $out = $asn->decode($_); |
65
|
0
|
0
|
|
|
|
|
$ref = $out, last if $out; |
66
|
|
|
|
|
|
|
} |
67
|
0
|
0
|
|
|
|
|
croak "Invalid Content" unless $ref; |
68
|
0
|
|
|
|
|
|
$sig->s($ref->{s}); |
69
|
0
|
|
|
|
|
|
$sig->r($ref->{r}); |
70
|
0
|
|
|
|
|
|
$sig; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub serialize { |
74
|
0
|
|
|
0
|
1
|
|
my $sig = shift; |
75
|
0
|
|
|
|
|
|
my %param = @_; |
76
|
0
|
|
|
|
|
|
my $asn = __PACKAGE__->asn; |
77
|
0
|
0
|
|
|
|
|
my $buf = $asn->encode({ s => $sig->s, r => $sig->r }) |
78
|
|
|
|
|
|
|
or croak $asn->{error}; |
79
|
0
|
|
|
|
|
|
$buf; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
__END__ |