blob: c79d11716d9c19c049cef6f309c4d09a6656e4df [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 Kehrera68fd332014-11-27 07:08:40 -100027 pass
Paul Kehrerb2de9482014-12-11 14:54:48 -060028
29
30@six.add_metaclass(abc.ABCMeta)
Paul Kehrere76cd272014-12-14 19:00:51 -060031class Certificate(object):
Paul Kehrerb2de9482014-12-11 14:54:48 -060032 @abc.abstractmethod
33 def fingerprint(self, algorithm):
34 """
35 Returns bytes using digest passed.
36 """
37
38 @abc.abstractproperty
39 def serial(self):
40 """
41 Returns certificate serial number
42 """
43
44 @abc.abstractproperty
45 def version(self):
46 """
47 Returns the certificate version
48 """
49
50 @abc.abstractmethod
51 def public_key(self):
52 """
53 Returns the public key
54 """
55
56 @abc.abstractproperty
57 def not_valid_before(self):
58 """
59 Not before time (represented as UTC datetime)
60 """
61
62 @abc.abstractproperty
63 def not_valid_after(self):
64 """
65 Not after time (represented as UTC datetime)
66 """