File Coverage

lib/Crypt/Perl/RSA/PublicKey.pm
Criterion Covered Total %
statement 17 17 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 23 23 100.0


line stmt bran cond sub pod time code
1             package Crypt::Perl::RSA::PublicKey;
2              
3             =encoding utf-8
4              
5             =head1 NAME
6              
7             Crypt::Perl::RSA::PublicKey - object representation of an RSA public key
8              
9             =head1 SYNOPSIS
10              
11             #You’ll probably instantiate this class using Parser.pm
12             #or PrivateKey’s get_public_key() method.
13              
14             #cf. JSON Web Algorithms (RFC 7518, page 5)
15             #These return 1 or 0 to indicate verification or non-verification.
16             $pbkey->verify_RS256($message, $sig);
17             $pbkey->verify_RS384($message, $sig);
18             $pbkey->verify_RS512($message, $sig);
19              
20             #----------------------------------------------------------------------
21              
22             my $enc = $pbkey->encrypt_raw($payload);
23              
24             #----------------------------------------------------------------------
25              
26             my $der = $pbkey->to_der();
27             my $pem = $pbkey->to_pem();
28              
29             #For use in creating PKCS #10 CSRs and X.509 certificates
30             my $pub_der = $pbkey->to_subject_der();
31              
32             #----------------------------------------------------------------------
33              
34             $pbkey->size(); #modulus length, in bits
35             $pbkey->modulus_byte_length();
36              
37             #----------------------------------------------------------------------
38             # The following all return instances of Crypt::Perl::BigInt,
39             # a subclass of Math::BigInt.
40             # The pairs (e.g., modulus() and N()) are aliases.
41             #----------------------------------------------------------------------
42              
43             $pbkey->modulus();
44             $pbkey->N();
45              
46             $pbkey->publicExponent();
47             $pbkey->E();
48             $pbkey->exponent(); #another alias of publicExponent()
49              
50             =cut
51              
52 5     5   330 use strict;
  5         7  
  5         176  
53 5     5   21 use warnings;
  5         8  
  5         143  
54              
55 5         41 use parent qw(
56             Crypt::Perl::RSA::KeyBase
57 5     5   906 );
  5         14  
58              
59 5     5   262 use constant _PEM_HEADER => 'RSA PUBLIC KEY';
  5         9  
  5         270  
60 5     5   21 use constant _ASN1_MACRO => 'RSAPublicKey';
  5         8  
  5         298  
61              
62             BEGIN {
63 5     5   87 *exponent = __PACKAGE__->can('publicExponent');
64 5         114 *to_subject_der = __PACKAGE__->can('_to_subject_public_der');
65             }
66              
67             1;