Skip to content

Commit f1011a6

Browse files
committed
we only need to care about Python 3.6 for the decrypt oracle
* remove import safeguards to allow 3.5.0 and 3.5.1 to not fail * convert from comment-style typehints to inline
1 parent e30e19c commit f1011a6

File tree

9 files changed

+40
-88
lines changed

9 files changed

+40
-88
lines changed

.travis.yml

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -206,33 +206,12 @@ matrix:
206206
##################
207207
# Decrypt Oracle #
208208
##################
209-
# CPython 2.7
210-
- python: 2.7
211-
env:
212-
DECRYPT_ORACLE=1
213-
TOXENV=py27-local
214-
# CPython 3.4
215-
- python: 3.4
216-
env:
217-
DECRYPT_ORACLE=1
218-
TOXENV=py34-local
219-
# CPython 3.5
220-
- python: 3.5
221-
env:
222-
DECRYPT_ORACLE=1
223-
TOXENV=py35-local
224209
# CPython 3.6
210+
# Because this build as Python 3.6 Lambda, this is the only runtime we are targetting.
225211
- python: 3.6
226212
env:
227213
DECRYPT_ORACLE=1
228214
TOXENV=py36-local
229-
# CPython 3.7
230-
- python: 3.7
231-
env:
232-
DECRYPT_ORACLE=1
233-
TOXENV=py37-local
234-
dist: xenial
235-
sudo: true
236215
# Linters
237216
- python: 3.6
238217
env:

decrypt_oracle/setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ force_grid_wrap = 0
3939
combine_as_imports = True
4040
not_skip = __init__.py
4141
known_first_party = aws_encryption_sdk_decryption_oracle
42-
known_third_party =aws_encryption_sdk,aws_encryption_sdk_decryption_oracle,chalice,pytest,requests,setuptools
42+
known_third_party =aws_encryption_sdk,aws_encryption_sdk_decrypt_oracle,aws_encryption_sdk_decryption_oracle,chalice,pytest,requests,setuptools

decrypt_oracle/src/aws_encryption_sdk_decrypt_oracle/app.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,8 @@
2626
APP = Chalice(app_name="aws-encryption-sdk-decrypt-oracle", debug=CHALICE_DEBUG)
2727
APP.log.setLevel(logging.DEBUG)
2828

29-
try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
30-
from typing import Dict, Text, NoReturn, Union # noqa pylint: disable=unused-import
31-
except ImportError: # pragma: no cover
32-
# We only actually need these imports when running the mypy checks
33-
pass
3429

35-
36-
def _master_key_provider():
37-
# type: () -> KMSMasterKeyProvider
30+
def _master_key_provider() -> KMSMasterKeyProvider:
3831
"""Build the V0 master key provider."""
3932
master_key_provider = KMSMasterKeyProvider()
4033
master_key_provider.add_master_key_provider(NullMasterKey())
@@ -43,8 +36,7 @@ def _master_key_provider():
4336

4437

4538
@APP.route("/v0/decrypt", methods=["POST"], content_types=["application/octet-stream"])
46-
def basic_decrypt():
47-
# type: () -> Response
39+
def basic_decrypt() -> Response:
4840
"""Basic decrypt handler for decrypt oracle v0.
4941
5042
**Request**

decrypt_oracle/src/aws_encryption_sdk_decrypt_oracle/key_providers/counting.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,22 @@
1414
Master key that generates deterministic data keys and decrypts a pre-defined
1515
encrypted data key value to that deterministic data keys.
1616
"""
17+
from typing import Dict, NoReturn, Text
18+
1719
from aws_encryption_sdk.exceptions import DecryptKeyError
18-
from aws_encryption_sdk.identifiers import AlgorithmSuite # noqa pylint: disable=unused-import
20+
from aws_encryption_sdk.identifiers import AlgorithmSuite
1921
from aws_encryption_sdk.key_providers.base import MasterKey, MasterKeyConfig
20-
from aws_encryption_sdk.structures import EncryptedDataKey # noqa pylint: disable=unused-import
22+
from aws_encryption_sdk.structures import EncryptedDataKey
2123
from aws_encryption_sdk.structures import DataKey
2224

23-
try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
24-
from typing import Dict, Text, NoReturn # noqa pylint: disable=unused-import
25-
except ImportError: # pragma: no cover
26-
# We only actually need these imports when running the mypy checks
27-
pass
28-
2925

