2 # PyGOST -- Pure Python GOST cryptographic functions library
3 # Copyright (C) 2015-2019 Sergey Matveev <stargrave@stargrave.org>
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, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 """:rfc:`5280` related structures (**NOT COMPLETE**)
19 They are taken from `PyDERASN <http://pyderasn.cypherpunks.ru/`__ tests.
22 from pyderasn import Any
23 from pyderasn import BitString
24 from pyderasn import Boolean
25 from pyderasn import Choice
26 from pyderasn import GeneralizedTime
27 from pyderasn import Integer
28 from pyderasn import ObjectIdentifier
29 from pyderasn import OctetString
30 from pyderasn import PrintableString
31 from pyderasn import Sequence
32 from pyderasn import SequenceOf
33 from pyderasn import SetOf
34 from pyderasn import tag_ctxc
35 from pyderasn import tag_ctxp
36 from pyderasn import TeletexString
37 from pyderasn import UTCTime
40 class Version(Integer):
48 class CertificateSerialNumber(Integer):
52 class AlgorithmIdentifier(Sequence):
54 ("algorithm", ObjectIdentifier()),
55 ("parameters", Any(optional=True)),
59 class AttributeType(ObjectIdentifier):
63 class AttributeValue(Any):
67 class OrganizationName(Choice):
69 ("printableString", PrintableString()),
70 ("teletexString", TeletexString()),
74 class AttributeTypeAndValue(Sequence):
76 ("type", AttributeType(defines=(((".", "value"), {
77 ObjectIdentifier("2.5.4.6"): PrintableString(),
78 ObjectIdentifier("2.5.4.8"): PrintableString(),
79 ObjectIdentifier("2.5.4.7"): PrintableString(),
80 ObjectIdentifier("2.5.4.10"): OrganizationName(),
81 ObjectIdentifier("2.5.4.3"): PrintableString(),
83 ("value", AttributeValue()),
87 class RelativeDistinguishedName(SetOf):
88 schema = AttributeTypeAndValue()
89 bounds = (1, float("+inf"))
92 class RDNSequence(SequenceOf):
93 schema = RelativeDistinguishedName()
98 ("rdnSequence", RDNSequence()),
104 ("utcTime", UTCTime()),
105 ("generalTime", GeneralizedTime()),
109 class Validity(Sequence):
111 ("notBefore", Time()),
112 ("notAfter", Time()),
116 class SubjectPublicKeyInfo(Sequence):
118 ("algorithm", AlgorithmIdentifier()),
119 ("subjectPublicKey", BitString()),
123 class UniqueIdentifier(BitString):
127 class Extension(Sequence):
129 ("extnID", ObjectIdentifier()),
130 ("critical", Boolean(default=False)),
131 ("extnValue", OctetString()),
135 class Extensions(SequenceOf):
137 bounds = (1, float("+inf"))
140 class TBSCertificate(Sequence):
142 ("version", Version(expl=tag_ctxc(0), default="v1")),
143 ("serialNumber", CertificateSerialNumber()),
144 ("signature", AlgorithmIdentifier()),
146 ("validity", Validity()),
148 ("subjectPublicKeyInfo", SubjectPublicKeyInfo()),
149 ("issuerUniqueID", UniqueIdentifier(impl=tag_ctxp(1), optional=True)),
150 ("subjectUniqueID", UniqueIdentifier(impl=tag_ctxp(2), optional=True)),
151 ("extensions", Extensions(expl=tag_ctxc(3), optional=True)),
155 class Certificate(Sequence):
157 ("tbsCertificate", TBSCertificate()),
158 ("signatureAlgorithm", AlgorithmIdentifier()),
159 ("signatureValue", BitString()),