blob: be1298b67eece0eb33498378befb657a9b7138f8 [file] [log] [blame]
Paul Kehrer016e08a2014-11-26 09:41:18 -10001# This file is dual licensed under the terms of the Apache License, Version
2# 2.0, and the BSD License. See the LICENSE file in the root of this repository
3# for complete details.
4
5from __future__ import absolute_import, division, print_function
6
Paul Kehrerb2de9482014-12-11 14:54:48 -06007import abc
Paul Kehrer016e08a2014-11-26 09:41:18 -10008from enum import Enum
9
Paul Kehrerb2de9482014-12-11 14:54:48 -060010import six
11
Paul Kehrer016e08a2014-11-26 09:41:18 -100012
Paul Kehrere76cd272014-12-14 19:00:51 -060013class Version(Enum):
Paul Kehrer016e08a2014-11-26 09:41:18 -100014 v1 = 0
15 v3 = 2
16
17
Paul Kehrer016e08a2014-11-26 09:41:18 -100018def load_pem_x509_certificate(data, backend):
19 return backend.load_pem_x509_certificate(data)
20
21
Paul Kehrer016e08a2014-11-26 09:41:18 -100022def load_der_x509_certificate(data, backend):
23 return backend.load_der_x509_certificate(data)
Paul Kehrera68fd332014-11-27 07:08:40 -100024
25
Paul Kehrere76cd272014-12-14 19:00:51 -060026class InvalidVersion(Exception):
Paul Kehrerd5cccf72014-12-15 17:20:33 -060027 def __init__(self, msg, parsed_version):
28 super(InvalidVersion, self).__init__(msg)
29 self.parsed_version = parsed_version
Paul Kehrerb2de9482014-12-11 14:54:48 -060030
31
32@six.add_metaclass(abc.ABCMeta)
Paul Kehrere76cd272014-12-14 19:00:51 -060033class Certificate(object):
Paul Kehrerb2de9482014-12-11 14:54:48 -060034 @abc.abstractmethod
35 def fingerprint(self, algorithm):
36 """
37 Returns bytes using digest passed.
38 """
39
40 @abc.abstractproperty
41 def serial(self):
42 """
43 Returns certificate serial number
44 """
45
46 @abc.abstractproperty
47 def version(self):
48 """
49 Returns the certificate version
50 """
51
52 @abc.abstractmethod
53 def public_key(self):
54 """
55 Returns the public key
56 """
57
58 @abc.abstractproperty
59 def not_valid_before(self):
60 """
61 Not before time (represented as UTC datetime)
62 """
63
64 @abc.abstractproperty
65 def not_valid_after(self):
66 """
67 Not after time (represented as UTC datetime)
68 """