1
1
package software .amazon .cryptography .dbencryptionsdk .dynamodb .itemencryptor .internaldafny .legacy ;
2
2
3
+ /**
4
+ * This file does *NOT* import a lot of things.
5
+ * This is because it is dealing with converting
6
+ * between different versions of the same name.
7
+ * The DynamoDbItemEncryptor module has Dafny and Java versions
8
+ * of the same type.
9
+ * This means that `EncryptItemOutput` for example
10
+ * needs to be disambiguated between the Dafny version and the Java version.
11
+ * In order to make it clearer at each call-site exactly what is happening
12
+ * the full import is used.
13
+ * IDEs tend to fight this so I'm sorry.
14
+ */
15
+
16
+ import StandardLibraryInternal .InternalResult ;
3
17
import Wrappers_Compile .Option ;
4
18
import Wrappers_Compile .Result ;
5
19
import com .amazonaws .services .dynamodbv2 .datamodeling .encryption .DynamoDBEncryptor ;
16
30
import software .amazon .cryptography .dbencryptionsdk .dynamodb .internaldafny .types .LegacyPolicy ;
17
31
import software .amazon .cryptography .dbencryptionsdk .dynamodb .itemencryptor .ToNative ;
18
32
import software .amazon .cryptography .dbencryptionsdk .dynamodb .itemencryptor .internaldafny .types .Error ;
19
- /**
20
- * This file does *NOT* import a lot of things.
21
- * This is because it is dealing with converting
22
- * between different versions of the same name.
23
- * The DynamoDbItemEncryptor module has Dafny and Java versions
24
- * of the same type.
25
- * This means that `EncryptItemOutput` for example
26
- * needs to be disambiguated between the Dafny version and the Java version.
27
- * In order to make it clearer at each call-site exactly what is happening
28
- * the full import is used.
29
- * IDEs tend to fight this so I'm sorry.
30
- */
31
-
32
33
import software .amazon .cryptography .dbencryptionsdk .structuredencryption .internaldafny .types .CryptoAction ;
33
34
34
- public class InternalLegacyOverride {
35
+ public class InternalLegacyOverride extends _ExternBase_InternalLegacyOverride {
35
36
36
37
private DynamoDBEncryptor encryptor ;
37
38
private Map <String , Set <EncryptionFlags >> actions ;
@@ -69,7 +70,7 @@ public static TypeDescriptor<InternalLegacyOverride> _typeDescriptor() {
69
70
);
70
71
}
71
72
72
- public Boolean IsLegacyInput (
73
+ public boolean IsLegacyInput (
73
74
software .amazon .cryptography .dbencryptionsdk .dynamodb .itemencryptor .internaldafny .types .DecryptItemInput input
74
75
) {
75
76
//= specification/dynamodb-encryption-client/decrypt-item.md#determining-legacy-items
@@ -94,7 +95,9 @@ > EncryptItem(
94
95
) {
95
96
// Precondition: Policy MUST allow the caller to encrypt.
96
97
if (!_policy .is_FORCE__LEGACY__ENCRYPT__ALLOW__LEGACY__DECRYPT ()) {
97
- return createFailure ("Legacy Policy does not support encrypt." );
98
+ return CreateEncryptItemFailure (
99
+ createError ("Legacy Policy does not support encrypt." )
100
+ );
98
101
}
99
102
100
103
try {
@@ -124,9 +127,9 @@ > EncryptItem(
124
127
software .amazon .cryptography .dbencryptionsdk .dynamodb .itemencryptor .ToDafny .EncryptItemOutput (
125
128
nativeOutput
126
129
);
127
- return Result . create_Success (dafnyOutput );
130
+ return CreateEncryptItemSuccess (dafnyOutput );
128
131
} catch (Exception ex ) {
129
- return Result . create_Failure (Error .create_Opaque (ex ));
132
+ return CreateEncryptItemFailure (Error .create_Opaque (ex ));
130
133
}
131
134
}
132
135
@@ -146,7 +149,9 @@ > DecryptItem(
146
149
!_policy .is_FORCE__LEGACY__ENCRYPT__ALLOW__LEGACY__DECRYPT () &&
147
150
!_policy .is_FORBID__LEGACY__ENCRYPT__ALLOW__LEGACY__DECRYPT ()
148
151
) {
149
- return createFailure ("Legacy Policy does not support decrypt." );
152
+ return CreateDecryptItemFailure (
153
+ createError ("Legacy Policy does not support decrypt." )
154
+ );
150
155
}
151
156
try {
152
157
Map <
@@ -175,9 +180,9 @@ > DecryptItem(
175
180
software .amazon .cryptography .dbencryptionsdk .dynamodb .itemencryptor .ToDafny .DecryptItemOutput (
176
181
nativeOutput
177
182
);
178
- return Result . create_Success (dafnyOutput );
183
+ return CreateDecryptItemSuccess (dafnyOutput );
179
184
} catch (Exception ex ) {
180
- return Result . create_Failure (Error .create_Opaque (ex ));
185
+ return CreateDecryptItemFailure (Error .create_Opaque (ex ));
181
186
}
182
187
}
183
188
@@ -186,7 +191,7 @@ public static Result<Option<InternalLegacyOverride>, Error> Build(
186
191
) {
187
192
// Check for early return (Postcondition): If there is no legacyOverride there is nothing to do.
188
193
if (encryptorConfig .dtor_legacyOverride ().is_None ()) {
189
- return Result . create_Success ( Option . create_None ());
194
+ return CreateBuildSuccess ( CreateInternalLegacyOverrideNone ());
190
195
}
191
196
final software .amazon .cryptography .dbencryptionsdk .dynamodb .internaldafny .types .LegacyOverride legacyOverride =
192
197
encryptorConfig .dtor_legacyOverride ().dtor_value ();
@@ -198,43 +203,48 @@ public static Result<Option<InternalLegacyOverride>, Error> Build(
198
203
199
204
// Precondition: The encryptor MUST be a DynamoDBEncryptor
200
205
if (!isDynamoDBEncryptor (maybeEncryptor )) {
201
- return createFailure ("Legacy encryptor is not supported" );
206
+ return CreateBuildFailure (
207
+ createError ("Legacy encryptor is not supported" )
208
+ );
202
209
}
203
210
// Preconditions: MUST be able to create valid encryption context
204
- final Result <EncryptionContext , Error > maybeEncryptionContext =
211
+ final InternalResult <EncryptionContext , Error > maybeEncryptionContext =
205
212
legacyEncryptionContext (encryptorConfig );
206
- if (maybeEncryptionContext .is_Failure ()) {
207
- return Result . create_Failure (maybeEncryptionContext .dtor_error ());
213
+ if (maybeEncryptionContext .isFailure ()) {
214
+ return CreateBuildFailure (maybeEncryptionContext .error ());
208
215
}
209
216
// Precondition: All actions MUST be supported types
210
- final Result <Map <String , Set <EncryptionFlags >>, Error > maybeActions =
211
- legacyActions (legacyOverride .dtor_attributeActionsOnEncrypt ());
212
- if (maybeActions .is_Failure ()) {
213
- return Result .create_Failure (maybeEncryptionContext .dtor_error ());
217
+ final InternalResult <
218
+ Map <String , Set <EncryptionFlags >>,
219
+ Error
220
+ > maybeActions = legacyActions (
221
+ legacyOverride .dtor_attributeActionsOnEncrypt ()
222
+ );
223
+ if (maybeActions .isFailure ()) {
224
+ return CreateBuildFailure (maybeEncryptionContext .error ());
214
225
}
215
226
216
227
final InternalLegacyOverride internalLegacyOverride =
217
228
new InternalLegacyOverride (
218
229
(DynamoDBEncryptor ) maybeEncryptor ,
219
- maybeActions .dtor_value (),
220
- maybeEncryptionContext .dtor_value (),
230
+ maybeActions .value (),
231
+ maybeEncryptionContext .value (),
221
232
legacyOverride .dtor_policy ()
222
233
);
223
234
224
- return Result .create_Success (Option .create_Some (internalLegacyOverride ));
235
+ return CreateBuildSuccess (
236
+ CreateInternalLegacyOverrideSome (internalLegacyOverride )
237
+ );
225
238
}
226
239
227
240
// Everything below this point is an implementation detail
228
241
229
- public static < T > Result < T , Error > createFailure (String message ) {
242
+ public static Error createError (String message ) {
230
243
final DafnySequence <Character > dafnyMessage =
231
244
software .amazon .smithy .dafny .conversion .ToDafny .Simple .CharacterSequence (
232
245
message
233
246
);
234
- final Error dafnyEx = Error .create_DynamoDbItemEncryptorException (
235
- dafnyMessage
236
- );
237
- return Result .create_Failure (dafnyEx );
247
+ return Error .create_DynamoDbItemEncryptorException (dafnyMessage );
238
248
}
239
249
240
250
public static boolean isDynamoDBEncryptor (
@@ -253,7 +263,10 @@ public static DafnySequence<Character> ToDafnyString(String s) {
253
263
);
254
264
}
255
265
256
- public static Result <EncryptionContext , Error > legacyEncryptionContext (
266
+ public static InternalResult <
267
+ EncryptionContext ,
268
+ Error
269
+ > legacyEncryptionContext (
257
270
software .amazon .cryptography .dbencryptionsdk .dynamodb .itemencryptor .internaldafny .types .DynamoDbItemEncryptorConfig config
258
271
) {
259
272
try {
@@ -272,13 +285,16 @@ public static Result<EncryptionContext, Error> legacyEncryptionContext(
272
285
.build ()
273
286
: encryptionContextBuilder .build ();
274
287
275
- return Result . create_Success (encryptionContext );
288
+ return InternalResult . success (encryptionContext );
276
289
} catch (Exception ex ) {
277
- return Result . create_Failure (Error .create_Opaque (ex ));
290
+ return InternalResult . failure (Error .create_Opaque (ex ));
278
291
}
279
292
}
280
293
281
- public static Result <Map <String , Set <EncryptionFlags >>, Error > legacyActions (
294
+ public static InternalResult <
295
+ Map <String , Set <EncryptionFlags >>,
296
+ Error
297
+ > legacyActions (
282
298
DafnyMap <
283
299
? extends DafnySequence <? extends Character >,
284
300
? extends CryptoAction
@@ -311,14 +327,14 @@ public static Result<Map<String, Set<EncryptionFlags>>, Error> legacyActions(
311
327
}
312
328
};
313
329
attributeActionsOnEncrypt .forEach (buildLegacyActions );
314
- return Result . create_Success (legacyActions );
330
+ return InternalResult . success (legacyActions );
315
331
} catch (IllegalArgumentException ex ) {
316
332
final Error dafnyEx = Error .create_DynamoDbItemEncryptorException (
317
333
ToDafnyString (ex .getMessage ())
318
334
);
319
- return Result . create_Failure (dafnyEx );
335
+ return InternalResult . failure (dafnyEx );
320
336
} catch (Exception ex ) {
321
- return Result . create_Failure (Error .create_Opaque (ex ));
337
+ return InternalResult . failure (Error .create_Opaque (ex ));
322
338
}
323
339
}
324
340
0 commit comments