OpenPGP/Key/Public/RSA.pm

filter: Statementstmt 81.9% 50 / 61 Branchbran 33.3% 2 / 6 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 66.6% 12 / 18 Podpod 38.4% 5 / 13 totaltotal 66.6% 72 / 108 CC 6 SCAR 7.4
CC
6
Cov
75%
encrypt
6.0
keygen
3.1
init
2.0
CRAP 2.1
« OpenPGP/ErrorHandler.pm ↑ Summary OpenPGP/Key.pm »
1 package Crypt::OpenPGP::Key::Public::RSA;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 4 our $VERSION = '1.21'; # VERSION
5  
6 4 ▶use Crypt::RSA::Key::Public;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Crypt::OpenPGP::Digest;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Crypt::OpenPGP::Util qw( bitsize bin2mp mp2bin );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use parent qw( Crypt::OpenPGP::Key::Public Crypt::OpenPGP::ErrorHandler );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 0 ▶sub can_encrypt { 1 }
Subroutine can_encrypt: not called CC=1 SCAR=6.9
Pod documented
12 0 ▶sub can_sign { 1 }
Subroutine can_sign: not called CC=1 SCAR=6.9
Pod documented
13 0 ▶sub abbrev { 'R' }
Subroutine abbrev: not called CC=1 SCAR=6.9
Pod undocumented
14  
15 24 ▶sub public_props { qw( n e ) }
Subroutine public_props: called CC=1 SCAR=0.0
Pod undocumented
16 0 ▶sub crypt_props { qw( c ) }
Subroutine crypt_props: not called CC=1 SCAR=6.9
Pod undocumented
17 10 ▶sub sig_props { qw( c ) }
Subroutine sig_props: called CC=1 SCAR=0.0
Pod undocumented
18  
19 13 ▶sub init {
Subroutine init: called CC=2 SCAR=7.0
Pod undocumented
20 13 my $key = shift;
21 13 ▶ $key->{key_data} = shift || Crypt::RSA::Key::Public->new;
Condition66%2/3
shift() || 'Crypt::RSA::Key::Public'->new
l!l&&r!l&&!r
1120
MC/DC0%0/2
shift() || 'Crypt::RSA::Key::Public'->new
shift() 'Crypt::RSA::Key::Public'->new
Truth table66%2/3
A || B
A= shift()B= 'Crypt::RSA::Key::Public'->new
ABresult
1X1
011
000
22 13 $key;
23 }
24  
25 1 ▶sub keygen {
Subroutine keygen: called CC=3 SCAR=11.3
Pod documented
26 1 my $class = shift;
27 1 my %param = @_;
28 1 $param{Password} = $param{Passphrase};
29 1 require Crypt::RSA::Key;
30 1 my $chain = Crypt::RSA::Key->new;
31 1 my($pub, $sec) = $chain->generate( %param );
32 1 ▶ return $class->error( $chain->errstr ) unless $pub && $sec;
Branch: 1 branch
BranchTrueFalseTotal
unless $pub and $sec 0 1 1
Condition33%1/3
$pub and $sec
!ll&&!rl&&r
001
MC/DC0%0/2
$pub and $sec
$pub $sec
Truth table33%1/3
A and B
A= $pubB= $sec
ABresult
0X0
100
111
33 1 ($pub, $sec);
34 }
35  
36 5 ▶sub size { bitsize($_[0]->{key_data}->n) }
Subroutine size: called CC=1 SCAR=0.0
Pod documented
37  
38 0 ▶sub check { $_[0]->{key_data}->check }
Subroutine check: not called CC=1 SCAR=6.9
Pod documented
39  
40 0 ▶sub encrypt {
Subroutine encrypt: not called CC=2 SCAR=17.9
Pod undocumented
41 0 my $key = shift;
42 0 my($M) = @_;
43 0 require Crypt::RSA::Primitives;
44 0 my $prim = Crypt::RSA::Primitives->new;
45 0 ▶ my $c = $prim->core_encrypt( Key => $key->{key_data}, Plaintext => $M ) or
Branch: 1 branch
BranchTrueFalseTotal
my $c = $prim->core_encrypt("Key", $key->{"key_data"}, "Plaintext", $M) or return $key->error($prim->errstr) 0 0 0
46 return $key->error($prim->errstr);
47 0 { c => $c }
48 }
49  
50 2 ▶sub verify {
Subroutine verify: called CC=2 SCAR=6.9
Pod undocumented
51 2 my $key = shift;
52 2 my($sig, $dgst) = @_;
53 2 my $k = $key->bytesize;
54 2 require Crypt::RSA::Primitives;
55 2 my $prim = Crypt::RSA::Primitives->new;
56 2 my $c = $sig->{c};
57 2 ▶ my $m = $prim->core_verify( Key => $key->{key_data}, Signature => $c) or
Branch: 1 branch
BranchTrueFalseTotal
my $m = $prim->core_verify("Key", $key->{"key_data"}, "Signature", $c) or return 2 0 2
58 return;
59 2 $m = mp2bin($m, $k - 1);
60 2 my $hash_alg = Crypt::OpenPGP::Digest->alg($sig->{hash_alg});
61 2 my $M = encode($dgst, $hash_alg, $k - 1);
62 2 $m eq $M;
63 }
64  
65 {
66 4 my %ENCODING = (
67 MD2 => pack('H*', '3020300C06082A864886F70D020205000410'),
68 MD5 => pack('H*', '3020300C06082A864886F70D020505000410'),
69 SHA1 => pack('H*', '3021300906052B0E03021A05000414'),
70 SHA256 => pack('H*', '3031300d060960864801650304020105000420'),
71 SHA224 => pack('H*', '302d300d06096086480165030402040500041c'),
72 SHA384 => pack('H*', '3041300d060960864801650304020205000430'),
73 SHA512 => pack('H*', '3051300d060960864801650304020305000440'),
74 RIPEMD160 => pack('H*', '3021300906052b2403020105000414'),
75 );
76  
77 3 ▶ sub encode {
Subroutine encode: called CC=1 SCAR=0.0
Pod undocumented
78 3 my($dgst, $hash_alg, $mlen) = @_;
79 3 my $alg = $ENCODING{$hash_alg};
80 3 my $m = $alg . $dgst;
81 3 my $padlen = $mlen - length($m) - 2;
82 3 my $pad = chr(255) x $padlen;
83 3 chr(1) . $pad . chr(0) . $m;
84 }
85 }
86  
87 4 1;
« OpenPGP/ErrorHandler.pm ↑ Summary OpenPGP/Key.pm »