SSH2/Format/PKCS1.pm

filter: Statementstmt 100% 27 / 27 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 94.8% 37 / 39 CC 3 SCAR 5.2
CC
3
Cov
94%
generate
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.7
« SSH2/Format/PKCS8.pm ↑ Summary SSH2/Format/Base.pm »
1 package Convert::SSH2::Format::PKCS1;
2  
3 1 our $VERSION = '0.01';
4  
5 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 extends 'Convert::SSH2::Format::Base';
7  
8 1 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use MIME::Base64 qw(encode_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Convert::ASN1;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =head1 NAME
13  
14 Convert::SSH2::Format::PKCS1 - Format SSH key data as PKCS1
15  
16 =head1 PURPOSE
17  
18 This module formats SSH2 RSA public keys as PKCS1 strings.
19  
20 Generally, you shouldn't instantiate this class on its own. It will be called by L<Convert::SSH2>
21 when needed.
22  
23 =head1 ATTRIBUTES
24  
25 =over
26  
27 =item asn
28  
29 Holds an ASN converter. Defaults to L<Convert::ASN1>.
30  
31 =back
32  
33 =cut
34  
35 has 'asn' => (
36 is => 'ro',
37 2 ▶ default => sub { Convert::ASN1->new(); },
Subroutine __ANON__: called CC=1 SCAR=0.0
38 1 );
39  
40 =over
41  
42 =item asn_template
43  
44 The ASN encoding template.
45  
46 Defaults to:
47  
48 RSAPublicKey ::= SEQUENCE {
49 modulus INTEGER, -- n
50 publicExponent INTEGER -- e
51 }
52  
53 =back
54  
55 =cut
56  
57 has 'asn_template' => (
58 is => 'ro',
59 2 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
60 2 return <<_EOT;
61 RSAPublicKey ::= SEQUENCE {
62 modulus INTEGER, -- n
63 publicExponent INTEGER -- e
64 }
65 _EOT
66 },
67 1 );
68  
69  
70 =head1 METHOD
71  
72 =over
73  
74 =item generate()
75  
76 Returns a PKCS#1 formatted string, given C<n> and C<e>.
77  
78 =back
79  
80 =cut
81  
82 2 ▶sub generate {
Subroutine generate: called CC=3 SCAR=11.1
Pod documented
83 2 my $self = shift;
84  
85 2 ▶ $self->asn->prepare($self->asn_template) or confess;
Branch: 1 branch
BranchTrueFalseTotal
$self->asn->prepare($self->asn_template) or confess() 2 0 2
86  
87 2 ▶ my $pdu = $self->asn->encode(
Branch: 1 branch
BranchTrueFalseTotal
my $pdu = $self->asn->encode("modulus", $self->n, "publicExponent", $self->e) or confess() 2 0 2
88 modulus => $self->n,
89 publicExponent => $self->e,
90 ) or confess;
91  
92 2 my $b64 = encode_base64($pdu, "");
93  
94 2 my $out = "-----BEGIN RSA PUBLIC KEY-----\n";
95 2 $out .= $self->format_lines($b64);
96 2 $out .= "-----END RSA PUBLIC KEY-----\n";
97  
98 2 return $out;
99 }
100  
101 =head1 SEE ALSO
102  
103 L<Convert::SSH2>
104  
105 =cut
106  
107 1 1;
« SSH2/Format/PKCS8.pm ↑ Summary SSH2/Format/Base.pm »