|
| 1 | +# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"). You |
| 4 | +# may not use this file except in compliance with the License. A copy of |
| 5 | +# the License is located at |
| 6 | +# |
| 7 | +# http://aws.amazon.com/apache2.0/ |
| 8 | +# |
| 9 | +# or in the "license" file accompanying this file. This file is |
| 10 | +# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 11 | +# ANY KIND, either express or implied. See the License for the specific |
| 12 | +# language governing permissions and limitations under the License. |
| 13 | +"""Base class interface for Keyrings.""" |
| 14 | +from aws_encryption_sdk.materials_managers import DecryptionMaterials, EncryptionMaterials |
| 15 | +from aws_encryption_sdk.structures import EncryptedDataKey |
| 16 | + |
| 17 | +try: # Python 3.5.0 and 3.5.1 have incompatible typing modules |
| 18 | + from typing import Iterable # noqa pylint: disable=unused-import |
| 19 | +except ImportError: # pragma: no cover |
| 20 | + # We only actually need these imports when running the mypy checks |
| 21 | + pass |
| 22 | + |
| 23 | + |
| 24 | +class Keyring(object): |
| 25 | + """Parent interface for Keyring classes. |
| 26 | +
|
| 27 | + .. versionadded:: 1.5.0 |
| 28 | + """ |
| 29 | + |
| 30 | + def on_encrypt(self, encryption_materials): |
| 31 | + # type: (EncryptionMaterials) -> EncryptionMaterials |
| 32 | + """Generate a data key if not present and encrypt it using any available wrapping key. |
| 33 | +
|
| 34 | + :param encryption_materials: Encryption materials for the keyring to modify. |
| 35 | + :type encryption_materials: aws_encryption_sdk.materials_managers.EncryptionMaterials |
| 36 | + :returns: Optionally modified encryption materials. |
| 37 | + :rtype: aws_encryption_sdk.materials_managers.EncryptionMaterials |
| 38 | + :raises NotImplementedError: if method is not implemented |
| 39 | + """ |
| 40 | + raise NotImplementedError("Keyring does not implement on_encrypt function") |
| 41 | + |
| 42 | + def on_decrypt(self, decryption_materials, encrypted_data_keys): |
| 43 | + # type: (DecryptionMaterials, Iterable[EncryptedDataKey]) -> DecryptionMaterials |
| 44 | + """Attempt to decrypt the encrypted data keys. |
| 45 | +
|
| 46 | + :param decryption_materials: Decryption materials for the keyring to modify. |
| 47 | + :type decryption_materials: aws_encryption_sdk.materials_managers.DecryptionMaterials |
| 48 | + :param encrypted_data_keys: List of encrypted data keys. |
| 49 | + :type: Iterable of :class:`aws_encryption_sdk.structures.EncryptedDataKey` |
| 50 | + :returns: Optionally modified decryption materials. |
| 51 | + :rtype: aws_encryption_sdk.materials_managers.DecryptionMaterials |
| 52 | + :raises NotImplementedError: if method is not implemented |
| 53 | + """ |
| 54 | + raise NotImplementedError("Keyring does not implement on_decrypt function") |
0 commit comments