Parse.pm

filter: Statementstmt 100% 21 / 21 Branchbran n/a Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 4 totaltotal 82.0% 32 / 39 CC 2 SCAR 1.9
CC
2
Cov
96%
_MathBigInt
2.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« Parse/Parser.pm ↑ Summary Parse/Template.pm »
1 package Crypt::RSA::Parse;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = 0.044;
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 DEPRECATION NOTICE
52  
53 B<IMPORTANT:> This distribution is no longer maintained. See its successor,
54 L<Crypt::Perl>, for a much more comprehensive toolkit.
55  
56 =head1 DESCRIPTION
57  
58 Not much else to say: it parses RSA keys for useful information!
59  
60 The public keys are represented via the C<Crypt::RSA::Parse::Public>
61 class, while private keys are represented via C<Crypt::RSA::Parse::Private>.
62  
63 =cut
64  
65 2 ▶use Crypt::Format ();
Subroutine BEGIN: called CC=1 SCAR=0.0
66  
67 2 ▶use Crypt::RSA::Parse::Parser::MathBigInt (); #lazy-loads Math::BigInt only
Subroutine BEGIN: called CC=1 SCAR=0.0
68  
69 2 our $BASE64_MODULE = 'MIME::Base64';
70  
71 2 my %parser;
72  
73 10 ▶sub _MathBigInt {
Subroutine _MathBigInt: called CC=2 SCAR=7.2
74 10 ▶ return $parser{'MathBigInt'} ||= Crypt::RSA::Parse::Parser::MathBigInt->new();
Condition66%2/3
$parser{"MathBigInt"} ||= "Crypt::RSA::Parse::Parser::MathBigInt"->new
l!l&&r!l&&!r
910
MC/DC0%0/2
$parser{"MathBigInt"} ||= "Crypt::RSA::Parse::Parser::MathBigInt"->new
$parser{"MathBigInt"} "Crypt::RSA::Parse::Parser::MathBigInt"->new
Truth table66%2/3
A ||= B
A= $parser{"MathBigInt"}B= "Crypt::RSA::Parse::Parser::MathBigInt"->new
ABresult
1X1
011
000
75 }
76  
77 3 ▶sub private {
Subroutine private: called CC=1 SCAR=0.0
Pod undocumented
78 3 return _MathBigInt()->private(@_);
79 }
80  
81 3 ▶sub public {
Subroutine public: called CC=1 SCAR=0.0
Pod undocumented
82 3 return _MathBigInt()->public(@_);
83 }
84  
85 2 ▶sub private_pkcs8 {
Subroutine private_pkcs8: called CC=1 SCAR=0.0
Pod undocumented
86 2 return _MathBigInt()->private_pkcs8(@_);
87 }
88  
89 2 ▶sub public_pkcs8 {
Subroutine public_pkcs8: called CC=1 SCAR=0.0
Pod undocumented
90 2 return _MathBigInt()->public_pkcs8(@_);
91 }
92  
93 #----------------------------------------------------------------------
94  
95 =head1 AUTHOR
96  
97 Felipe M. L. Gasper
98 CPAN ID: FELIPE
99  
100 =head1 REPOSITORY
101  
102 https://github.com/FGasper/p5-Crypt-RSA-Parse
103  
104 =head1 COPYRIGHT
105  
106 This program is free software; you can redistribute
107 it and/or modify it under the same terms as Perl itself.
108  
109 The full text of the license can be found in the
110 LICENSE file included with this module.
111  
112 =cut
113  
114 2 1;
« Parse/Parser.pm ↑ Summary Parse/Template.pm »