Skip to content

Commit c54f21a

Browse files
mattsb42-awsjuneb
andauthored
Apply suggestions from code review
Co-Authored-By: June Blender <[email protected]>
1 parent b0c7c80 commit c54f21a

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

examples/README.md

+13-15
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# AWS Encryption SDK Examples
22

3-
Here you can find some examples that show you
3+
This section features examples that show you
44
how to use the AWS Encryption SDK.
5-
We demonstrate how to use the high-level APIs
6-
as well as how to set up some common configuration patterns.
5+
We demonstrate how to use the encryption and decryption APIs
6+
and how to set up some common configuration patterns.
77

88
## APIs
99

@@ -17,24 +17,24 @@ in the [`examples/src/`](./src) directory root.
1717
## Configuration
1818

1919
In order to use the library APIs,
20-
you must provide some configuration that defines
20+
you must provide a configuration that defines
2121
how you want to protect your data keys.
2222

2323
### Keyrings
2424

25-
Keyrings are the most common way for you to configure that AWS Encryption SDK.
26-
These let you define how you want the AWS Encryption SDK to protect your data keys.
25+
Keyrings are the most common way for you to configure the AWS Encryption SDK.
26+
They determine how the AWS Encryption SDK protects your data.
2727
You can find these examples in [`examples/src/keyring`](./src/keyring).
2828

2929
### Cryptographic Materials Managers
3030

31-
Keyrings define how you want to protect your data keys,
32-
but there is more going on here than just data keys.
31+
Keyrings define how your data keys are protected,
32+
but there is more going on here than just protecting data keys.
3333

3434
Cryptographic materials managers give you higher-level controls
3535
over how the AWS Encryption SDK protects your data.
3636
This can include things like
37-
enforcing certain algorithm suites or encryption context settings,
37+
enforcing the use of certain algorithm suites or encryption context settings,
3838
reusing data keys across messages,
3939
or changing how you interact with keyrings.
4040
You can find these examples in
@@ -53,17 +53,15 @@ you can find these examples in [`examples/src/master_key_provider`](./src/master
5353

5454
## Legacy
5555

56-
These are any examples that were already defined
57-
before we started revamping our examples.
58-
We are keeping them around for anyone who needs them as reference material,
56+
This section includes older examples, including examples of using master keys and master key providers in Java and Python.
57+
You can use them as a reference,
5958
but we recommend looking at the newer examples
60-
that should provide a clearer picture of how to use this library.
59+
but we recommend looking at the newer examples, which explain the preferred ways of using this library.
6160
You can find these examples in [`examples/src/legacy`](./src/legacy).
6261

6362
# Writing Examples
6463

65-
If you want to write a new example, that's awesome!
66-
There are a couple things you need to keep in mind, though.
64+
If you want to contribute a new example, that's awesome!
6765
To make sure that your example is tested in our CI,
6866
please make sure that it meets the following requirements:
6967

examples/src/file_streaming_defaults.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44
This example shows how to use the streaming encrypt and decrypt APIs when working with files.
55
6-
For the purposes of this example, we demonstrate using AWS KMS,
6+
This example uses an AWS KMS CMK,
77
but you can use other key management options with the AWS Encryption SDK.
88
Look in the ``keyring`` and ``master_key_provider`` directories
99
for examples that demonstrate how to use other key management configurations.
@@ -21,7 +21,7 @@ def run(aws_kms_cmk, source_plaintext_filename):
2121
:param str aws_kms_cmk: AWS KMS CMK ARN to use to protect data keys
2222
:param str source_plaintext_filename: Path to plaintext file to encrypt
2323
"""
24-
# We assume that you can also write in the directory containing the plaintext file,
24+
# We assume that you can also write to the directory containing the plaintext file,
2525
# so that is where we will put all of the results.
2626
ciphertext_filename = source_plaintext_filename + ".encrypted"
2727
decrypted_filename = ciphertext_filename + ".decrypted"
@@ -35,13 +35,13 @@ def run(aws_kms_cmk, source_plaintext_filename):
3535
"the data you are handling": "is what you think it is",
3636
}
3737

38-
# Create the keyring that determines how your keys are protected.
38+
# Create the keyring that determines how your data keys are protected.
3939
keyring = KmsKeyring(generator_key_id=aws_kms_cmk)
4040

4141
# Open the files you want to work with.
4242
with open(source_plaintext_filename, "rb") as plaintext, open(ciphertext_filename, "wb") as ciphertext:
43-
# The streaming API provides you with a context manager
44-
# that you can read from similar to how you would read from a file.
43+
# The streaming API provides a context manager.
44+
# You can read from it just as you read from a file.
4545
with aws_encryption_sdk.stream(
4646
mode="encrypt", source=plaintext, encryption_context=encryption_context, keyring=keyring
4747
) as encryptor:
@@ -63,17 +63,17 @@ def run(aws_kms_cmk, source_plaintext_filename):
6363
# One benefit of using the streaming API is that
6464
# we can check the encryption context in the header before we start decrypting.
6565
#
66-
# Verify that the encryption context used in the decrypt operation matches what you expect.
66+
# Verify that the encryption context used in the decrypt operation includes the encryption context that you specified when encrypting.
6767
# The AWS Encryption SDK can add pairs, so don't require an exact match.
6868
#
6969
# In production, always use a meaningful encryption context.
7070
assert set(encryption_context.items()) <= set(decryptor.header.encryption_context.items())
7171

72-
# Now that we are confident that the message is what we think it should be,
72+
# Now that we are more confident that we will decrypt the right message,
7373
# we can start decrypting.
7474
for chunk in decryptor:
7575
decrypted.write(chunk)
7676

77-
# Verify that the "cycled" (encrypted then decrypted) plaintext
77+
# Verify that the decrypted plaintext
7878
# is identical to the original plaintext.
7979
assert filecmp.cmp(source_plaintext_filename, decrypted_filename)

0 commit comments

Comments
 (0)