File: x509_common.py

package info (click to toggle)
golang-github-google-certificate-transparency 0.0~git20160709.0.0f6e3d1~ds1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 5,676 kB
  • sloc: cpp: 35,278; python: 11,838; java: 1,911; sh: 1,885; makefile: 950; xml: 520; ansic: 225
file content (41 lines) | stat: -rw-r--r-- 1,023 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""ASN.1 X509 base components."""

from ct.crypto.asn1 import oid
from ct.crypto.asn1 import print_util
from ct.crypto.asn1 import types


class Version(types.Integer):
    def _encode_value(self):
        return types.encode_int(self._value - 1)

    @classmethod
    def _convert_value(cls, value):
        return int(value) + 1

    @classmethod
    def _decode_value(cls, buf, strict=True):
        return types.decode_int(buf, strict=strict) + 1


class CertificateSerialNumber(types.Integer):
    def __str__(self):
        return print_util.int_to_hex(int(self))


class AlgorithmIdentifier(types.Sequence):
    components = (
        (types.Component("algorithm", oid.ObjectIdentifier)),
        (types.Component("parameters", types.Any, optional=True))
        )


class UniqueIdentifier(types.BitString):
    pass


class SubjectPublicKeyInfo(types.Sequence):
    components = (
        (types.Component("algorithm", AlgorithmIdentifier)),
        (types.Component("subjectPublicKey", types.BitString))
        )