3026
class CountingMasterKeyConfig(MasterKeyConfig):
3127
# pylint: disable=too-few-public-methods
3228
"""Passthrough master key configuration to set the key id to "test_counting_prov_info"."""
3329

3430
provider_id = "test_counting"
3531

36-
def __init__(self):
37-
# type: () -> None
32+
def __init__(self) -> None:
3833
"""Set the key id to "test_counting_prov_info"."""
3934
super(CountingMasterKeyConfig, self).__init__(key_id=b"test_counting_prov_info")
4035

@@ -51,8 +46,7 @@ class CountingMasterKey(MasterKey):
5146
_config_class = CountingMasterKeyConfig
5247
_encrypted_data_key = b"\x40\x41\x42\x43\x44"
5348

54-
def _generate_data_key(self, algorithm, encryption_context):
55-
# type: (AlgorithmSuite, Dict[Text, Text]) -> DataKey
49+
def _generate_data_key(self, algorithm: AlgorithmSuite, encryption_context: Dict[Text, Text]) -> DataKey:
5650
"""Perform the provider-specific data key generation task.
5751
5852
:param algorithm: Algorithm on which to base data key
@@ -64,8 +58,9 @@ def _generate_data_key(self, algorithm, encryption_context):
6458
data_key = b"".join([chr(i).encode("utf-8") for i in range(1, algorithm.data_key_len + 1)])
6559
return DataKey(key_provider=self.key_provider, data_key=data_key, encrypted_data_key=self._encrypted_data_key)
6660

67-
def _encrypt_data_key(self, data_key, algorithm, encryption_context):
68-
# type: (DataKey, AlgorithmSuite, Dict[Text, Text]) -> NoReturn
61+
def _encrypt_data_key(
62+
self, data_key: DataKey, algorithm: AlgorithmSuite, encryption_context: Dict[Text, Text]
63+
) -> NoReturn:
6964
"""Encrypt a data key and return the ciphertext.
7065
7166
:param data_key: Unencrypted data key
@@ -78,8 +73,9 @@ def _encrypt_data_key(self, data_key, algorithm, encryption_context):
7873
"""
7974
raise NotImplementedError("CountingMasterKey does not support encrypt_data_key")
8075

81-
def _decrypt_data_key(self, encrypted_data_key, algorithm, encryption_context):
82-
# type: (EncryptedDataKey, AlgorithmSuite, Dict[Text, Text]) -> DataKey
76+
def _decrypt_data_key(
77+
self, encrypted_data_key: EncryptedDataKey, algorithm: AlgorithmSuite, encryption_context: Dict[Text, Text]
78+
) -> DataKey:
8379
"""Decrypt an encrypted data key and return the plaintext.
8480
8581
:param data_key: Encrypted data key

decrypt_oracle/src/aws_encryption_sdk_decrypt_oracle/key_providers/null.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,21 @@
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
1313
"""Master key that provides null data keys."""
14-
from aws_encryption_sdk.identifiers import AlgorithmSuite # noqa pylint: disable=unused-import
14+
from typing import Dict, NoReturn, Text
15+
16+
from aws_encryption_sdk.identifiers import AlgorithmSuite
1517
from aws_encryption_sdk.key_providers.base import MasterKey, MasterKeyConfig
16-
from aws_encryption_sdk.structures import EncryptedDataKey # noqa pylint: disable=unused-import
18+
from aws_encryption_sdk.structures import EncryptedDataKey
1719
from aws_encryption_sdk.structures import DataKey
1820

19-
try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
20-
from typing import Dict, Text, NoReturn # noqa pylint: disable=unused-import
21-
except ImportError: # pragma: no cover
22-
# We only actually need these imports when running the mypy checks
23-
pass
24-
2521

2622
class NullMasterKeyConfig(MasterKeyConfig):
2723
# pylint: disable=too-few-public-methods
2824
"""Passthrough master key configuration to set the key id to "null"."""
2925

3026
provider_id = "null"
3127

32-
def __init__(self):
33-
# type: () -> None
28+
def __init__(self) -> None:
3429
"""Set the key id to "null"."""
3530
super(NullMasterKeyConfig, self).__init__(key_id=b"null")
3631

@@ -43,8 +38,7 @@ class NullMasterKey(MasterKey):
4338
_allowed_provider_ids = (provider_id, "zero")
4439
_config_class = NullMasterKeyConfig
4540

