forked from aws/aws-dynamodb-encryption-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
128 lines (98 loc) · 4.03 KB
/
__init__.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""Cryptographic materials are containers that provide delegated keys for cryptographic operations."""
import abc
import six
from dynamodb_encryption_sdk.delegated_keys import DelegatedKey # noqa pylint: disable=unused-import
try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
from typing import Dict, Text # noqa pylint: disable=unused-import
from mypy_extensions import NoReturn # noqa pylint: disable=unused-import
except ImportError: # pragma: no cover
# We only actually need these imports when running the mypy checks
pass
__all__ = ("CryptographicMaterials", "EncryptionMaterials", "DecryptionMaterials")
@six.add_metaclass(abc.ABCMeta)
class CryptographicMaterials(object):
"""Base class for all cryptographic materials."""
@property
@abc.abstractmethod
def material_description(self):
# type: () -> Dict[Text, Text]
"""Material description to use with these cryptographic materials.
:returns: Material description
:rtype: dict
"""
@property
@abc.abstractmethod
def encryption_key(self):
# type: () -> DelegatedKey
"""Delegated key used for encrypting attributes.
:returns: Encryption key
:rtype: DelegatedKey
"""
@property
@abc.abstractmethod
def decryption_key(self):
# type: () -> DelegatedKey
"""Delegated key used for decrypting attributes.
:returns: Decryption key
:rtype: DelegatedKey
"""
@property
@abc.abstractmethod
def signing_key(self):
# type: () -> DelegatedKey
"""Delegated key used for calculating digital signatures.
:returns: Signing key
:rtype: DelegatedKey
"""
@property
@abc.abstractmethod
def verification_key(self):
# type: () -> DelegatedKey
"""Delegated key used for verifying digital signatures.
:returns: Verification key
:rtype: DelegatedKey
"""
class EncryptionMaterials(CryptographicMaterials):
"""Base class for all encryption materials."""
@property
def decryption_key(self):
# type: () -> NoReturn
"""Encryption materials do not provide decryption keys.
:raises NotImplementedError: because encryption materials do not contain decryption keys
"""
raise NotImplementedError("Encryption materials do not provide decryption keys.")
@property
def verification_key(self):
# type: () -> NoReturn
"""Encryption materials do not provide verification keys.
:raises NotImplementedError: because encryption materials do not contain verification keys
"""
raise NotImplementedError("Encryption materials do not provide verification keys.")
class DecryptionMaterials(CryptographicMaterials):
"""Base class for all decryption materials."""
@property
def encryption_key(self):
# type: () -> NoReturn
"""Decryption materials do not provide encryption keys.
:raises NotImplementedError: because decryption materials do not contain encryption keys
"""
raise NotImplementedError("Decryption materials do not provide encryption keys.")
@property
def signing_key(self):
# type: () -> NoReturn
"""Decryption materials do not provide signing keys.
:raises NotImplementedError: because decryption materials do not contain signing keys
"""
raise NotImplementedError("Decryption materials do not provide signing keys.")