Skip to content

Commit 882dd03

Browse files
author
Adriano Hernandez
committed
Fixed linking issue with algorithm in Sphinx. Black also made some small changes so formatting
may be slightly different, but it should be the same functionality wise. I have a couple errors that I believe are not from my own changes (they were there on master when I pulled and pertain to there not being valid AWS credentials for tests for the most part), but they should not be important.
1 parent 1de8d5c commit 882dd03

File tree

8 files changed

+481
-155
lines changed

8 files changed

+481
-155
lines changed

src/aws_encryption_sdk/__init__.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,17 @@
1414
# Below are imported for ease of use by implementors
1515
from aws_encryption_sdk.caches.local import LocalCryptoMaterialsCache # noqa
1616
from aws_encryption_sdk.caches.null import NullCryptoMaterialsCache # noqa
17-
from aws_encryption_sdk.identifiers import Algorithm, __version__ # noqa
18-
from aws_encryption_sdk.key_providers.kms import KMSMasterKeyProvider, KMSMasterKeyProviderConfig # noqa
19-
from aws_encryption_sdk.materials_managers.caching import CachingCryptoMaterialsManager # noqa
20-
from aws_encryption_sdk.materials_managers.default import DefaultCryptoMaterialsManager # noqa
17+
from aws_encryption_sdk.identifiers import AlgorithmSuite, __version__ # noqa
18+
from aws_encryption_sdk.key_providers.kms import (
19+
KMSMasterKeyProvider,
20+
KMSMasterKeyProviderConfig,
21+
) # noqa
22+
from aws_encryption_sdk.materials_managers.caching import (
23+
CachingCryptoMaterialsManager,
24+
) # noqa
25+
from aws_encryption_sdk.materials_managers.default import (
26+
DefaultCryptoMaterialsManager,
27+
) # noqa
2128
from aws_encryption_sdk.streaming_client import ( # noqa
2229
DecryptorConfig,
2330
EncryptorConfig,
@@ -69,8 +76,8 @@ def encrypt(**kwargs):
6976
this is not enforced if a `key_provider` is provided.
7077
7178
:param dict encryption_context: Dictionary defining encryption context
72-
:param algorithm: Algorithm to use for encryption
73-
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
79+
:param algorithm: AlgorithmSuite to use for encryption
80+
:type algorithm: aws_encryption_sdk.identifiers.AlgorithmSuite
7481
:param int frame_length: Frame length in bytes
7582
:returns: Tuple containing the encrypted ciphertext and the message header object
7683
:rtype: tuple of bytes and :class:`aws_encryption_sdk.structures.MessageHeader`
@@ -177,7 +184,12 @@ def stream(**kwargs):
177184
:raises ValueError: if supplied with an unsupported mode value
178185
"""
179186
mode = kwargs.pop("mode")
180-
_stream_map = {"e": StreamEncryptor, "encrypt": StreamEncryptor, "d": StreamDecryptor, "decrypt": StreamDecryptor}
187+
_stream_map = {
188+
"e": StreamEncryptor,
189+
"encrypt": StreamEncryptor,
190+
"d": StreamDecryptor,
191+
"decrypt": StreamDecryptor,
192+
}
181193
try:
182194
return _stream_map[mode.lower()](**kwargs)
183195
except KeyError:

src/aws_encryption_sdk/identifiers.py

Lines changed: 78 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,15 @@ class EncryptionSuite(Enum):
5050
AES_192_GCM_IV12_TAG16 = (algorithms.AES, modes.GCM, 24, 12, 16)
5151
AES_256_GCM_IV12_TAG16 = (algorithms.AES, modes.GCM, 32, 12, 16)
5252

53-
def __init__(self, algorithm, mode, data_key_length, iv_length, auth_length, auth_key_length=0):
53+
def __init__(
54+
self,
55+
algorithm,
56+
mode,
57+
data_key_length,
58+
iv_length,
59+
auth_length,
60+
auth_key_length=0,
61+
):
5462
"""Prepare a new EncryptionSuite."""
5563
self.algorithm = algorithm
5664
self.mode = mode
@@ -157,9 +165,21 @@ class AlgorithmSuite(Enum): # pylint: disable=too-many-instance-attributes
157165
AES_128_GCM_IV12_TAG16 = (0x0014, EncryptionSuite.AES_128_GCM_IV12_TAG16)
158166
AES_192_GCM_IV12_TAG16 = (0x0046, EncryptionSuite.AES_192_GCM_IV12_TAG16)
159167
AES_256_GCM_IV12_TAG16 = (0x0078, EncryptionSuite.AES_256_GCM_IV12_TAG16)
160-
AES_128_GCM_IV12_TAG16_HKDF_SHA256 = (0x0114, EncryptionSuite.AES_128_GCM_IV12_TAG16, KDFSuite.HKDF_SHA256)
161-
AES_192_GCM_IV12_TAG16_HKDF_SHA256 = (0x0146, EncryptionSuite.AES_192_GCM_IV12_TAG16, KDFSuite.HKDF_SHA256)
162-
AES_256_GCM_IV12_TAG16_HKDF_SHA256 = (0x0178, EncryptionSuite.AES_256_GCM_IV12_TAG16, KDFSuite.HKDF_SHA256)
168+
AES_128_GCM_IV12_TAG16_HKDF_SHA256 = (
169+
0x0114,
170+
EncryptionSuite.AES_128_GCM_IV12_TAG16,
171+
KDFSuite.HKDF_SHA256,
172+
)
173+
AES_192_GCM_IV12_TAG16_HKDF_SHA256 = (
174+
0x0146,
175+
EncryptionSuite.AES_192_GCM_IV12_TAG16,
176+
KDFSuite.HKDF_SHA256,
177+
)
178+
AES_256_GCM_IV12_TAG16_HKDF_SHA256 = (
179+
0x0178,
180+
EncryptionSuite.AES_256_GCM_IV12_TAG16,
181+
KDFSuite.HKDF_SHA256,
182+
)
163183
AES_128_GCM_IV12_TAG16_HKDF_SHA256_ECDSA_P256 = (
164184
0x0214,
165185
EncryptionSuite.AES_128_GCM_IV12_TAG16,
@@ -240,6 +260,8 @@ def safe_to_cache(self):
240260
return self.kdf is not KDFSuite.NONE
241261

242262

263+
# algorithm is just an alias for AlgorithmSuite ... but Sphinx does not recognize this fact
264+
# so we need to go through and fix the references
243265
Algorithm = AlgorithmSuite
244266

245267

@@ -271,16 +293,60 @@ class WrappingAlgorithm(Enum):
271293
:type padding_mgf:
272294
"""
273295

274-
AES_128_GCM_IV12_TAG16_NO_PADDING = (EncryptionType.SYMMETRIC, Algorithm.AES_128_GCM_IV12_TAG16, None, None, None)
275-
AES_192_GCM_IV12_TAG16_NO_PADDING = (EncryptionType.SYMMETRIC, Algorithm.AES_192_GCM_IV12_TAG16, None, None, None)
276-
AES_256_GCM_IV12_TAG16_NO_PADDING = (EncryptionType.SYMMETRIC, Algorithm.AES_256_GCM_IV12_TAG16, None, None, None)
296+
AES_128_GCM_IV12_TAG16_NO_PADDING = (
297+
EncryptionType.SYMMETRIC,
298+
AlgorithmSuite.AES_128_GCM_IV12_TAG16,
299+
None,
300+
None,
301+
None,
302+
)
303+
AES_192_GCM_IV12_TAG16_NO_PADDING = (
304+
EncryptionType.SYMMETRIC,
305+
AlgorithmSuite.AES_192_GCM_IV12_TAG16,
306+
None,
307+
None,
308+
None,
309+
)
310+
AES_256_GCM_IV12_TAG16_NO_PADDING = (
311+
EncryptionType.SYMMETRIC,
312+
AlgorithmSuite.AES_256_GCM_IV12_TAG16,
313+
None,
314+
None,
315+
None,
316+
)
277317
RSA_PKCS1 = (EncryptionType.ASYMMETRIC, rsa, padding.PKCS1v15, None, None)
278-
RSA_OAEP_SHA1_MGF1 = (EncryptionType.ASYMMETRIC, rsa, padding.OAEP, hashes.SHA1, padding.MGF1)
279-
RSA_OAEP_SHA256_MGF1 = (EncryptionType.ASYMMETRIC, rsa, padding.OAEP, hashes.SHA256, padding.MGF1)
280-
RSA_OAEP_SHA384_MGF1 = (EncryptionType.ASYMMETRIC, rsa, padding.OAEP, hashes.SHA384, padding.MGF1)
281-
RSA_OAEP_SHA512_MGF1 = (EncryptionType.ASYMMETRIC, rsa, padding.OAEP, hashes.SHA512, padding.MGF1)
318+
RSA_OAEP_SHA1_MGF1 = (
319+
EncryptionType.ASYMMETRIC,
320+
rsa,
321+
padding.OAEP,
322+
hashes.SHA1,
323+
padding.MGF1,
324+
)
325+
RSA_OAEP_SHA256_MGF1 = (
326+
EncryptionType.ASYMMETRIC,
327+
rsa,
328+
padding.OAEP,
329+
hashes.SHA256,
330+
padding.MGF1,
331+
)
332+
RSA_OAEP_SHA384_MGF1 = (
333+
EncryptionType.ASYMMETRIC,
334+
rsa,
335+
padding.OAEP,
336+
hashes.SHA384,
337+
padding.MGF1,
338+
)
339+
RSA_OAEP_SHA512_MGF1 = (
340+
EncryptionType.ASYMMETRIC,
341+
rsa,
342+
padding.OAEP,
343+
hashes.SHA512,
344+
padding.MGF1,
345+
)
282346

283-
def __init__(self, encryption_type, algorithm, padding_type, padding_algorithm, padding_mgf):
347+
def __init__(
348+
self, encryption_type, algorithm, padding_type, padding_algorithm, padding_mgf
349+
):
284350
"""Prepares new WrappingAlgorithm."""
285351
self.encryption_type = encryption_type
286352
self.algorithm = algorithm

0 commit comments

Comments
 (0)