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, version 3 of the License.
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.
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 """:rfc:`5280` related structures (**NOT COMPLETE**)
18 They are taken from `PyDERASN <http://pyderasn.cypherpunks.ru/`__ tests.
21 from pyderasn import Any
22 from pyderasn import BitString
23 from pyderasn import Boolean
24 from pyderasn import Choice
25 from pyderasn import GeneralizedTime
26 from pyderasn import Integer
27 from pyderasn import ObjectIdentifier
28 from pyderasn import OctetString
29 from pyderasn import PrintableString
30 from pyderasn import Sequence
31 from pyderasn import SequenceOf
32 from pyderasn import SetOf
33 from pyderasn import tag_ctxc
34 from pyderasn import tag_ctxp
35 from pyderasn import TeletexString
36 from pyderasn import UTCTime
39 class Version(Integer):
47 class CertificateSerialNumber(Integer):
51 class AlgorithmIdentifier(Sequence):
53 ("algorithm", ObjectIdentifier()),
54 ("parameters", Any(optional=True)),
58 class AttributeType(ObjectIdentifier):
62 class AttributeValue(Any):
66 class OrganizationName(Choice):
68 ("printableString", PrintableString()),
69 ("teletexString", TeletexString()),
73 class AttributeTypeAndValue(Sequence):
75 ("type", AttributeType(defines=(((".", "value"), {
76 ObjectIdentifier("2.5.4.6"): PrintableString(),
77 ObjectIdentifier("2.5.4.8"): PrintableString(),
78 ObjectIdentifier("2.5.4.7"): PrintableString(),
79 ObjectIdentifier("2.5.4.10"): OrganizationName(),
80 ObjectIdentifier("2.5.4.3"): PrintableString(),
82 ("value", AttributeValue()),
86 class RelativeDistinguishedName(SetOf):
87 schema = AttributeTypeAndValue()
88 bounds = (1, float("+inf"))
91 class RDNSequence(SequenceOf):
92 schema = RelativeDistinguishedName()
97 ("rdnSequence", RDNSequence()),
103 ("utcTime", UTCTime()),
104 ("generalTime", GeneralizedTime()),
108 class Validity(Sequence):
110 ("notBefore", Time()),
111 ("notAfter", Time()),
115 class SubjectPublicKeyInfo(Sequence):
117 ("algorithm", AlgorithmIdentifier()),
118 ("subjectPublicKey", BitString()),
122 class UniqueIdentifier(BitString):
126 class Extension(Sequence):
128 ("extnID", ObjectIdentifier()),
129 ("critical", Boolean(default=False)),
130 ("extnValue", OctetString()),
134 class Extensions(SequenceOf):
136 bounds = (1, float("+inf"))
139 class TBSCertificate(Sequence):
141 ("version", Version(expl=tag_ctxc(0), default="v1")),
142 ("serialNumber", CertificateSerialNumber()),
143 ("signature", AlgorithmIdentifier()),
145 ("validity", Validity()),
147 ("subjectPublicKeyInfo", SubjectPublicKeyInfo()),
148 ("issuerUniqueID", UniqueIdentifier(impl=tag_ctxp(1), optional=True)),
149 ("subjectUniqueID", UniqueIdentifier(impl=tag_ctxp(2), optional=True)),
150 ("extensions", Extensions(expl=tag_ctxc(3), optional=True)),
154 class Certificate(Sequence):
156 ("tbsCertificate", TBSCertificate()),
157 ("signatureAlgorithm", AlgorithmIdentifier()),
158 ("signatureValue", BitString()),