File Coverage

blib/lib/Crypt/RSA/Parse.pm
Criterion Covered Total %
statement 17 17 100.0
branch n/a
condition 2 3 66.6
subroutine 9 9 100.0
pod 0 4 0.0
total 28 33 84.8


line stmt bran cond sub pod time code
1             package Crypt::RSA::Parse;
2              
3 2     2   36150 use strict;
  2         3  
  2         53  
4 2     2   16 use warnings;
  2         2  
  2         90  
5              
6             our $VERSION = 0.043;
7              
8             =pod
9              
10             =encoding utf-8
11              
12             =head1 NAME
13              
14             Crypt::RSA::Parse - Parse RSA keys
15              
16             =head1 SYNOPSIS
17              
18             #General-purpose, native RSA or PKCS8 (DER or PEM)
19             my $public_rsa = Crypt::RSA::Parse::public($key_str);
20             my $private_rsa = Crypt::RSA::Parse::private($private_key_str);
21              
22             $public_rsa->exponent(); #alias E()
23             $public_rsa->modulus(); #isa Math::BigInt, alias N()
24             $public_rsa->size(); #i.e., the modulus length in bits
25              
26             $private_rsa->version(); #usually 0
27             $private_rsa->modulus(); #isa Math::BigInt, alias N()
28             $private_rsa->size(); #i.e., the modulus length in bits
29              
30             $private_rsa->publicExponent(); #same as public “exponent”, alias E()
31             $private_rsa->privateExponent(); #isa Math::BigInt, alias D()
32             $private_rsa->prime1(); #isa Math::BigInt, alias P()
33             $private_rsa->prime2(); #isa Math::BigInt, alias Q()
34             $private_rsa->exponent1(); #isa Math::BigInt, alias DP()
35             $private_rsa->exponent2(); #isa Math::BigInt, alias DQ()
36             $private_rsa->coefficient(); #isa Math::BigInt, alias QINV()
37              
38             #Only checks PKCS8 (DER or PEM)
39             $public_rsa = Crypt::RSA::Parse::public_pkcs8($pkcs8_str);
40             $private_rsa = Crypt::RSA::Parse::private_pkcs8($pkcs8_str);
41              
42             {
43             #If, for whatever reason, you don’t like MIME::Base64,
44             #then customize this. The module must have a decode() function.
45             #
46             local $Crypt::RSA::Parse::BASE64_MODULE = '..';
47              
48             Crypt::RSA::Parse::...
49             }
50              
51             =head1 DESCRIPTION
52              
53             Not much else to say: it parses RSA keys for useful information!
54              
55             The public keys are represented via the C
56             class, while private keys are represented via C.
57              
58             =cut
59              
60 2     2   977 use Crypt::Format ();
  2         903  
  2         36  
61              
62 2     2   828 use Crypt::RSA::Parse::Parser::MathBigInt (); #lazy-loads Math::BigInt only
  2         5  
  2         479  
63              
64             our $BASE64_MODULE = 'MIME::Base64';
65              
66             my %parser;
67              
68             sub _MathBigInt {
69 10   66 10   151 return $parser{'MathBigInt'} ||= Crypt::RSA::Parse::Parser::MathBigInt->new();
70             }
71              
72             sub private {
73 3     3 0 39367 return _MathBigInt()->private(@_);
74             }
75              
76             sub public {
77 3     3 0 19503 return _MathBigInt()->public(@_);
78             }
79              
80             sub private_pkcs8 {
81 2     2 0 29648 return _MathBigInt()->private_pkcs8(@_);
82             }
83              
84             sub public_pkcs8 {
85 2     2 0 20138 return _MathBigInt()->public_pkcs8(@_);
86             }
87              
88             #----------------------------------------------------------------------
89              
90             =head1 AUTHOR
91              
92             Felipe M. L. Gasper
93             CPAN ID: FELIPE
94              
95             =head1 REPOSITORY
96              
97             https://github.com/FGasper/p5-Crypt-RSA-Parse
98              
99             =head1 COPYRIGHT
100              
101             This program is free software; you can redistribute
102             it and/or modify it under the same terms as Perl itself.
103              
104             The full text of the license can be found in the
105             LICENSE file included with this module.
106              
107             =cut
108              
109             1;