Skip to content

Commit febe6db

Browse files
cleanup
1 parent 6bf6094 commit febe6db

File tree

5 files changed

+22
-25
lines changed

5 files changed

+22
-25
lines changed

examples/src/keyrings/required_encryption_context_cmm.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,17 @@
1414
from aws_cryptographic_materialproviders.mpl import AwsCryptographicMaterialProviders
1515
from aws_cryptographic_materialproviders.mpl.config import MaterialProvidersConfig
1616
from aws_cryptographic_materialproviders.mpl.models import (
17-
CacheTypeDefault,
1817
CreateAwsKmsKeyringInput,
1918
CreateDefaultCryptographicMaterialsManagerInput,
2019
CreateRequiredEncryptionContextCMMInput,
21-
DefaultCache,
2220
)
23-
from aws_cryptographic_materialproviders.mpl.references import (
24-
IKeyring,
25-
ICryptographicMaterialsManager,
26-
)
27-
from aws_encryption_sdk.materials_managers.mpl.cmm import CryptoMaterialsManagerFromMPL
28-
from typing import Dict
21+
from aws_cryptographic_materialproviders.mpl.references import ICryptographicMaterialsManager, IKeyring
22+
from typing import Dict, List
2923

3024
import aws_encryption_sdk
3125
from aws_encryption_sdk import CommitmentPolicy
3226
from aws_encryption_sdk.exceptions import AWSEncryptionSDKClientError
3327

34-
from .example_branch_key_id_supplier import ExampleBranchKeyIdSupplier
35-
3628
# TODO-MPL: Remove this as part of removing PYTHONPATH hacks
3729
module_root_dir = '/'.join(__file__.split("/")[:-1])
3830

