blib/lib/Crypt/Perl/PKCS8.pm untested

filter: Statementstmt 0.0% 0 / 17 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 27 CC 1 SCAR 6.9
CC
1
Cov
0%
parse_private
2.0
parse_public
2.0
_asn1
2.0
CRAP 2.0
1 package Crypt::Perl::PKCS8;
2  
3 #TODO: Rename this, and split up the public/private as appropriate.
4  
5 use strict;
6 use warnings;
7  
8 use Crypt::Perl::ASN1 ();
9  
10 use constant ASN1 => <<END;
11 -- FG: simplified from RFC for Convert::ASN1
12 Version ::= INTEGER
13  
14 -- cf. RFC 3280 4.1.1.2
15 AlgorithmIdentifier ::= SEQUENCE {
16 algorithm OBJECT IDENTIFIER,
17 parameters ANY DEFINED BY algorithm OPTIONAL
18 }
19  
20 -- cf. RFC 5208 appendix A
21 PrivateKeyInfo ::= SEQUENCE {
22 version Version,
23 privateKeyAlgorithm AlgorithmIdentifier,
24 privateKey PrivateKey
25 }
26  
27 PrivateKey ::= OCTET STRING
28  
29 -- cf. RFC 3280 4.1
30 SubjectPublicKeyInfo ::= SEQUENCE {
31 algorithm AlgorithmIdentifier,
32 subjectPublicKey BIT STRING
33 }
34 END
35  
36 sub parse_private {
37 my ($pem_or_der) = @_;
38  
39 return _asn1()->find('PrivateKeyInfo')->decode($pem_or_der);
40 }
41  
42 sub parse_public {
43 my ($pem_or_der) = @_;
44  
45 return _asn1()->find('SubjectPublicKeyInfo')->decode($pem_or_der);
46 }
47  
48 sub _asn1 {
49 return Crypt::Perl::ASN1->new()->prepare( Crypt::Perl::PKCS8::ASN1() );
50 }
51  
52 1;