Skip to content

Commit b82250e

Browse files
author
Lucas McDonald
committed
m
1 parent 1e42a75 commit b82250e

File tree

1 file changed

+81
-67
lines changed
  • DynamoDbEncryption/runtimes/python/src/aws_dbesdk_dynamodb/encrypted

1 file changed

+81
-67
lines changed

DynamoDbEncryption/runtimes/python/src/aws_dbesdk_dynamodb/encrypted/item.py

Lines changed: 81 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def encrypt_python_item(
5252
then return the encrypted Python dictionary.
5353
5454
See the boto3 documentation for details on Python/DynamoDB type transfomations:
55+
5556
https://boto3.amazonaws.com/v1/documentation/api/latest/_modules/boto3/dynamodb/types.html
5657
5758
boto3 DynamoDB Tables and Resources expect items formatted as native Python dictionaries.
@@ -94,29 +95,32 @@ def encrypt_dynamodb_item(
9495
Encrypt DynamoDB-formatted JSON.
9596
9697
boto3 DynamoDB clients expect items formatted as DynamoDB JSON:
98+
9799
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Programming.LowLevelAPI.html
100+
98101
Use this method to encrypt an item if you intend to pass the encrypted item
99-
to a boto3 DynamoDB client to store it.
102+
to a boto3 DynamoDB client to store it.
100103
(Alternatively, you can use this library's EncryptedClient interface
101-
to transparently encrypt items without an intermediary ItemEncryptor.)
104+
to transparently encrypt items without an intermediary ItemEncryptor.)
102105
103106
Args:
104107
plaintext_dynamodb_item (dict[str, dict[str, Any]]): The item to encrypt formatted as DynamoDB JSON.
105108
106109
Returns:
107110
EncryptItemOutput: Structure containing the following fields:
108-
- `encrypted_item` (dict[str, Any]): A dictionary containing the encrypted DynamoDB item
109-
formatted as DynamoDB JSON.
110-
- `parsed_header` (Optional[ParsedHeader]): The encrypted DynamoDB item's header (`aws_dbe_head` value).
111+
112+
- encrypted_item (dict[str, Any]): A dictionary containing the encrypted DynamoDB item
113+
formatted as DynamoDB JSON.
114+
- parsed_header (Optional[ParsedHeader]): The encrypted DynamoDB item's header (`aws_dbe_head` value).
111115
112116
Example:
113-
>>> plaintext_item = {
114-
... 'some': {'S': 'data'},
115-
... 'more': {'N': '5'}
116-
... }
117-
>>> encrypt_output = item_encryptor.encrypt_dynamodb_item(plaintext_item)
118-
>>> encrypted_item = encrypt_output.encrypted_item
119-
>>> header = encrypt_output.parsed_header
117+
>>> plaintext_item = {
118+
... 'some': {'S': 'data'},
119+
... 'more': {'N': '5'}
120+
... }
121+
>>> encrypt_output = item_encryptor.encrypt_dynamodb_item(plaintext_item)
122+
>>> encrypted_item = encrypt_output.encrypted_item
123+
>>> header = encrypt_output.parsed_header
120124
121125
"""
122126
return self.encrypt_item(EncryptItemInput(plaintext_item=plaintext_dynamodb_item))
@@ -129,30 +133,33 @@ def encrypt_item(
129133
Encrypt a DynamoDB item.
130134
131135
The input item should contain a dictionary formatted as DynamoDB JSON:
136+
132137
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Programming.LowLevelAPI.html
133138
134139
Args:
135140
encrypt_item_input (EncryptItemInput): Structure containing the following field:
136-
- `plaintext_item` (dict[str, Any]): The item to encrypt formatted as DynamoDB JSON.
141+
142+
- plaintext_item (dict[str, Any]): The item to encrypt formatted as DynamoDB JSON.
137143
138144
Returns:
139145
EncryptItemOutput: Structure containing the following fields:
140-
- `encrypted_item` (dict[str, Any]): The encrypted DynamoDB item formatted as DynamoDB JSON.
141-
- `parsed_header` (Optional[ParsedHeader]): The encrypted DynamoDB item's header
142-
(`aws_dbe_head` value).
146+
147+
- encrypted_item (dict[str, Any]): The encrypted DynamoDB item formatted as DynamoDB JSON.
148+
- parsed_header (Optional[ParsedHeader]): The encrypted DynamoDB item's header
149+
(`aws_dbe_head` value).
143150
144151
Example:
145-
>>> plaintext_item = {
146-
... 'some': {'S': 'data'},
147-
... 'more': {'N': '5'}
148-
... }
149-
>>> encrypt_output = item_encryptor.encrypt_item(
150-
... EncryptItemInput(
151-
... plaintext_ddb_item = plaintext_item
152-
... )
153-
... )
154-
>>> encrypted_item = encrypt_output.encrypted_item
155-
>>> header = encrypt_output.parsed_header
152+
>>> plaintext_item = {
153+
... 'some': {'S': 'data'},
154+
... 'more': {'N': '5'}
155+
... }
156+
>>> encrypt_output = item_encryptor.encrypt_item(
157+
... EncryptItemInput(
158+
... plaintext_ddb_item = plaintext_item
159+
... )
160+
... )
161+
>>> encrypted_item = encrypt_output.encrypted_item
162+
>>> header = encrypt_output.parsed_header
156163
157164
"""
158165
return self._internal_client.encrypt_item(encrypt_item_input)
@@ -165,37 +172,39 @@ def decrypt_python_item(
165172
Decrypt a Python dictionary.
166173
167174
This method will transform the Python dictionary into DynamoDB JSON,
168-
decrypt the DynamoDB JSON,
169-
transform the plaintext DynamoDB JSON into a plaintext Python dictionary,
170-
then return the plaintext Python dictionary.
175+
decrypt the DynamoDB JSON,
176+
transform the plaintext DynamoDB JSON into a plaintext Python dictionary,
177+
then return the plaintext Python dictionary.
171178
172179
See the boto3 documentation for details on Python/DynamoDB type transfomations:
180+
173181
https://boto3.amazonaws.com/v1/documentation/api/latest/_modules/boto3/dynamodb/types.html
174182
175183
boto3 DynamoDB Tables and Resources return items formatted as native Python dictionaries.
176184
Use this method to decrypt an item if you retrieve the encrypted item
177-
from a boto3 DynamoDB Table or Resource interface.
185+
from a boto3 DynamoDB Table or Resource interface.
178186
(Alternatively, you can use this library's EncryptedTable or EncryptedResource interfaces
179-
to transparently decrypt items without an intermediary ItemEncryptor.)
187+
to transparently decrypt items without an intermediary ItemEncryptor.)
180188
181189
Args:
182190
encrypted_dict_item (dict[str, Any]): A standard Python dictionary with encrypted values.
183191
184192
Returns:
185193
DecryptItemOutput: Structure containing the following fields:
186-
- `plaintext_item` (dict[str, Any]): The decrypted Python dictionary.
187-
**Note:** The item was decrypted as DynamoDB JSON, then transformed to a Python dictionary.
188-
- `parsed_header` (Optional[ParsedHeader]): The encrypted DynamoDB item's header
194+
195+
- plaintext_item (dict[str, Any]): The decrypted Python dictionary.
196+
**Note:** The item was decrypted as DynamoDB JSON, then transformed to a Python dictionary.
197+
- parsed_header (Optional[ParsedHeader]): The encrypted DynamoDB item's header
189198
(parsed `aws_dbe_head` value).
190199
191200
Example:
192-
>>> encrypted_item = {
193-
... 'some': b'ENCRYPTED_DATA',
194-
... 'more': b'ENCRYPTED_DATA',
195-
... }
196-
>>> decrypt_output = item_encryptor.decrypt_python_item(encrypted_item)
197-
>>> plaintext_item = decrypt_output.plaintext_item
198-
>>> header = decrypt_output.parsed_header
201+
>>> encrypted_item = {
202+
... 'some': b'ENCRYPTED_DATA',
203+
... 'more': b'ENCRYPTED_DATA',
204+
... }
205+
>>> decrypt_output = item_encryptor.decrypt_python_item(encrypted_item)
206+
>>> plaintext_item = decrypt_output.plaintext_item
207+
>>> header = decrypt_output.parsed_header
199208
200209
"""
201210
encrypted_ddb_item = dict_to_ddb(encrypted_dict_item)
@@ -211,28 +220,31 @@ def decrypt_dynamodb_item(
211220
Decrypt DynamoDB-formatted JSON.
212221
213222
boto3 DynamoDB clients return items formatted as DynamoDB JSON:
223+
214224
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Programming.LowLevelAPI.html
225+
215226
Use this method to decrypt an item if you retrieved the encrypted item
216-
from a boto3 DynamoDB client.
227+
from a boto3 DynamoDB client.
217228
(Alternatively, you can use this library's EncryptedClient interface
218-
to transparently decrypt items without an intermediary ItemEncryptor.)
229+
to transparently decrypt items without an intermediary ItemEncryptor.)
219230
220231
Args:
221232
encrypted_dynamodb_item (dict[str, dict[str, Any]]): The item to decrypt formatted as DynamoDB JSON.
222233
223234
Returns:
224235
DecryptItemOutput: Structure containing the following fields:
225-
- `plaintext_item` (dict[str, Any]): The plaintext DynamoDB item formatted as DynamoDB JSON.
226-
- `parsed_header` (Optional[ParsedHeader]): The decrypted DynamoDB item's header (`aws_dbe_head` value).
236+
237+
- plaintext_item (dict[str, Any]): The plaintext DynamoDB item formatted as DynamoDB JSON.
238+
- parsed_header (Optional[ParsedHeader]): The decrypted DynamoDB item's header (`aws_dbe_head` value).
227239
228240
Example:
229-
>>> encrypted_item = {
230-
... 'some': {'B': b'ENCRYPTED_DATA'},
231-
... 'more': {'B': b'ENCRYPTED_DATA'}
232-
... }
233-
>>> decrypt_output = item_encryptor.decrypt_dynamodb_item(encrypted_item)
234-
>>> plaintext_item = decrypt_output.plaintext_item
235-
>>> header = decrypt_output.parsed_header
241+
>>> encrypted_item = {
242+
... 'some': {'B': b'ENCRYPTED_DATA'},
243+
... 'more': {'B': b'ENCRYPTED_DATA'}
244+
... }
245+
>>> decrypt_output = item_encryptor.decrypt_dynamodb_item(encrypted_item)
246+
>>> plaintext_item = decrypt_output.plaintext_item
247+
>>> header = decrypt_output.parsed_header
236248
237249
"""
238250
return self.decrypt_item(DecryptItemInput(encrypted_item=encrypted_dynamodb_item))
@@ -245,29 +257,31 @@ def decrypt_item(
245257
Decrypt a DynamoDB item.
246258
247259
The input item should contain a dictionary formatted as DynamoDB JSON:
260+
248261
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Programming.LowLevelAPI.html
249262
250263
Args:
251264
decrypt_item_input (DecryptItemInput): Structure containing the following field:
252-
- `encrypted_item` (dict[str, Any]): The item to decrypt formatted as DynamoDB JSON.
265+
- encrypted_item (dict[str, Any]): The item to decrypt formatted as DynamoDB JSON.
253266
254267
Returns:
255268
DecryptItemOutput: Structure containing the following fields:
256-
- `plaintext_item` (dict[str, Any]): The decrypted DynamoDB item formatted as DynamoDB JSON.
257-
- `parsed_header` (Optional[ParsedHeader]): The decrypted DynamoDB item's header (`aws_dbe_head` value).
269+
270+
- plaintext_item (dict[str, Any]): The decrypted DynamoDB item formatted as DynamoDB JSON.
271+
- parsed_header (Optional[ParsedHeader]): The decrypted DynamoDB item's header (`aws_dbe_head` value).
258272
259273
Example:
260-
>>> encrypted_item = {
261-
... 'some': {'B': b'ENCRYPTED_DATA'},
262-
... 'more': {'B': b'ENCRYPTED_DATA'}
263-
... }
264-
>>> decrypted_item = item_encryptor.decrypt_item(
265-
... DecryptItemInput(
266-
... encrypted_item = encrypted_item,
267-
... )
268-
... )
269-
>>> plaintext_item = decrypted_item.plaintext_item
270-
>>> header = decrypted_item.parsed_header
274+
>>> encrypted_item = {
275+
... 'some': {'B': b'ENCRYPTED_DATA'},
276+
... 'more': {'B': b'ENCRYPTED_DATA'}
277+
... }
278+
>>> decrypted_item = item_encryptor.decrypt_item(
279+
... DecryptItemInput(
280+
... encrypted_item = encrypted_item,
281+
... )
282+
... )
283+
>>> plaintext_item = decrypted_item.plaintext_item
284+
>>> header = decrypted_item.parsed_header
271285
272286
"""
273287
return self._internal_client.decrypt_item(decrypt_item_input)

0 commit comments

Comments
 (0)