1# 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
7import abc
8from enum import Enum
9
10import six
11
12from cryptography import utils
13
14
15def load_pem_private_key(data, password, backend):
16    return backend.load_pem_private_key(data, password)
17
18
19def load_pem_public_key(data, backend):
20    return backend.load_pem_public_key(data)
21
22
23def load_pem_parameters(data, backend):
24    return backend.load_pem_parameters(data)
25
26
27def load_der_private_key(data, password, backend):
28    return backend.load_der_private_key(data, password)
29
30
31def load_der_public_key(data, backend):
32    return backend.load_der_public_key(data)
33
34
35def load_der_parameters(data, backend):
36    return backend.load_der_parameters(data)
37
38
39class Encoding(Enum):
40    PEM = "PEM"
41    DER = "DER"
42    OpenSSH = "OpenSSH"
43    Raw = "Raw"
44    X962 = "ANSI X9.62"
45
46
47class PrivateFormat(Enum):
48    PKCS8 = "PKCS8"
49    TraditionalOpenSSL = "TraditionalOpenSSL"
50    Raw = "Raw"
51
52
53class PublicFormat(Enum):
54    SubjectPublicKeyInfo = "X.509 subjectPublicKeyInfo with PKCS#1"
55    PKCS1 = "Raw PKCS#1"
56    OpenSSH = "OpenSSH"
57    Raw = "Raw"
58    CompressedPoint = "X9.62 Compressed Point"
59    UncompressedPoint = "X9.62 Uncompressed Point"
60
61
62class ParameterFormat(Enum):
63    PKCS3 = "PKCS3"
64
65
66@six.add_metaclass(abc.ABCMeta)
67class KeySerializationEncryption(object):
68    pass
69
70
71@utils.register_interface(KeySerializationEncryption)
72class BestAvailableEncryption(object):
73    def __init__(self, password):
74        if not isinstance(password, bytes) or len(password) == 0:
75            raise ValueError("Password must be 1 or more bytes.")
76
77        self.password = password
78
79
80@utils.register_interface(KeySerializationEncryption)
81class NoEncryption(object):
82    pass
83