44 DynamoDbItemEncryptorConfig_DynamoDbItemEncryptorConfig ,
55 Error_DynamoDbItemEncryptorException ,
66 EncryptItemOutput_EncryptItemOutput ,
7- DecryptItemOutput_DecryptItemOutput
7+ DecryptItemOutput_DecryptItemOutput ,
88)
99from aws_dbesdk_dynamodb .internaldafny .generated .AwsCryptographyDbEncryptionSdkStructuredEncryptionTypes import (
1010 CryptoAction_ENCRYPT__AND__SIGN ,
@@ -65,10 +65,12 @@ def Build(config: DynamoDbItemEncryptorConfig_DynamoDbItemEncryptorConfig):
6565 legacy_instance .encryption_context = maybe_encryption_context .value
6666 # Access the value property, not calling it as a function
6767 legacy_instance .attribute_actions = maybe_actions .value
68-
68+
6969 # Set the material description field name and signature field name
7070 # These values might be customized by the customer
71- if isinstance (legacy_override .encryptor , EncryptedClient ) and hasattr (legacy_override .encryptor , "_crypto_config" ):
71+ if isinstance (legacy_override .encryptor , EncryptedClient ) and hasattr (
72+ legacy_override .encryptor , "_crypto_config"
73+ ):
7274 # Get field names from the encryptor's crypto config
7375 crypto_config = legacy_override .encryptor ._crypto_config
7476 if hasattr (crypto_config , "material_description_field_name" ):
@@ -78,11 +80,9 @@ def Build(config: DynamoDbItemEncryptorConfig_DynamoDbItemEncryptorConfig):
7880 else :
7981 # Use default value if not explicitly set
8082 legacy_instance .materialDescriptionFieldName = _dafny .seq_of_chars ("*amzn-ddb-map-desc*" )
81-
83+
8284 if hasattr (crypto_config , "signature_field_name" ):
83- legacy_instance .signatureFieldName = _dafny .seq_of_chars (
84- crypto_config .signature_field_name
85- )
85+ legacy_instance .signatureFieldName = _dafny .seq_of_chars (crypto_config .signature_field_name )
8686 else :
8787 # Use default value if not explicitly set
8888 legacy_instance .signatureFieldName = _dafny .seq_of_chars ("*amzn-ddb-map-sig*" )
@@ -139,83 +139,79 @@ def legacyActions(attribute_actions_on_encrypt):
139139
140140 def EncryptItem (self , input ):
141141 """Encrypt an item using the legacy DynamoDB encryptor.
142-
142+
143143 Args:
144144 input: EncryptItemInput containing the plaintext item to encrypt
145-
145+
146146 Returns:
147147 Result containing the encrypted item or an error
148148 """
149149 try :
150150 # Get the plaintext item from the input
151151 plaintext_item = input .plaintextItem
152-
152+
153153 # Check policy
154154 if not self .policy .is_FORCE__LEGACY__ENCRYPT__ALLOW__LEGACY__DECRYPT :
155155 return Wrappers .Result_Failure (
156156 InternalLegacyOverride .CreateError ("Legacy policy does not support encrypt" )
157157 )
158-
158+
159159 # Use the encryptor to encrypt the item using the instance attributes
160160 encrypted_item = self .encryptor .encrypt_item (
161- plaintext_item ,
162- actions = self .attribute_actions ,
163- encryption_context = self .encryption_context
161+ plaintext_item , actions = self .attribute_actions , encryption_context = self .encryption_context
164162 )
165-
163+
166164 # Create the output with the encrypted item
167165 output = EncryptItemOutput_EncryptItemOutput (encrypted_item , Wrappers .Option_None ())
168166 return Wrappers .Result_Success (output )
169-
167+
170168 except Exception as e :
171169 # Return an appropriate error result with the exception details
172- return Wrappers .Result_Failure (
173- InternalLegacyOverride .CreateError (f"Error during encryption: { str (e )} " )
174- )
170+ return Wrappers .Result_Failure (InternalLegacyOverride .CreateError (f"Error during encryption: { str (e )} " ))
175171
176172 def DecryptItem (self , input ):
177173 """Decrypt an item using the legacy DynamoDB encryptor.
178174
179175 Args:
180176 input: DecryptItemInput containing the encrypted item to decrypt
181-
177+
182178 Returns:
183179 Result containing the decrypted item or an error
184180 """
185181 try :
186182 # Get the encrypted item from the input
187183 encrypted_item = input .encryptedItem
188-
184+
189185 # Check policy
190- if not (self .policy .is_FORCE__LEGACY__ENCRYPT__ALLOW__LEGACY__DECRYPT or
191- self .policy .is_FORBID__LEGACY__ENCRYPT__ALLOW__LEGACY__DECRYPT ):
186+ if not (
187+ self .policy .is_FORCE__LEGACY__ENCRYPT__ALLOW__LEGACY__DECRYPT
188+ or self .policy .is_FORBID__LEGACY__ENCRYPT__ALLOW__LEGACY__DECRYPT
189+ ):
192190 return Wrappers .Result_Failure (
193191 InternalLegacyOverride .CreateError ("Legacy policy does not support decrypt" )
194192 )
195-
193+
196194 # Validate that this is indeed a legacy item with the required fields
197- if not (encrypted_item .contains (self .materialDescriptionFieldName ) and
198- encrypted_item .contains (self .signatureFieldName )):
195+ if not (
196+ encrypted_item .contains (self .materialDescriptionFieldName )
197+ and encrypted_item .contains (self .signatureFieldName )
198+ ):
199199 return Wrappers .Result_Failure (
200200 InternalLegacyOverride .CreateError ("Item does not contain required legacy fields" )
201201 )
202-
202+
203203 # Use the encryptor to decrypt the item using the instance attributes
204204 decrypted_item = self .encryptor .decrypt_item (
205- encrypted_item ,
206- actions = self .attribute_actions ,
207- encryption_context = self .encryption_context
205+ encrypted_item , actions = self .attribute_actions , encryption_context = self .encryption_context
208206 )
209-
207+
210208 # Create the output with the decrypted item
211209 output = DecryptItemOutput_DecryptItemOutput (decrypted_item , Wrappers .Option_None ())
212210 return Wrappers .Result_Success (output )
213-
211+
214212 except Exception as e :
215213 # Return an appropriate error result with the exception details
216- return Wrappers .Result_Failure (
217- InternalLegacyOverride .CreateError (f"Error during decryption: { str (e )} " )
218- )
214+ return Wrappers .Result_Failure (InternalLegacyOverride .CreateError (f"Error during decryption: { str (e )} " ))
219215
220216 def __init__ (self ):
221217 super ().__init__ ()
@@ -240,23 +236,27 @@ def IsLegacyInput(input):
240236 return False
241237
242238 # Check if we're dealing with DecryptItemInput
243- if not hasattr (input , ' encryptedItem' ):
239+ if not hasattr (input , " encryptedItem" ):
244240 return False
245241
246242 # We need the instance with materialDescriptionFieldName and signatureFieldName
247- if not hasattr (input , ' legacyOverride' ) or not input .legacyOverride :
243+ if not hasattr (input , " legacyOverride" ) or not input .legacyOverride :
248244 return False
249245
250246 legacy_override = input .legacyOverride
251- if not hasattr (legacy_override , 'materialDescriptionFieldName' ) or not legacy_override .materialDescriptionFieldName :
247+ if (
248+ not hasattr (legacy_override , "materialDescriptionFieldName" )
249+ or not legacy_override .materialDescriptionFieldName
250+ ):
252251 return False
253- if not hasattr (legacy_override , ' signatureFieldName' ) or not legacy_override .signatureFieldName :
252+ if not hasattr (legacy_override , " signatureFieldName" ) or not legacy_override .signatureFieldName :
254253 return False
255254
256255 # Check if the item contains both required markers
257- return (input .encryptedItem .contains (legacy_override .materialDescriptionFieldName ) and
258- input .encryptedItem .contains (legacy_override .signatureFieldName ))
259-
256+ return input .encryptedItem .contains (
257+ legacy_override .materialDescriptionFieldName
258+ ) and input .encryptedItem .contains (legacy_override .signatureFieldName )
259+
260260 except :
261261 # If we encounter any error during detection, default to not using legacy
262262 return False
@@ -267,5 +267,4 @@ def CreateError(message):
267267 return Error_DynamoDbItemEncryptorException (message )
268268
269269
270-
271270aws_dbesdk_dynamodb .internaldafny .generated .InternalLegacyOverride .InternalLegacyOverride = InternalLegacyOverride
0 commit comments