Skip to content

Commit d1a9fe7

Browse files
committed
Scrub Python code comments
1 parent b6a2bbc commit d1a9fe7

File tree

4 files changed

+47
-29
lines changed

4 files changed

+47
-29
lines changed

README.rst

+4-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ An example of a CMM is the default CMM, which is automatically generated anywher
4444
key provider. The default CMM collects encrypted data keys from all master keys referenced by the master key
4545
provider.
4646

47-
An example of a more advanced CMM is the caching CMM, which caches cryptographic materials provided by a another CMM.
47+
An example of a more advanced CMM is the caching CMM, which caches cryptographic materials provided by another CMM.
4848

4949
Master Key Providers
5050
--------------------
@@ -57,12 +57,13 @@ To encrypt data in this client, a ``MasterKeyProvider`` object must contain at l
5757

5858
Master Keys
5959
-----------
60-
Master keys provide data keys.
60+
Master keys generate, encrypt, and decrypt data keys.
6161
An example of a master key is a `KMS customer master key (CMK)`_.
6262

6363
Data Keys
6464
---------
65-
Data Keys are the actual encryption keys which are used to encrypt your data.
65+
Data keys are the encryption keys that are used to encrypt your data. If your algorithm suite
66+
uses a key derivation function, the data key is used to generate the key that directly encrypts the data.
6667

6768
*****
6869
Usage

test/integration/docs_examples_bytes.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@
2121

2222

2323
class StaticRandomMasterKeyProvider(RawMasterKeyProvider):
24-
"""Randomly generates and provides 256-bit keys consistently per unique key id."""
24+
"""Randomly generates 256-bit keys for each unique key ID."""
2525
provider_id = 'static-random'
2626

2727
def __init__(self, **kwargs):
2828
self._static_keys = {}
2929

3030
def _get_raw_key(self, key_id):
31-
"""Retrieves a static, randomly generated, symmetric key for the specified key id.
31+
"""Returns a static, randomly-generated symmetric key for the specified key ID.
3232
3333
:param str key_id: Key ID
34-
:returns: Wrapping key which contains the specified static key
34+
:returns: Wrapping key that contains the specified static key
3535
:rtype: :class:`aws_encryption_sdk.internal.crypto.WrappingKey`
3636
"""
3737
try:
@@ -47,20 +47,20 @@ def _get_raw_key(self, key_id):
4747

4848

4949
def cycle_file(source_plaintext_filename):
50-
"""Encrypts and then decrypts a file under a custom static Master Key Provider.
50+
"""Encrypts and then decrypts a file under a custom static master key provider.
5151
5252
:param str source_plaintext_filename: Filename of file to encrypt
5353
"""
5454

55-
# Create the Static Random Master Key Provider
55+
# Create a static random master key provider
5656
key_id = os.urandom(8)
5757
master_key_provider = StaticRandomMasterKeyProvider()
5858
master_key_provider.add_master_key(key_id)
5959

6060
ciphertext_filename = source_plaintext_filename + '.encrypted'
6161
cycled_plaintext_filename = source_plaintext_filename + '.decrypted'
6262

