Skip to content

Keyring reorg #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""Base class interface for Keyrings."""
from aws_encryption_sdk.materials_managers import ( # only used for mypy; pylint: disable=unused-import,duplicate-code
from aws_encryption_sdk.materials_managers import ( # only used for mypy; pylint: disable=unused-import
DecryptionMaterials,
EncryptionMaterials,
)
from aws_encryption_sdk.structures import ( # only used for mypy; pylint: disable=unused-import,duplicate-code
EncryptedDataKey,
)
from aws_encryption_sdk.structures import EncryptedDataKey # only used for mypy; pylint: disable=unused-import

try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
from typing import Iterable # noqa pylint: disable=unused-import
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
from attr.validators import deep_iterable, instance_of, optional

from aws_encryption_sdk.exceptions import EncryptKeyError, GenerateKeyError
from aws_encryption_sdk.keyring.base import DecryptionMaterials # only used for mypy so pylint: disable=unused-import
from aws_encryption_sdk.keyring.base import EncryptionMaterials # only used for mypy so pylint: disable=unused-import
from aws_encryption_sdk.keyring.base import Keyring
from aws_encryption_sdk.structures import EncryptedDataKey # only used for mypy so pylint: disable=unused-import
from aws_encryption_sdk.keyrings.base import Keyring

from aws_encryption_sdk.materials_managers import ( # only used for mypy; pylint: disable=unused-import
DecryptionMaterials,
EncryptionMaterials,
)
from aws_encryption_sdk.structures import EncryptedDataKey # only used for mypy; pylint: disable=unused-import

try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
from typing import Iterable # noqa pylint: disable=unused-import
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""Resources required for Raw Keyrings."""

import logging
import os

Expand All @@ -28,13 +27,18 @@
from aws_encryption_sdk.internal.formatting.deserialize import deserialize_wrapped_key
from aws_encryption_sdk.internal.formatting.serialize import serialize_raw_master_key_prefix, serialize_wrapped_key
from aws_encryption_sdk.key_providers.raw import RawMasterKey
from aws_encryption_sdk.keyring.base import Keyring
from aws_encryption_sdk.materials_managers import ( # only used for mypy so pylint: disable=unused-import
from aws_encryption_sdk.keyrings.base import Keyring
from aws_encryption_sdk.structures import ( # pylint: disable=unused-import
EncryptedDataKey,
KeyringTrace,
MasterKeyInfo,
RawDataKey,
)

from aws_encryption_sdk.materials_managers import ( # only used for mypy; pylint: disable=unused-import
DecryptionMaterials,
EncryptionMaterials,
)
from aws_encryption_sdk.structures import EncryptedDataKey # only used for mypy so pylint: disable=unused-import
from aws_encryption_sdk.structures import KeyringTrace, MasterKeyInfo, RawDataKey

try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
from typing import Iterable # noqa pylint: disable=unused-import
Expand Down
3 changes: 3 additions & 0 deletions src/pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ additional-builtins = raw_input
[DESIGN]
max-args = 10

[SIMILARITIES]
ignore-imports = yes

[FORMAT]
max-line-length = 120

Expand Down
Empty file added test/__init__.py
Empty file.
13 changes: 13 additions & 0 deletions test/functional/keyrings/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2019 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.
"""Dummy stub to make linters work better."""
13 changes: 13 additions & 0 deletions test/functional/keyrings/raw/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2019 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.
"""Dummy stub to make linters work better."""
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from aws_encryption_sdk.internal.crypto import WrappingKey
from aws_encryption_sdk.internal.formatting.serialize import serialize_raw_master_key_prefix
from aws_encryption_sdk.key_providers.raw import RawMasterKey
from aws_encryption_sdk.keyring.raw_keyring import RawAESKeyring
from aws_encryption_sdk.keyrings.raw import RawAESKeyring
from aws_encryption_sdk.materials_managers import DecryptionMaterials, EncryptionMaterials
from aws_encryption_sdk.structures import KeyringTrace, MasterKeyInfo, RawDataKey

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
)
from aws_encryption_sdk.internal.crypto import WrappingKey
from aws_encryption_sdk.key_providers.raw import RawMasterKey
from aws_encryption_sdk.keyring.raw_keyring import RawRSAKeyring
from aws_encryption_sdk.keyrings.raw import RawRSAKeyring
from aws_encryption_sdk.materials_managers import DecryptionMaterials, EncryptionMaterials
from aws_encryption_sdk.structures import KeyringTrace, MasterKeyInfo, RawDataKey

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

from aws_encryption_sdk.identifiers import KeyringTraceFlag, WrappingAlgorithm
from aws_encryption_sdk.internal.defaults import ALGORITHM
from aws_encryption_sdk.keyring.multi_keyring import MultiKeyring
from aws_encryption_sdk.keyring.raw_keyring import RawAESKeyring, RawRSAKeyring
from aws_encryption_sdk.keyrings.multi import MultiKeyring
from aws_encryption_sdk.keyrings.raw import RawAESKeyring, RawRSAKeyring
from aws_encryption_sdk.materials_managers import DecryptionMaterials, EncryptionMaterials
from aws_encryption_sdk.structures import KeyringTrace, MasterKeyInfo, RawDataKey

Expand Down
13 changes: 13 additions & 0 deletions test/unit/keyrings/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2019 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.
"""Dummy stub to make linters work better."""
13 changes: 13 additions & 0 deletions test/unit/keyrings/raw/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2019 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.
"""Dummy stub to make linters work better."""
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
from pytest_mock import mocker # noqa pylint: disable=unused-import

import aws_encryption_sdk.key_providers.raw
import aws_encryption_sdk.keyring.raw_keyring
import aws_encryption_sdk.keyrings.raw
from aws_encryption_sdk.identifiers import Algorithm, KeyringTraceFlag, WrappingAlgorithm
from aws_encryption_sdk.internal.crypto.wrapping_keys import WrappingKey
from aws_encryption_sdk.keyring.base import Keyring
from aws_encryption_sdk.keyring.raw_keyring import GenerateKeyError, RawAESKeyring, _generate_data_key
from aws_encryption_sdk.keyrings.base import Keyring
from aws_encryption_sdk.keyrings.raw import GenerateKeyError, RawAESKeyring, _generate_data_key
from aws_encryption_sdk.materials_managers import EncryptionMaterials
from aws_encryption_sdk.structures import MasterKeyInfo

from .unit_test_utils import (
from ...unit_test_utils import (
_DATA_KEY,
_ENCRYPTED_DATA_KEY_AES,
_ENCRYPTED_DATA_KEY_NOT_IN_KEYRING,
Expand Down Expand Up @@ -57,8 +57,8 @@ def raw_aes_keyring():

@pytest.fixture
def patch_generate_data_key(mocker):
mocker.patch.object(aws_encryption_sdk.keyring.raw_keyring, "_generate_data_key")
return aws_encryption_sdk.keyring.raw_keyring._generate_data_key
mocker.patch.object(aws_encryption_sdk.keyrings.raw, "_generate_data_key")
return aws_encryption_sdk.keyrings.raw._generate_data_key


@pytest.fixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
from pytest_mock import mocker # noqa pylint: disable=unused-import

import aws_encryption_sdk.key_providers.raw
import aws_encryption_sdk.keyring.raw_keyring
import aws_encryption_sdk.keyrings.raw
from aws_encryption_sdk.identifiers import KeyringTraceFlag, WrappingAlgorithm
from aws_encryption_sdk.internal.crypto.wrapping_keys import WrappingKey
from aws_encryption_sdk.keyring.base import Keyring
from aws_encryption_sdk.keyring.raw_keyring import RawRSAKeyring
from aws_encryption_sdk.keyrings.base import Keyring
from aws_encryption_sdk.keyrings.raw import RawRSAKeyring

from .test_values import VALUES
from .unit_test_utils import (
from ...test_values import VALUES
from ...unit_test_utils import (
_BACKEND,
_DATA_KEY,
_ENCRYPTED_DATA_KEY_RSA,
Expand Down Expand Up @@ -58,8 +58,8 @@ def raw_rsa_private_key():

@pytest.fixture
def patch_generate_data_key(mocker):
mocker.patch.object(aws_encryption_sdk.keyring.raw_keyring, "_generate_data_key")
return aws_encryption_sdk.keyring.raw_keyring._generate_data_key
mocker.patch.object(aws_encryption_sdk.keyrings.raw, "_generate_data_key")
return aws_encryption_sdk.keyrings.raw._generate_data_key


@pytest.fixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import pytest

from aws_encryption_sdk.identifiers import Algorithm
from aws_encryption_sdk.keyring.base import Keyring
from aws_encryption_sdk.keyrings.base import Keyring
from aws_encryption_sdk.materials_managers import DecryptionMaterials, EncryptionMaterials

pytestmark = [pytest.mark.unit, pytest.mark.local]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
from aws_encryption_sdk.exceptions import EncryptKeyError, GenerateKeyError
from aws_encryption_sdk.identifiers import WrappingAlgorithm
from aws_encryption_sdk.internal.formatting import serialize
from aws_encryption_sdk.keyring.base import Keyring
from aws_encryption_sdk.keyring.multi_keyring import MultiKeyring
from aws_encryption_sdk.keyring.raw_keyring import RawAESKeyring
from aws_encryption_sdk.keyrings.base import Keyring
from aws_encryption_sdk.keyrings.multi import MultiKeyring
from aws_encryption_sdk.keyrings.raw import RawAESKeyring

from .unit_test_utils import (
from ..unit_test_utils import (
IdentityKeyring,
OnlyGenerateKeyring,
get_decryption_materials_with_data_key,
Expand Down Expand Up @@ -139,10 +139,10 @@ def test_keyring_with_no_generator_no_children():
def test_keyring_with_invalid_parameters(generator, children):
with pytest.raises(TypeError) as exc_info:
MultiKeyring(generator=generator, children=children)
assert exc_info.match("('children'|'generator') must be <class 'aws_encryption_sdk.keyring.base.Keyring'>.*")
assert exc_info.match("('children'|'generator') must be <class 'aws_encryption_sdk.keyrings.base.Keyring'>.*")


def test_decryption_keyrings():
def test_decryption_keyring():
test_multi_keyring = get_multi_keyring_with_generator_and_children()
assert test_multi_keyring.generator in test_multi_keyring._decryption_keyrings
for child_keyring in test_multi_keyring.children:
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import aws_encryption_sdk.internal.utils
from aws_encryption_sdk.exceptions import InvalidDataKeyError, SerializationError, UnknownIdentityError
from aws_encryption_sdk.internal.defaults import MAX_FRAME_SIZE, MESSAGE_ID_LENGTH
from aws_encryption_sdk.keyring.base import EncryptedDataKey
from aws_encryption_sdk.keyrings.base import EncryptedDataKey
from aws_encryption_sdk.structures import DataKey, MasterKeyInfo, RawDataKey

from .test_values import VALUES
Expand Down
6 changes: 3 additions & 3 deletions test/unit/unit_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

from aws_encryption_sdk.identifiers import Algorithm, KeyringTraceFlag, WrappingAlgorithm
from aws_encryption_sdk.internal.utils.streams import InsistentReaderBytesIO
from aws_encryption_sdk.keyring.base import Keyring
from aws_encryption_sdk.keyring.multi_keyring import MultiKeyring
from aws_encryption_sdk.keyring.raw_keyring import RawAESKeyring, RawRSAKeyring
from aws_encryption_sdk.keyrings.base import Keyring
from aws_encryption_sdk.keyrings.multi import MultiKeyring
from aws_encryption_sdk.keyrings.raw import RawAESKeyring, RawRSAKeyring
from aws_encryption_sdk.materials_managers import DecryptionMaterials, EncryptionMaterials
from aws_encryption_sdk.structures import EncryptedDataKey, KeyringTrace, MasterKeyInfo, RawDataKey

Expand Down