lib/Crypt/Perl/ECDSA/PublicKey.pm

filter: Statementstmt 94.2% 33 / 35 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 91.6% 11 / 12 Podpod 0.0% 0 / 2 totaltotal 89.8% 44 / 49 CC 1 SCAR 0.8
CC
1
Cov
94%
algorithm_identifier_with_curve_name
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« lib/Crypt/Perl/X509/Extension/ct_precert_scts.pm ↑ Summary lib/Crypt/Perl/PKCS8.pm »
1 package Crypt::Perl::ECDSA::PublicKey;
2  
3 =encoding utf-8
4  
5 =head1 NAME
6  
7 Crypt::Perl::ECDSA::PublicKey - object representation of ECDSA public key
8  
9 =head1 SYNOPSIS
10  
11 #Use Parse.pm or a private key’s get_public_key()
12 #rather #than instantiating this class directly.
13  
14 #This works even if the object came from a key file that doesn’t
15 #contain the curve name.
16 $pbkey->get_curve_name();
17  
18 if ($payload > ($pbkey->max_sign_bits() / 8)) {
19 die "Payload too long!";
20 }
21  
22 $pbkey->verify($payload, $sig) or die "Invalid signature!";
23  
24 #For JSON Web Algorithms (JWT et al.), cf. RFC 7518 page 8
25 #This verifies against the appropriate SHA digest rather than
26 #against the original message.
27 $pbkey->verify_jwa($payload, $sig) or die "Invalid signature!";
28  
29 #----------------------------------------------------------------------
30  
31 #Includes “kty”, “crv”, “x”, and “y”.
32 #Add in whatever else your application needs afterward.
33 #
34 #This will die() if you try to run it with a curve that
35 #doesn’t have a known JWK “crv” value.
36 #
37 my $pub_jwk = $pbkey->get_struct_for_public_jwk();
38  
39 #Useful for JWTs
40 my $jwt_alg = $pbkey->get_jwa_alg();
41  
42 =head1 DISCUSSION
43  
44 The SYNOPSIS above should be illustration enough of how to use this class.
45  
46 Export methods (PEM, DER, etc.) are shown in L<Crypt::Perl::ECDSA>.
47  
48 =cut
49  
50 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53 6 ▶use parent qw( Crypt::Perl::ECDSA::KeyBase );
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 6 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
56  
57 6 ▶use Crypt::Perl::BigInt ();
Subroutine BEGIN: called CC=1 SCAR=0.0
58 6 ▶use Crypt::Perl::ECDSA::ECParameters ();
Subroutine BEGIN: called CC=1 SCAR=0.0
59  
60 6 use constant ASN1_PUBLIC => Crypt::Perl::ECDSA::KeyBase->ASN1_Params() . q<
61  
62 -- FG: For some reason just plain “AlgorithmIdentifier”
63 -- causes the parser not to decode parameters.namedCurve.
64 FG_AlgorithmIdentifier ::= SEQUENCE {
65 algorithm OBJECT IDENTIFIER,
66 parameters EcpkParameters
67 }
68  
69 ECPublicKey ::= SEQUENCE {
70 keydata FG_AlgorithmIdentifier,
71 publicKey BIT STRING
72 }
73 6 ▶>;
Subroutine BEGIN: called CC=1 SCAR=0.0
74  
75 6 ▶use constant _PEM_HEADER => 'EC PUBLIC KEY';
Subroutine BEGIN: called CC=1 SCAR=0.0
76  
77 #There’s no new_by_curve_name() method here because
78 #that logic in PrivateKey is only really useful for when we
79 #generate keys.
80  
81 sub new {
82 29 ▶ my ($class, $public, $curve_parts) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
83  
84 29 my $self = bless {}, $class;
85  
86 29 $self->_set_public($public);
87  
88 29 return $self->_add_params( $curve_parts );
89 }
90  
91 sub algorithm_identifier_with_curve_name {
92 0 ▶ my ($self) = @_;
Subroutine algorithm_identifier_with_curve_name: not called CC=1 SCAR=6.9
Pod undocumented
93  
94 0 return $self->_algorithm_identifier($self->_named_curve_parameters());
95 }
96  
97 sub _algorithm_identifier {
98 24 ▶ my ($self, $curve_parts) = @_;
Subroutine _algorithm_identifier: called CC=1 SCAR=0.0
99  
100 return {
101 24 algorithm => Crypt::Perl::ECDSA::ECParameters::OID_ecPublicKey(),
102 parameters => $curve_parts,
103 };
104 }
105  
106 sub _get_asn1_parts {
107 24 ▶ my ($self, $curve_parts, @params) = @_;
Subroutine _get_asn1_parts: called CC=1 SCAR=0.0
108  
109 24 return $self->__to_der(
110 'ECPublicKey',
111 ASN1_PUBLIC(),
112 {
113 keydata => $self->_algorithm_identifier($curve_parts),
114 },
115 @params,
116 );
117 }
118  
119 6 1;
« lib/Crypt/Perl/X509/Extension/ct_precert_scts.pm ↑ Summary lib/Crypt/Perl/PKCS8.pm »