63-
# Encrypt the source plaintext
63+
# Encrypt the plaintext source data
6464
with open(source_plaintext_filename, 'rb') as plaintext, open(ciphertext_filename, 'wb') as ciphertext:
6565
with aws_encryption_sdk.stream(
6666
mode='e',
@@ -80,10 +80,15 @@ def cycle_file(source_plaintext_filename):
8080
for chunk in decryptor:
8181
plaintext.write(chunk)
8282

83-
# Validate that the cycled plaintext is identical to the source plaintext
83+
# Verify that the "cycled" (encrypted, then decrypted) plaintext is identical to the source
84+
# plaintext
8485
assert filecmp.cmp(source_plaintext_filename, cycled_plaintext_filename)
8586

86-
# Validate that the encryption context used by the decryptor has all the key-pairs from the encryptor
87+
# Verify that the encryption context used in the decrypt operation includes all key pairs from
88+
# the encrypt operation
89+
#
90+
# In production, always use a meaningful encryption context. In this sample, we omit the
91+
# encryption context (no key pairs).
8792
assert all(
8893
pair in decryptor.header.encryption_context.items()
8994
for pair in encryptor.header.encryption_context.items()

test/integration/docs_examples_multiple_providers.py

+21-13
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ def __init__(self, **kwargs):
3333
def _get_raw_key(self, key_id):
3434
"""Retrieves a static, randomly generated, RSA key for the specified key id.
3535
36-
:param str key_id: Key ID
37-
:returns: Wrapping key which contains the specified static key
36+
:param str key_id: : User-defined ID for the static key
37+
:returns: Wrapping key that contains the specified static key
3838
:rtype: :class:`aws_encryption_sdk.internal.crypto.WrappingKey`
3939
"""
4040
try:
@@ -59,33 +59,36 @@ def _get_raw_key(self, key_id):
5959

6060

6161
def cycle_file(key_arn, source_plaintext_filename, botocore_session=None):
62-
"""Encrypts and then decrypts a file under both a KMS Master Key Provider and a custom static Master Key Provider.
62+
"""Encrypts and then decrypts a file using a KMS master key provider and a custom static master
63+
key provider. Both master key providers are used to encrypt the plaintext file, so either one alone
64+
can decrypt it.
6365
64-
:param str key_arn: Amazon Resource Name (Arn) of the KMS CMK
66+
:param str key_arn: Amazon Resource Name (ARN) of the KMS Customer Master Key (CMK) (http://docs.aws.amazon.com/kms/latest/developerguide/viewing-keys.html)
6567
:param str source_plaintext_filename: Filename of file to encrypt
6668
:param botocore_session: existing botocore session instance
6769
:type botocore_session: botocore.session.Session
6870
"""
69-
71+
72+
# "Cycled" means encrypted and then decrypted
7073
ciphertext_filename = source_plaintext_filename + '.encrypted'
7174
cycled_kms_plaintext_filename = source_plaintext_filename + '.kms.decrypted'
7275
cycled_static_plaintext_filename = source_plaintext_filename + '.static.decrypted'
7376

74-
# Create KMS Master Key Provider
77+
# Create a KMS master key provider
7578
kms_kwargs = dict(key_ids=[key_arn])
7679
if botocore_session is not None:
7780
kms_kwargs['botocore_session'] = botocore_session
7881
kms_master_key_provider = aws_encryption_sdk.KMSMasterKeyProvider(**kms_kwargs)
7982

80-
# Create Static Master Key Provider and add to KMS Master Key Provider
83+
# Create a static master key provider and add a master key to it
8184
static_key_id = os.urandom(8)
8285
static_master_key_provider = StaticRandomMasterKeyProvider()
8386
static_master_key_provider.add_master_key(static_key_id)
8487

85-
# Add Static Master Key Provider to KMS Master Key Provider
88+
# Create a master key provider that includes the KMS and static master key providers
8689
kms_master_key_provider.add_master_key_provider(static_master_key_provider)
8790

88-
# Encrypt plaintext with both KMS and Static Master Keys
91+
# Encrypt plaintext with both KMS and static master keys
8992
with open(source_plaintext_filename, 'rb') as plaintext, open(ciphertext_filename, 'wb') as ciphertext:
9093
with aws_encryption_sdk.stream(
9194
source=plaintext,
@@ -95,7 +98,7 @@ def cycle_file(key_arn, source_plaintext_filename, botocore_session=None):
9598
for chunk in encryptor:
9699
ciphertext.write(chunk)
97100

98-
# Decrypt the ciphertext with the KMS Master Key
101+
# Decrypt the ciphertext with only the KMS master key
99102
with open(ciphertext_filename, 'rb') as ciphertext, open(cycled_kms_plaintext_filename, 'wb') as plaintext:
100103
with aws_encryption_sdk.stream(
101104
source=ciphertext,
@@ -105,7 +108,7 @@ def cycle_file(key_arn, source_plaintext_filename, botocore_session=None):
105108
for chunk in kms_decryptor:
106109
plaintext.write(chunk)
107110

108-
# Decrypt the ciphertext with the Static Master Key only
111+
# Decrypt the ciphertext with only the static master key
109112
with open(ciphertext_filename, 'rb') as ciphertext, open(cycled_static_plaintext_filename, 'wb') as plaintext:
110113
with aws_encryption_sdk.stream(
111114
source=ciphertext,
@@ -115,11 +118,16 @@ def cycle_file(key_arn, source_plaintext_filename, botocore_session=None):
115118
for chunk in static_decryptor:
116119
plaintext.write(chunk)
117120

118-
# Validate that the cycled plaintext is identical to the source plaintext
121+
# Verify that the "cycled" (encrypted, then decrypted) plaintext is identical to the source plaintext
119122
assert filecmp.cmp(source_plaintext_filename, cycled_kms_plaintext_filename)
120123
assert filecmp.cmp(source_plaintext_filename, cycled_static_plaintext_filename)
121124

122-
# Validate that the encryption context used by the decryptor has all the key-pairs from the encryptor
125+
126+
# Verify that the encryption context in the decrypt operation includes all key pairs from the
127+
# encrypt operation.
128+
#
129+
# In production, always use a meaningful encryption context. In this sample, we omit the
130+
# encryption context (no key pairs).
123131
assert all(
124132
pair in kms_decryptor.header.encryption_context.items()
125133
for pair in encryptor.header.encryption_context.items()

test/integration/docs_examples_strings.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@
1919
def cycle_string(key_arn, source_plaintext, botocore_session=None):
2020
"""Encrypts and then decrypts a string under a KMS customer master key (CMK)
2121
22-
:param str key_arn: Amazon Resource Name (Arn) of the KMS CMK
22+
:param str key_arn: Amazon Resource Name (ARN) of the KMS CMK
2323
:param bytes source_plaintext: Data to encrypt
2424
:param botocore_session: existing botocore session instance
2525
:type botocore_session: botocore.session.Session
2626
"""
2727

28-
# Create the KMS Master Key Provider
28+
# Create a KMS master key provider
2929
kms_kwargs = dict(key_ids=[key_arn])
3030
if botocore_session is not None:
3131
kms_kwargs['botocore_session'] = botocore_session
3232
master_key_provider = aws_encryption_sdk.KMSMasterKeyProvider(**kms_kwargs)
3333

34-
# Encrypt the source plaintext
34+
# Encrypt the plaintext source data
3535
ciphertext, encryptor_header = aws_encryption_sdk.encrypt(
3636
source=source_plaintext,
3737
key_provider=master_key_provider
@@ -44,10 +44,14 @@ def cycle_string(key_arn, source_plaintext, botocore_session=None):
4444
key_provider=master_key_provider
4545
)
4646

47-
# Validate that the cycled plaintext is identical to the source plaintext
47+
# Verify that the "cycled" (encrypted, then decrypted) plaintext is identical to the source plaintext
4848
assert cycled_plaintext == source_plaintext
4949

50-
# Validate that the encryption context used by the decryptor has all the key-pairs from the encryptor
50+
# Verify that the encryption context used in the decrypt operation includes all key pairs from
51+
# the encrypt operation. (The SDK can add pairs, so don't require an exact match.)
52+
#
53+
# In production, always use a meaningful encryption context. In this sample, we omit the
54+
# encryption context (no key pairs).
5155
assert all(
5256
pair in decrypted_header.encryption_context.items()
5357
for pair in encryptor_header.encryption_context.items()

0 commit comments

Comments
 (0)