File Coverage

blib/lib/Crypt/OpenPGP/Key/Secret/RSA.pm
Criterion Covered Total %
statement 36 41 87.8
branch n/a
condition 2 3 66.6
subroutine 11 12 91.6
pod 0 4 0.0
total 49 60 81.6


line stmt bran cond sub pod time code
1             package Crypt::OpenPGP::Key::Secret::RSA;
2 2     2   14 use strict;
  2         4  
  2         93  
3 2     2   13 use warnings;
  2         5  
  2         337  
4              
5             our $VERSION = '1.19'; # VERSION
6              
7 2     2   657 use Crypt::RSA::Key::Private;
  2         40112  
  2         62  
8 2     2   638 use Crypt::OpenPGP::Key::Public::RSA;
  2         8  
  2         96  
9 2     2   13 use Crypt::OpenPGP::Key::Secret;
  2         5  
  2         91  
10 2     2   20 use Crypt::OpenPGP::Util qw( bin2mp );
  2         5  
  2         218  
11 2     2   10 use Crypt::OpenPGP::ErrorHandler;
  2         3  
  2         124  
12 2     2   19 use base qw( Crypt::OpenPGP::Key::Secret Crypt::OpenPGP::ErrorHandler );
  2         5  
  2         1209  
13              
14 8     8 0 45 sub secret_props { qw( d p q u ) }
15             *sig_props = \&Crypt::OpenPGP::Key::Public::RSA::sig_props;
16             *public_props = \&Crypt::OpenPGP::Key::Public::RSA::public_props;
17             *crypt_props = \&Crypt::OpenPGP::Key::Public::RSA::crypt_props;
18             *size = \&Crypt::OpenPGP::Key::Public::RSA::size;
19             *encode = \&Crypt::OpenPGP::Key::Public::RSA::encode;
20             *keygen = \&Crypt::OpenPGP::Key::Public::RSA::keygen;
21             *can_encrypt = \&Crypt::OpenPGP::Key::Public::RSA::can_encrypt;
22             *can_sign = \&Crypt::OpenPGP::Key::Public::RSA::can_sign;
23              
24             sub init {
25 6     6 0 21 my $key = shift;
26             $key->{key_data} = shift ||
27 6   66     71 Crypt::RSA::Key::Private->new( Password => 'pgp' );
28 6         488 $key;
29             }
30              
31             *encrypt = \&Crypt::OpenPGP::Key::Public::RSA::encrypt;
32              
33             sub decrypt {
34 0     0 0 0 my $key = shift;
35 0         0 my($C) = @_;
36 0         0 require Crypt::RSA::Primitives;
37 0         0 my $prim = Crypt::RSA::Primitives->new;
38 0         0 $prim->core_decrypt( Key => $key->{key_data}, Cyphertext => $C->{c} );
39             }
40              
41             sub sign {
42 1     1 0 3 my $key = shift;
43 1         4 my($dgst, $hash_alg) = @_;
44 1         12 my $m = encode($dgst, $hash_alg, $key->bytesize - 1);
45 1         894 require Crypt::RSA::Primitives;
46 1         3138 my $prim = Crypt::RSA::Primitives->new;
47 1         26 $m = bin2mp($m);
48 1         3578 my $c = $prim->core_sign( Key => $key->{key_data}, Message => $m );
49 1         4021502 { c => $c }
50             }
51              
52             1;