DSA/Signature.pm

filter: Statementstmt 92.9% 53 / 57 Branchbran 60.0% 12 / 20 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 11 / 11 Podpod 50.0% 2 / 4 totaltotal 83.1% 79 / 95 CC 14 SCAR 16.0
CC
14
Cov
84%
__ANON__
11.6
deserialize
4.0
BEGIN
2.2
CRAP 4.9
« DSA/Key.pm ↑ Summary DSA.pm »
1 package Crypt::DSA::Signature;
2  
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 7 our $VERSION = '1.24'; #VERSION
8 #
9 7 ▶use vars qw{$VERSION};
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
12 4 my $class = shift;
13 4 my %param = @_;
14 4 my $sig = bless { }, $class;
15 4 ▶ if ($param{Content}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param{"Content"}) 3 1 4
16 3 return $sig->deserialize(%param);
17 }
18 1 $sig;
19 }
20  
21 7 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.9
22 7 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 7 for my $meth (qw( r s )) {
24 19 ▶ *$meth = sub {
Subroutine __ANON__: called CC=7 SCAR=24.5
25 19 my($key, $value) = @_;
26 19 ▶ if (ref $value eq 'Math::Pari') {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $value eq 'Math::Pari') { } 0 19 19
elsif (ref $value) { } 8 11 19
elsif ($value) { } 0 11 11
27 0 $key->{$meth} = Math::Pari::pari2pv($value);
28 }
29 elsif (ref $value) {
30 8 $key->{$meth} = "$value";
31 }
32 elsif ($value) {
33 0 ▶ if ($value =~ /^0x/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /^0x/) { } 0 0 0
34 0 $key->{$meth} = Math::BigInt->new($value)->bstr;
35 }
36 else {
37 0 $key->{$meth} = $value;
38 }
39 }
40 19 ▶ my $ret = $key->{$meth} || "";
Condition50%1/2
$key->{$meth} || ''
l!l
190
MC/DC0%0/1
$key->{$meth} || ''
$key->{$meth}
Truth table50%1/2
A
A= $key->{$meth}
Aresult
11
00
41 19 ▶ $ret = Math::BigInt->new("$ret") if $ret =~ /^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
if $ret =~ /^\d+$/ 19 0 19
42 19 $ret;
43 14 };
44 }
45 }
46  
47 4 ▶sub asn {
Subroutine asn: called CC=2 SCAR=7.0
Pod undocumented
48 4 require Convert::ASN1;
49 4 my $asn = Convert::ASN1->new;
50 4 ▶ $asn->prepare('SEQUENCE { r INTEGER, s INTEGER }') or croak $asn->{error};
Branch: 1 branch
BranchTrueFalseTotal
$asn->prepare("SEQUENCE { r INTEGER, s INTEGER }") or croak($asn->{"error"}) 4 0 4
51 4 $asn;
52 }
53  
54 3 ▶sub deserialize {
Subroutine deserialize: called CC=4 SCAR=13.9
Pod undocumented
55 3 my $sig = shift;
56 3 my %param = @_;
57 3 my $asn = __PACKAGE__->asn;
58 3 my $ref;
59 3 require MIME::Base64;
60 ## Turn off warnings, because we're attempting to base64-decode content
61 ## that may not be base64-encoded.
62 3 local $^W = 0;
63 3 for ($param{Content}, MIME::Base64::decode_base64($param{Content})) {
64 4 my $out = $asn->decode($_);
65 4 ▶ $ref = $out, last if $out;
Branch: 1 branch
BranchTrueFalseTotal
if $out 3 1 4
66 }
67 3 ▶ croak "Invalid Content" unless $ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $ref 0 3 3
68 3 $sig->s($ref->{s});
69 3 $sig->r($ref->{r});
70 3 $sig;
71 }
72  
73 1 ▶sub serialize {
Subroutine serialize: called CC=2 SCAR=7.0
Pod documented
74 1 my $sig = shift;
75 1 my %param = @_;
76 1 my $asn = __PACKAGE__->asn;
77 my $buf = $asn->encode({ s => $sig->s, r => $sig->r })
78 1 ▶ or croak $asn->{error};
Branch: 1 branch
BranchTrueFalseTotal
my $buf = $asn->encode({"s", $sig->s, "r", $sig->r}) or croak($asn->{"error"}) 1 0 1
79 1 $buf;
80 }
81  
82 7 1;
83 __END__
« DSA/Key.pm ↑ Summary DSA.pm »