]> Cypherpunks.ru repositories - pygost.git/blob - pygost/asn1schemas/prvkey.py
67e6fb1b3852d00a7123617fb3061a87b4593a04
[pygost.git] / pygost / asn1schemas / prvkey.py
1 # coding: utf-8
2 # PyGOST -- Pure Python GOST cryptographic functions library
3 # Copyright (C) 2015-2020 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
27 from pygost.asn1schemas.oids import id_tc26_gost3410_2012_256
28 from pygost.asn1schemas.oids import id_tc26_gost3410_2012_512
29 from pygost.asn1schemas.x509 import GostR34102012PublicKeyParameters
30
31
32 class ECParameters(Choice):
33     schema = (
34         ("namedCurve", ObjectIdentifier()),
35         ("implicitCurve", Null()),
36         # ("specifiedCurve", SpecifiedECDomain()),
37     )
38
39
40 ecPrivkeyVer1 = Integer(1)
41
42
43 class ECPrivateKey(Sequence):
44     schema = (
45         ("version", Integer(ecPrivkeyVer1)),
46         ("privateKey", OctetString()),
47         ("parameters", ECParameters(expl=tag_ctxc(0), optional=True)),
48         ("publicKey", BitString(expl=tag_ctxc(1), optional=True)),
49     )
50
51
52 class PrivateKeyAlgorithmIdentifier(Sequence):
53     schema = (
54         ("algorithm", ObjectIdentifier(defines=(
55             (("parameters",), {
56                 id_tc26_gost3410_2012_256: GostR34102012PublicKeyParameters(),
57                 id_tc26_gost3410_2012_512: GostR34102012PublicKeyParameters(),
58             }),
59         ))),
60         ("parameters", Any(optional=True)),
61     )
62
63
64 class PrivateKey(OctetString):
65     pass
66
67
68 class PrivateKeyInfo(Sequence):
69     schema = (
70         ("version", Integer(0)),
71         ("privateKeyAlgorithm", PrivateKeyAlgorithmIdentifier()),
72         ("privateKey", PrivateKey()),
73     )