46-
def owns_data_key(self, data_key):
47-
# type: (DataKey) -> bool
41+
def owns_data_key(self, data_key: DataKey) -> bool:
4842
"""Determine whether the data key is owned by a ``null`` or ``zero`` provider.
4943
5044
:param data_key: Data key to evaluate
@@ -57,8 +51,7 @@ def owns_data_key(self, data_key):
5751
return data_key.key_provider.provider_id in self._allowed_provider_ids
5852

5953
@staticmethod
60-
def _null_plaintext_data_key(algorithm):
61-
# type: (AlgorithmSuite) -> bytes
54+
def _null_plaintext_data_key(algorithm: AlgorithmSuite) -> bytes:
6255
"""Build the null data key of the correct length for the requested algorithm suite.
6356
6457
:param algorithm: Algorithm on which to base data key
@@ -68,8 +61,7 @@ def _null_plaintext_data_key(algorithm):
6861
"""
6962
return b"\x00" * algorithm.data_key_len
7063

71-
def _generate_data_key(self, algorithm, encryption_context):
72-
# type: (AlgorithmSuite, Dict[Text, Text]) -> DataKey
64+
def _generate_data_key(self, algorithm: AlgorithmSuite, encryption_context: Dict[Text, Text]) -> DataKey:
7365
"""NullMasterKey does not support generate_data_key
7466
7567
:param algorithm: Algorithm on which to base data key
@@ -81,8 +73,9 @@ def _generate_data_key(self, algorithm, encryption_context):
8173
key_provider=self.key_provider, data_key=self._null_plaintext_data_key(algorithm), encrypted_data_key=b""
8274
)
8375

84-
def _encrypt_data_key(self, data_key, algorithm, encryption_context):
85-
# type: (DataKey, AlgorithmSuite, Dict[Text, Text]) -> NoReturn
76+
def _encrypt_data_key(
77+
self, data_key: DataKey, algorithm: AlgorithmSuite, encryption_context: Dict[Text, Text]
78+
) -> NoReturn:
8679
"""NullMasterKey does not support encrypt_data_key
8780
8881
:param data_key: Unencrypted data key
@@ -95,8 +88,9 @@ def _encrypt_data_key(self, data_key, algorithm, encryption_context):
9588
"""
9689
raise NotImplementedError("NullMasterKey does not support encrypt_data_key")
9790