@@ -98,7 +90,7 @@ def encrypt_and_decrypt_with_keyring(
9890
underlying_cmm=underlying_cmm,
9991
)
10092
)
101-
93+
10294
# 6. Encrypt the data
10395
ciphertext, _ = client.encrypt(
10496
source=EXAMPLE_DATA,

src/aws_encryption_sdk/internal/formatting/serialize.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def _serialize_header_auth_v2(
223223
header,
224224
data_encryption_key,
225225
signer=None,
226-
required_encryption_context_bytes=None
226+
required_ec_bytes=None
227227
):
228228
"""Creates serialized header authentication data for messages in serialization version V2.
229229
@@ -241,7 +241,7 @@ def _serialize_header_auth_v2(
241241
:returns: Serialized header authentication data
242242
:rtype: bytes
243243
"""
244-
if required_encryption_context_bytes is None:
244+
if required_ec_bytes is None:
245245
header_auth = encrypt(
246246
algorithm=algorithm,
247247
key=data_encryption_key,
@@ -259,7 +259,7 @@ def _serialize_header_auth_v2(
259259
# be the encryption context in the encryption materials filtered to only contain key value
260260
# pairs listed in the encryption material's required encryption context keys serialized
261261
# according to the encryption context serialization specification.
262-
associated_data=header + required_encryption_context_bytes,
262+
associated_data=header + required_ec_bytes,
263263
iv=header_auth_iv(algorithm),
264264
)
265265
output = struct.pack(
@@ -277,7 +277,7 @@ def serialize_header_auth(
277277
header,
278278
data_encryption_key,
279279
signer=None,
280-
required_encryption_context_bytes=None
280+
required_ec_bytes=None
281281
):
282282
"""Creates serialized header authentication data.
283283
@@ -302,7 +302,7 @@ def serialize_header_auth(
302302
return _serialize_header_auth_v1(algorithm, header, data_encryption_key, signer)
303303
elif version == SerializationVersion.V2:
304304
return _serialize_header_auth_v2(
305-
algorithm, header, data_encryption_key, signer, required_encryption_context_bytes
305+
algorithm, header, data_encryption_key, signer, required_ec_bytes
306306
)
307307
else:
308308
raise SerializationError("Unrecognized message format version: {}".format(version))

src/aws_encryption_sdk/materials_managers/mpl/materials.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ def signing_key(self) -> bytes:
9797
return self.mpl_materials.signing_key
9898

9999
@property
100+
# Pylint thinks this name is too long, but it's the best descriptor for this...
101+
# pylint: disable=invalid-name
100102
def required_encryption_context_keys(self) -> bytes:
101103
"""Materials' required encryption context keys."""
102104
return self.mpl_materials.required_encryption_context_keys
@@ -148,6 +150,8 @@ def encryption_context(self) -> Dict[str, str]:
148150
return self.mpl_materials.encryption_context
149151

150152
@property
153+
# Pylint thinks this name is too long, but it's the best descriptor for this...
154+
# pylint: disable=invalid-name
151155
def required_encryption_context_keys(self) -> bytes:
152156
"""Materials' required encryption context keys."""
153157
return self.mpl_materials.required_encryption_context_keys

src/aws_encryption_sdk/streaming_client.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@
7676
from aws_cryptographic_materialproviders.mpl import AwsCryptographicMaterialProviders
7777
from aws_cryptographic_materialproviders.mpl.config import MaterialProvidersConfig
7878
from aws_cryptographic_materialproviders.mpl.errors import AwsCryptographicMaterialProvidersException
79-
from aws_cryptographic_materialproviders.mpl.models import (
80-
CreateDefaultCryptographicMaterialsManagerInput,
81-
)
79+
from aws_cryptographic_materialproviders.mpl.models import CreateDefaultCryptographicMaterialsManagerInput
8280
from aws_cryptographic_materialproviders.mpl.references import (
8381
ICryptographicMaterialsManager as MPL_ICryptographicMaterialsManager,
8482
IKeyring as MPL_IKeyring,
@@ -631,11 +629,11 @@ def generate_header(self, message_id):
631629
if hasattr(self._encryption_materials, "required_encryption_context_keys"):
632630
self._required_encryption_context = {}
633631
self._stored_encryption_context = {}
634-
for (k, v) in self._encryption_materials.encryption_context.items():
635-
if k in self._encryption_materials.required_encryption_context_keys:
636-
self._required_encryption_context[k] = v
632+
for (key, value) in self._encryption_materials.encryption_context.items():
633+
if key in self._encryption_materials.required_encryption_context_keys:
634+
self._required_encryption_context[key] = value
637635
else:
638-
self._stored_encryption_context[k] = v
636+
self._stored_encryption_context[key] = value
639637
# Otherwise, store all encryption context with the message.
640638
else:
641639
self._stored_encryption_context = self._encryption_materials.encryption_context
@@ -956,7 +954,10 @@ def _prep_message(self):
956954
self._prep_non_framed()
957955
self._message_prepped = True
958956

959-
def _read_header(self): # noqa: C901
957+
# TODO-MPL: Refactor this function, remove these linter disablers
958+
# noqa: C901
959+
# pylint: disable=too-many-branches
960+
def _read_header(self):
960961
"""Reads the message header from the input stream.
961962
962963
:returns: tuple containing deserialized header and header_auth objects

test/unit/test_streaming_client_stream_decryptor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def test_read_header(self, mock_derive_datakey, mock_decrypt_materials_request,
238238
@patch("aws_encryption_sdk.streaming_client.Verifier")
239239
# Given: no MPL
240240
@pytest.mark.skipif(HAS_MPL, reason="Test should only be executed without MPL in installation")
241-
def test_GIVEN_verification_key_AND_no_mpl_WHEN_read_header_THEN_calls_from_key_bytes(
241+
def test_GIVEN_decrypt_config_has_ec_WHEN_read_header_THEN_calls_decrypt_materials_with_reproduced_ec(
242242
self,
243243
mock_verifier,
244244
mock_decrypt_materials_request,

0 commit comments

Comments
 (0)