13
13
* IDEs tend to fight this so I'm sorry.
14
14
*/
15
15
16
+ import Dafny .Aws .Cryptography .Primitives .Types .InternalResult ;
16
17
import software .amazon .cryptography .dbencryptionsdk .structuredencryption .internaldafny .types .CryptoAction ;
17
18
import software .amazon .cryptography .dbencryptionsdk .dynamodb .itemencryptor .internaldafny .types .Error ;
18
19
import software .amazon .cryptography .dbencryptionsdk .dynamodb .internaldafny .types .LegacyPolicy ;
26
27
import dafny .TypeDescriptor ;
27
28
import software .amazon .awssdk .core .SdkBytes ;
28
29
import software .amazon .cryptography .dbencryptionsdk .dynamodb .ILegacyDynamoDbEncryptor ;
29
- import software .amazon .cryptography .dbencryptionsdk .dynamodb .itemencryptor .ToNative ;
30
30
31
31
import java .util .*;
32
32
import java .util .function .BiConsumer ;
33
33
import java .util .stream .Collectors ;
34
34
35
- public class InternalLegacyOverride {
35
+ public class InternalLegacyOverride extends _ExternBase_InternalLegacyOverride {
36
36
private DynamoDBEncryptor encryptor ;
37
37
private Map <String , Set <EncryptionFlags >> actions ;
38
38
private EncryptionContext encryptionContext ;
@@ -74,7 +74,7 @@ public static TypeDescriptor<InternalLegacyOverride> _typeDescriptor() {
74
74
return TypeDescriptor .referenceWithInitializer (InternalLegacyOverride .class , () -> null );
75
75
}
76
76
77
- public Boolean IsLegacyInput (
77
+ public boolean IsLegacyInput (
78
78
software .amazon .cryptography .dbencryptionsdk .dynamodb .itemencryptor .internaldafny .types .DecryptItemInput input
79
79
) {
80
80
//= specification/dynamodb-encryption-client/decrypt-item.md#determining-legacy-items
@@ -95,7 +95,7 @@ public Result<software.amazon.cryptography.dbencryptionsdk.dynamodb.itemencrypto
95
95
96
96
// Precondition: Policy MUST allow the caller to encrypt.
97
97
if (!_policy .is_FORCE__LEGACY__ENCRYPT__ALLOW__LEGACY__DECRYPT ()) {
98
- return createFailure ( "Legacy Policy does not support encrypt." );
98
+ return CreateEncryptItemFailure ( createError ( "Legacy Policy does not support encrypt." ) );
99
99
}
100
100
101
101
try {
@@ -135,9 +135,9 @@ public Result<software.amazon.cryptography.dbencryptionsdk.dynamodb.itemencrypto
135
135
.itemencryptor
136
136
.ToDafny
137
137
.EncryptItemOutput (nativeOutput );
138
- return Result . create_Success (dafnyOutput );
138
+ return CreateEncryptItemSuccess (dafnyOutput );
139
139
} catch (Exception ex ) {
140
- return Result . create_Failure (Error .create_Opaque (ex ));
140
+ return CreateEncryptItemFailure (Error .create_Opaque (ex ));
141
141
}
142
142
}
143
143
@@ -152,7 +152,7 @@ public Result<software.amazon.cryptography.dbencryptionsdk.dynamodb.itemencrypto
152
152
//# and the input item [is an item written in the legacy format](#determining-legacy-items),
153
153
//# this operation MUST fail.
154
154
if (!_policy .is_FORCE__LEGACY__ENCRYPT__ALLOW__LEGACY__DECRYPT () && !_policy .is_FORBID__LEGACY__ENCRYPT__ALLOW__LEGACY__DECRYPT ()) {
155
- return createFailure ( "Legacy Policy does not support decrypt." );
155
+ return CreateDecryptItemFailure ( createError ( "Legacy Policy does not support decrypt." ) );
156
156
}
157
157
try {
158
158
Map <String , software .amazon .awssdk .services .dynamodb .model .AttributeValue > encryptedItem = software
@@ -191,9 +191,9 @@ public Result<software.amazon.cryptography.dbencryptionsdk.dynamodb.itemencrypto
191
191
.itemencryptor
192
192
.ToDafny
193
193
.DecryptItemOutput (nativeOutput );
194
- return Result . create_Success (dafnyOutput );
194
+ return CreateDecryptItemSuccess (dafnyOutput );
195
195
} catch (Exception ex ) {
196
- return Result . create_Failure (Error .create_Opaque (ex ));
196
+ return CreateDecryptItemFailure (Error .create_Opaque (ex ));
197
197
}
198
198
}
199
199
@@ -203,7 +203,7 @@ public static Result<Option<InternalLegacyOverride>, Error> Build(
203
203
204
204
// Check for early return (Postcondition): If there is no legacyOverride there is nothing to do.
205
205
if (encryptorConfig .dtor_legacyOverride ().is_None ()) {
206
- return Result . create_Success ( Option . create_None ());
206
+ return CreateBuildSuccess ( CreateInternalLegacyOverrideNone ());
207
207
}
208
208
final software .amazon .cryptography .dbencryptionsdk .dynamodb .internaldafny .types .LegacyOverride legacyOverride = encryptorConfig
209
209
.dtor_legacyOverride ()
@@ -214,35 +214,34 @@ public static Result<Option<InternalLegacyOverride>, Error> Build(
214
214
215
215
// Precondition: The encryptor MUST be a DynamoDBEncryptor
216
216
if (!isDynamoDBEncryptor (maybeEncryptor )) {
217
- return createFailure ( "Legacy encryptor is not supported" );
217
+ return CreateBuildFailure ( createError ( "Legacy encryptor is not supported" ) );
218
218
}
219
219
// Preconditions: MUST be able to create valid encryption context
220
220
final Result <EncryptionContext , Error > maybeEncryptionContext = legacyEncryptionContext (encryptorConfig );
221
221
if (maybeEncryptionContext .is_Failure ()) {
222
- return Result . create_Failure (maybeEncryptionContext .dtor_error ());
222
+ return CreateBuildFailure (maybeEncryptionContext .dtor_error ());
223
223
}
224
224
// Precondition: All actions MUST be supported types
225
- final Result <Map <String , Set <EncryptionFlags >>, Error > maybeActions = legacyActions (legacyOverride .dtor_attributeActionsOnEncrypt ());
226
- if (maybeActions .is_Failure ()) {
227
- return Result . create_Failure (maybeEncryptionContext .dtor_error ());
225
+ final InternalResult <Map <String , Set <EncryptionFlags >>, Error > maybeActions = legacyActions (legacyOverride .dtor_attributeActionsOnEncrypt ());
226
+ if (maybeActions .isFailure ()) {
227
+ return CreateBuildFailure (maybeEncryptionContext .dtor_error ());
228
228
}
229
229
230
230
final InternalLegacyOverride internalLegacyOverride = new InternalLegacyOverride (
231
231
(DynamoDBEncryptor ) maybeEncryptor ,
232
- maybeActions .dtor_value (),
232
+ maybeActions .value (),
233
233
maybeEncryptionContext .dtor_value (),
234
234
legacyOverride .dtor_policy ()
235
235
);
236
236
237
- return Result . create_Success ( Option . create_Some (internalLegacyOverride ));
237
+ return CreateBuildSuccess ( CreateInternalLegacyOverrideSome (internalLegacyOverride ));
238
238
}
239
239
240
240
// Everything below this point is an implementation detail
241
241
242
- public static < T > Result < T , Error > createFailure (String message ) {
242
+ public static Error createError (String message ) {
243
243
final DafnySequence <Character > dafnyMessage = software .amazon .smithy .dafny .conversion .ToDafny .Simple .CharacterSequence (message );
244
- final Error dafnyEx = Error .create_DynamoDbItemEncryptorException (dafnyMessage );
245
- return Result .create_Failure (dafnyEx );
244
+ return Error .create_DynamoDbItemEncryptorException (dafnyMessage );
246
245
}
247
246
248
247
public static boolean isDynamoDBEncryptor (
@@ -262,7 +261,7 @@ public static DafnySequence<Character> ToDafnyString(String s)
262
261
return software .amazon .smithy .dafny .conversion .ToDafny .Simple .CharacterSequence (s );
263
262
}
264
263
265
- public static Result <EncryptionContext , Error > legacyEncryptionContext (
264
+ public static InternalResult <EncryptionContext , Error > legacyEncryptionContext (
266
265
software .amazon .cryptography .dbencryptionsdk .dynamodb .itemencryptor .internaldafny .types .DynamoDbItemEncryptorConfig config
267
266
) {
268
267
try {
@@ -275,13 +274,13 @@ public static Result<EncryptionContext, Error> legacyEncryptionContext(
275
274
? encryptionContextBuilder .withRangeKeyName (ToNativeString (config .dtor_sortKeyName ().dtor_value ())).build ()
276
275
: encryptionContextBuilder .build ();
277
276
278
- return Result . create_Success (encryptionContext );
277
+ return InternalResult . success (encryptionContext );
279
278
} catch (Exception ex ) {
280
- return Result . create_Failure (Error .create_Opaque (ex ));
279
+ return InternalResult . failure (Error .create_Opaque (ex ));
281
280
}
282
281
}
283
282
284
- public static Result <Map <String , Set <EncryptionFlags >>, Error > legacyActions (
283
+ public static InternalResult <Map <String , Set <EncryptionFlags >>, Error > legacyActions (
285
284
DafnyMap <? extends DafnySequence <? extends Character >, ? extends CryptoAction > attributeActionsOnEncrypt
286
285
) {
287
286
try {
@@ -303,12 +302,12 @@ public static Result<Map<String, Set<EncryptionFlags>>, Error> legacyActions(
303
302
}
304
303
};
305
304
attributeActionsOnEncrypt .forEach (buildLegacyActions );
306
- return Result . create_Success (legacyActions );
305
+ return InternalResult . success (legacyActions );
307
306
} catch (IllegalArgumentException ex ) {
308
307
final Error dafnyEx = Error .create_DynamoDbItemEncryptorException (ToDafnyString (ex .getMessage ()));
309
- return Result . create_Failure (dafnyEx );
308
+ return InternalResult . failure (dafnyEx );
310
309
} catch (Exception ex ) {
311
- return Result . create_Failure (Error .create_Opaque (ex ));
310
+ return InternalResult . failure (Error .create_Opaque (ex ));
312
311
}
313
312
}
314
313
0 commit comments