98-
def _decrypt_data_key(self, encrypted_data_key, algorithm, encryption_context):
99-
# type: (EncryptedDataKey, AlgorithmSuite, Dict[Text, Text]) -> DataKey
91+
def _decrypt_data_key(
92+
self, encrypted_data_key: EncryptedDataKey, algorithm: AlgorithmSuite, encryption_context: Dict[Text, Text]
93+
) -> DataKey:
10094
"""Decrypt an encrypted data key and return the plaintext.
10195
10296
:param data_key: Encrypted data key

decrypt_oracle/test/integration/integration_test_utils.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import json
1616
import os
1717
from collections import namedtuple
18+
from typing import Any, Callable, Iterable, Optional, Text
1819

1920
import pytest
2021
from aws_encryption_sdk.key_providers.kms import KMSMasterKeyProvider
@@ -27,7 +28,7 @@
2728
_ENDPOINT = None
2829

2930

30-
def decrypt_endpoint():
31+
def decrypt_endpoint() -> Text:
3132
"""Build the API endpoint based on environment variables."""
3233
global _ENDPOINT # pylint: disable=global-statement
3334

@@ -51,7 +52,7 @@ def decrypt_endpoint():
5152
return _ENDPOINT
5253

5354

54-
def get_cmk_arn():
55+
def get_cmk_arn() -> Text:
5556
"""Retrieve the target CMK ARN from environment variable."""
5657
try:
5758
arn = os.environ[AWS_KMS_KEY_ID]
@@ -68,7 +69,7 @@ def get_cmk_arn():
6869
raise ValueError("KMS CMK ARN provided for integration tests must be a key not an alias")
6970

7071

71-
def kms_master_key_provider(cache=True):
72+
def kms_master_key_provider(cache: Optional[bool] = True):
7273
"""Build the expected KMS Master Key Provider based on environment variables."""
7374
global _KMS_MKP # pylint: disable=global-statement
7475

@@ -85,15 +86,15 @@ def kms_master_key_provider(cache=True):
8586
return _kms_master_key_provider
8687

8788

88-
def test_vectors_filename():
89+
def test_vectors_filename() -> Text:
8990
"""Provide the absolute path to the test vectors file."""
9091
return os.path.join(HERE, "..", "vectors", "decrypt_vectors.json")
9192

9293

9394
TestVector = namedtuple("TestVector", ["plaintext", "ciphertext", "key_type", "algorithm_suite"])
9495

9596

96-
def all_test_vectors():
97+
def all_test_vectors() -> Iterable[Any]:
9798
"""Collect and iterate through all test vectors."""
9899

99100
with open(test_vectors_filename(), "r") as vectors_file:
@@ -114,7 +115,7 @@ def all_test_vectors():
114115
)
115116

116117

117-
def filtered_test_vectors(filter_function):
118+
def filtered_test_vectors(filter_function: Callable) -> Iterable[Any]:
118119
"""Collect and iterate through all test vectors that pass the filter function."""
119120
for vector_param in all_test_vectors():
120121
if filter_function(vector_param.values[0]):

decrypt_oracle/test/test_n_generate_test_vectors.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,24 @@
1515
import binascii
1616
import json
1717
import os
18+
from typing import Dict, Iterable, Text
1819

1920
import aws_encryption_sdk
2021
import pytest
2122
from aws_encryption_sdk.key_providers.base import MasterKeyProvider
2223
from aws_encryption_sdk.key_providers.kms import KMSMasterKey
23-
2424
from aws_encryption_sdk_decrypt_oracle.key_providers.counting import CountingMasterKey
2525
from aws_encryption_sdk_decrypt_oracle.key_providers.null import NullMasterKey
2626

2727
from .integration.integration_test_utils import test_vectors_filename
2828

29-
try: # Python 3.5.0 and 3.5.1 have incompatible typing modules
30-
from typing import Dict, Text, Iterable # noqa pylint: disable=unused-import
31-
except ImportError: # pragma: no cover
32-
# We only actually need these imports when running the mypy checks
33-
pass
34-
3529
HERE = os.path.abspath(os.path.dirname(__file__))
3630
GENERATE_VECTORS = "AWS_ENCRYPTION_SDK_PYTHON_DECRYPT_ORACLE_GENERATE_TEST_VECTORS"
3731
PUBLIC_CMK = "arn:aws:kms:us-west-2:658956600833:alias/EncryptDecrypt"
3832
ENCRYPTION_CONTEXT = {"key1": "val1", "key2": "val2"}
3933

4034

41-
def _key_providers():
42-
# type: () -> Iterable[MasterKeyProvider]
35+
def _key_providers() -> Iterable[MasterKeyProvider]:
4336
"""Generate all master key providers for test vector generation.
4437
Each will be used independently.
4538
"""
@@ -48,8 +41,7 @@ def _key_providers():
4841
yield KMSMasterKey(key_id=PUBLIC_CMK)
4942

5043

51-
def _generate_vectors(key_provider, plaintext):
52-
# type: (MasterKeyProvider, bytes) -> Iterable[Dict[Text, Text]]
44+
def _generate_vectors(key_provider: MasterKeyProvider, plaintext: bytes) -> Iterable[Dict[Text, Text]]:
5345
"""Generate all desired test vectors for a given key provider and plaintext."""
5446
for algorithm_suite in aws_encryption_sdk.Algorithm:
5547
ciphertext, _header = aws_encryption_sdk.encrypt(

decrypt_oracle/test/unit/key_providers/test_u_counting.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"""Unit test for ``aws_encryption_sdk_decrypt_oracle.key_providers.counting``."""
1414
import aws_encryption_sdk
1515
import pytest
16-
1716
from aws_encryption_sdk_decrypt_oracle.key_providers.counting import CountingMasterKey
1817

1918
from ...integration.integration_test_utils import filtered_test_vectors

decrypt_oracle/test/unit/key_providers/test_u_null.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"""Unit test for ``aws_encryption_sdk_decrypt_oracle.key_providers.null``."""
1414
import aws_encryption_sdk
1515
import pytest
16-
1716
from aws_encryption_sdk_decrypt_oracle.key_providers.null import NullMasterKey
1817

1918
from ...integration.integration_test_utils import filtered_test_vectors

0 commit comments

Comments
 (0)