1#
2# This file is part of pyasn1-modules software.
3#
4# Copyright (c) 2005-2017, Ilya Etingof <etingof@gmail.com>
5# License: http://pyasn1.sf.net/license.html
6#
7# PKCS#8 syntax
8#
9# ASN.1 source from:
10# http://tools.ietf.org/html/rfc5208
11#
12# Sample captures could be obtained with "openssl pkcs8 -topk8" command
13#
14from pyasn1_modules import rfc2251
15from pyasn1_modules.rfc2459 import *
16
17
18class KeyEncryptionAlgorithms(AlgorithmIdentifier):
19    pass
20
21
22class PrivateKeyAlgorithms(AlgorithmIdentifier):
23    pass
24
25
26class EncryptedData(univ.OctetString):
27    pass
28
29
30class EncryptedPrivateKeyInfo(univ.Sequence):
31    componentType = namedtype.NamedTypes(
32        namedtype.NamedType('encryptionAlgorithm', AlgorithmIdentifier()),
33        namedtype.NamedType('encryptedData', EncryptedData())
34    )
35
36
37class PrivateKey(univ.OctetString):
38    pass
39
40
41class Attributes(univ.SetOf):
42    componentType = rfc2251.Attribute()
43
44
45class Version(univ.Integer):
46    namedValues = namedval.NamedValues(('v1', 0), ('v2', 1))
47
48
49class PrivateKeyInfo(univ.Sequence):
50    componentType = namedtype.NamedTypes(
51        namedtype.NamedType('version', Version()),
52        namedtype.NamedType('privateKeyAlgorithm', AlgorithmIdentifier()),
53        namedtype.NamedType('privateKey', PrivateKey()),
54        namedtype.OptionalNamedType('attributes', Attributes().subtype(
55            implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0)))
56    )
57