]> Cypherpunks.ru repositories - pygost.git/blob - pygost/asn1schemas/prvkey.py
6b9c493418eb27d2426192b83cdf0ccaaebb3bfd
[pygost.git] / pygost / asn1schemas / prvkey.py
1 # coding: utf-8
2 # PyGOST -- Pure Python GOST cryptographic functions library
3 # Copyright (C) 2015-2021 Sergey Matveev <stargrave@stargrave.org>
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, version 3 of the License.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 from pyderasn import Any
18 from pyderasn import BitString
19 from pyderasn import Choice
20 from pyderasn import Integer
21 from pyderasn import Null
22 from pyderasn import ObjectIdentifier
23 from pyderasn import OctetString
24 from pyderasn import Sequence
25 from pyderasn import tag_ctxc
26 from pyderasn import tag_ctxp
27 from pyderasn import SetOf
28
29 from pygost.asn1schemas.oids import id_tc26_gost3410_2012_256
30 from pygost.asn1schemas.oids import id_tc26_gost3410_2012_512
31 from pygost.asn1schemas.x509 import GostR34102012PublicKeyParameters
32
33
34 class ECParameters(Choice):
35     schema = (
36         ("namedCurve", ObjectIdentifier()),
37         ("implicitCurve", Null()),
38         # ("specifiedCurve", SpecifiedECDomain()),
39     )
40
41
42 ecPrivkeyVer1 = Integer(1)
43
44
45 class ECPrivateKey(Sequence):
46     schema = (
47         ("version", Integer(ecPrivkeyVer1)),
48         ("privateKey", OctetString()),
49         ("parameters", ECParameters(expl=tag_ctxc(0), optional=True)),
50         ("publicKey", BitString(expl=tag_ctxc(1), optional=True)),
51     )
52
53
54 class PrivateKeyAlgorithmIdentifier(Sequence):
55     schema = (
56         ("algorithm", ObjectIdentifier(defines=(
57             (("parameters",), {
58                 id_tc26_gost3410_2012_256: GostR34102012PublicKeyParameters(),
59                 id_tc26_gost3410_2012_512: GostR34102012PublicKeyParameters(),
60             }),
61         ))),
62         ("parameters", Any(optional=True)),
63     )
64
65
66 class PrivateKey(OctetString):
67     pass
68
69
70 class AttributeValue(Any):
71     pass
72
73
74 class AttributeValues(SetOf):
75     schema = AttributeValue()
76
77
78 class Attribute(Sequence):
79     schema = (
80         ("attrType", ObjectIdentifier()),
81         ("attrValues", AttributeValues()),
82     )
83
84
85 class Attributes(SetOf):
86     schema = Attribute()
87
88
89 class PublicKey(BitString):
90     pass
91
92
93 class PrivateKeyInfo(Sequence):
94     schema = (
95         ("version", Integer(0)),
96         ("privateKeyAlgorithm", PrivateKeyAlgorithmIdentifier()),
97         ("privateKey", PrivateKey()),
98         ("attributes", Attributes(impl=tag_ctxc(0), optional=True)),
99         ("publicKey", PublicKey(impl=tag_ctxp(1), optional=True)),
100     )