20
20
ddb_to_dict ,
21
21
)
22
22
23
+
23
24
class ItemEncryptor :
24
25
"""Class providing item-level encryption for DynamoDB items / Python dictionaries."""
25
26
@@ -35,7 +36,7 @@ def __init__(
35
36
Parameters:
36
37
item_encryptor_config (DynamoDbItemEncryptorConfig): Encryption configuration object.
37
38
"""
38
- self ._internal_client = DynamoDbItemEncryptor (config = item_encryptor_config )
39
+ self ._internal_client = DynamoDbItemEncryptor (config = item_encryptor_config )
39
40
40
41
def encrypt_python_item (
41
42
self ,
@@ -60,15 +61,15 @@ def encrypt_python_item(
60
61
61
62
Parameters:
62
63
plaintext_dict_item (dict[str, Any]): A standard Python dictionary.
63
-
64
+
64
65
Returns:
65
66
EncryptItemOutput: Structure containing the following fields:
66
67
- `encrypted_item` (dict[str, Any]): The encrypted Python dictionary.
67
68
**Note:** The item was encrypted as DynamoDB JSON, then transformed to a Python dictionary.
68
69
- `parsed_header` (Optional[ParsedHeader]): The encrypted DynamoDB item's header (parsed `aws_dbe_head` value).
69
70
70
71
Example:
71
-
72
+
72
73
>>> plaintext_item = {
73
74
... 'some': 'data',
74
75
... 'more': 5
@@ -78,11 +79,13 @@ def encrypt_python_item(
78
79
>>> header = encrypt_output.parsed_header
79
80
"""
80
81
plaintext_ddb_item = dict_to_ddb (plaintext_dict_item )
81
- encrypted_ddb_item : EncryptItemOutput = self .encrypt_dynamodb_item (plaintext_ddb_item )
82
+ encrypted_ddb_item : EncryptItemOutput = self .encrypt_dynamodb_item (
83
+ plaintext_ddb_item
84
+ )
82
85
encrypted_dict_item = ddb_to_dict (encrypted_ddb_item .encrypted_item )
83
86
return EncryptItemOutput (
84
- encrypted_item = encrypted_dict_item ,
85
- parsed_header = encrypted_ddb_item .parsed_header
87
+ encrypted_item = encrypted_dict_item ,
88
+ parsed_header = encrypted_ddb_item .parsed_header ,
86
89
)
87
90
88
91
def encrypt_dynamodb_item (
@@ -101,15 +104,15 @@ def encrypt_dynamodb_item(
101
104
102
105
Parameters:
103
106
plaintext_dynamodb_item (dict[str, dict[str, Any]]): The item to encrypt formatted as DynamoDB JSON.
104
-
107
+
105
108
Returns:
106
109
EncryptItemOutput: Structure containing the following fields:
107
110
- `encrypted_item` (dict[str, Any]): A dictionary containing the encrypted DynamoDB item
108
111
formatted as DynamoDB JSON.
109
112
- `parsed_header` (Optional[ParsedHeader]): The encrypted DynamoDB item's header (`aws_dbe_head` value).
110
113
111
114
Example:
112
-
115
+
113
116
>>> plaintext_item = {
114
117
... 'some': {'S': 'data'},
115
118
... 'more': {'N': '5'}
@@ -119,9 +122,7 @@ def encrypt_dynamodb_item(
119
122
>>> header = encrypt_output.parsed_header
120
123
"""
121
124
return self .encrypt_item (
122
- EncryptItemInput (
123
- plaintext_item = plaintext_dynamodb_item
124
- )
125
+ EncryptItemInput (plaintext_item = plaintext_dynamodb_item )
125
126
)
126
127
127
128
def encrypt_item (
@@ -137,14 +138,14 @@ def encrypt_item(
137
138
Parameters:
138
139
encrypt_item_input (EncryptItemInput): Structure containing the following field:
139
140
- `plaintext_item` (dict[str, Any]): The item to encrypt formatted as DynamoDB JSON.
140
-
141
+
141
142
Returns:
142
143
EncryptItemOutput: Structure containing the following fields:
143
144
- `encrypted_item` (dict[str, Any]): The encrypted DynamoDB item formatted as DynamoDB JSON.
144
145
- `parsed_header` (Optional[ParsedHeader]): The encrypted DynamoDB item's header (`aws_dbe_head` value).
145
146
146
147
Example:
147
-
148
+
148
149
>>> plaintext_item = {
149
150
... 'some': {'S': 'data'},
150
151
... 'more': {'N': '5'}
@@ -182,15 +183,15 @@ def decrypt_python_item(
182
183
183
184
Parameters:
184
185
encrypted_dict_item (dict[str, Any]): A standard Python dictionary with encrypted values.
185
-
186
+
186
187
Returns:
187
188
DecryptItemOutput: Structure containing the following fields:
188
189
- `plaintext_item` (dict[str, Any]): The decrypted Python dictionary.
189
190
**Note:** The item was decrypted as DynamoDB JSON, then transformed to a Python dictionary.
190
191
- `parsed_header` (Optional[ParsedHeader]): The encrypted DynamoDB item's header (parsed `aws_dbe_head` value).
191
192
192
193
Example:
193
-
194
+
194
195
>>> encrypted_item = {
195
196
... 'some': b'ENCRYPTED_DATA',
196
197
... 'more': b'ENCRYPTED_DATA',
@@ -200,11 +201,13 @@ def decrypt_python_item(
200
201
>>> header = decrypt_output.parsed_header
201
202
"""
202
203
encrypted_ddb_item = dict_to_ddb (encrypted_dict_item )
203
- plaintext_ddb_item : DecryptItemOutput = self .decrypt_dynamodb_item (encrypted_ddb_item )
204
+ plaintext_ddb_item : DecryptItemOutput = self .decrypt_dynamodb_item (
205
+ encrypted_ddb_item
206
+ )
204
207
plaintext_dict_item = ddb_to_dict (plaintext_ddb_item .plaintext_item )
205
208
return DecryptItemOutput (
206
- plaintext_item = plaintext_dict_item ,
207
- parsed_header = plaintext_ddb_item .parsed_header
209
+ plaintext_item = plaintext_dict_item ,
210
+ parsed_header = plaintext_ddb_item .parsed_header ,
208
211
)
209
212
210
213
def decrypt_dynamodb_item (
@@ -223,14 +226,14 @@ def decrypt_dynamodb_item(
223
226
224
227
Parameters:
225
228
encrypted_ddb_item (dict[str, dict[str, Any]]): The item to decrypt formatted as DynamoDB JSON.
226
-
229
+
227
230
Returns:
228
231
DecryptItemOutput: Structure containing the following fields:
229
232
- `plaintext_item` (dict[str, Any]): The plaintext DynamoDB item formatted as DynamoDB JSON.
230
233
- `parsed_header` (Optional[ParsedHeader]): The decrypted DynamoDB item's header (`aws_dbe_head` value).
231
234
232
235
Example:
233
-
236
+
234
237
>>> encrypted_item = {
235
238
... 'some': {'B': b'ENCRYPTED_DATA'},
236
239
... 'more': {'B': b'ENCRYPTED_DATA'}
@@ -240,9 +243,7 @@ def decrypt_dynamodb_item(
240
243
>>> header = decrypt_output.parsed_header
241
244
"""
242
245
return self .decrypt_item (
243
- DecryptItemInput (
244
- encrypted_item = encrypted_dynamodb_item
245
- )
246
+ DecryptItemInput (encrypted_item = encrypted_dynamodb_item )
246
247
)
247
248
248
249
def decrypt_item (
@@ -258,14 +259,14 @@ def decrypt_item(
258
259
Parameters:
259
260
decrypt_item_input (DecryptItemInput): Structure containing the following field:
260
261
- `encrypted_item` (dict[str, Any]): The item to decrypt formatted as DynamoDB JSON.
261
-
262
+
262
263
Returns:
263
264
DecryptItemOutput: Structure containing the following fields:
264
265
- `plaintext_item` (dict[str, Any]): The decrypted DynamoDB item formatted as DynamoDB JSON.
265
266
- `parsed_header` (Optional[ParsedHeader]): The decrypted DynamoDB item's header (`aws_dbe_head` value).
266
267
267
268
Example:
268
-
269
+
269
270
>>> encrypted_item = {
270
271
... 'some': {'B': b'ENCRYPTED_DATA'},
271
272
... 'more': {'B': b'ENCRYPTED_DATA'}
0 commit comments