line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::Perl::PKCS8; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#TODO: Rename this, and split up the public/private as appropriate. |
4
|
|
|
|
|
|
|
|
5
|
11
|
|
|
11
|
|
59
|
use strict; |
|
11
|
|
|
|
|
19
|
|
|
11
|
|
|
|
|
342
|
|
6
|
11
|
|
|
11
|
|
50
|
use warnings; |
|
11
|
|
|
|
|
18
|
|
|
11
|
|
|
|
|
211
|
|
7
|
|
|
|
|
|
|
|
8
|
11
|
|
|
11
|
|
332
|
use Crypt::Perl::ASN1 (); |
|
11
|
|
|
|
|
23
|
|
|
11
|
|
|
|
|
394
|
|
9
|
|
|
|
|
|
|
|
10
|
11
|
|
|
11
|
|
55
|
use constant ASN1 => <
|
|
11
|
|
|
|
|
20
|
|
|
11
|
|
|
|
|
1824
|
|
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
|
10
|
|
|
10
|
0
|
26
|
my ($pem_or_der) = @_; |
38
|
|
|
|
|
|
|
|
39
|
10
|
|
|
|
|
1149
|
return _asn1()->find('PrivateKeyInfo')->decode($pem_or_der); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub parse_public { |
43
|
9
|
|
|
9
|
0
|
27
|
my ($pem_or_der) = @_; |
44
|
|
|
|
|
|
|
|
45
|
9
|
|
|
|
|
28
|
return _asn1()->find('SubjectPublicKeyInfo')->decode($pem_or_der); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _asn1 { |
49
|
19
|
|
|
19
|
|
84
|
return Crypt::Perl::ASN1->new()->prepare( Crypt::Perl::PKCS8::ASN1() ); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |