Skip to content

Commit 9d94dda

Browse files
committed
More static Java helpers out of extern classes
1 parent 8931e27 commit 9d94dda

File tree

2 files changed

+42
-41
lines changed

2 files changed

+42
-41
lines changed

DynamoDbEncryption/dafny/DynamoDbItemEncryptor/src/InternalLegacyOverride.dfy

+28-28
Original file line numberDiff line numberDiff line change
@@ -22,43 +22,43 @@ module {:extern "software.amazon.cryptography.dbencryptionsdk.dynamodb.itemencry
2222

2323
predicate method {:extern} IsLegacyInput(input: Types.DecryptItemInput)
2424

25-
// The following functions are for the benefit of the extern implementation to call,
26-
// avoiding direct references to generic datatype constructors
27-
// since their calling pattern is different between different versions of Dafny
28-
// (i.e. after 4.2, explicit type descriptors are required).
25+
}
2926

30-
static function method CreateBuildSuccess(value: Option<InternalLegacyOverride>): Result<Option<InternalLegacyOverride>, Types.Error> {
31-
Success(value)
32-
}
27+
// The following functions are for the benefit of the extern implementation to call,
28+
// avoiding direct references to generic datatype constructors
29+
// since their calling pattern is different between different versions of Dafny
30+
// (i.e. after 4.2, explicit type descriptors are required).
3331

34-
static function method CreateBuildFailure(error: Types.Error): Result<Option<InternalLegacyOverride>, Types.Error> {
35-
Failure(error)
36-
}
32+
function method CreateBuildSuccess(value: Option<InternalLegacyOverride>): Result<Option<InternalLegacyOverride>, Types.Error> {
33+
Success(value)
34+
}
3735

38-
static function method CreateInternalLegacyOverrideSome(value: InternalLegacyOverride): Option<InternalLegacyOverride> {
39-
Some(value)
40-
}
36+
function method CreateBuildFailure(error: Types.Error): Result<Option<InternalLegacyOverride>, Types.Error> {
37+
Failure(error)
38+
}
4139

42-
static function method CreateInternalLegacyOverrideNone(): Option<InternalLegacyOverride> {
43-
None
44-
}
40+
function method CreateInternalLegacyOverrideSome(value: InternalLegacyOverride): Option<InternalLegacyOverride> {
41+
Some(value)
42+
}
4543

46-
function method CreateEncryptItemSuccess(value: Types.EncryptItemOutput): Result<Types.EncryptItemOutput, Types.Error> {
47-
Success(value)
48-
}
44+
function method CreateInternalLegacyOverrideNone(): Option<InternalLegacyOverride> {
45+
None
46+
}
4947

50-
function method CreateEncryptItemFailure(error: Types.Error): Result<Types.EncryptItemOutput, Types.Error> {
51-
Failure(error)
52-
}
48+
function method CreateEncryptItemSuccess(value: Types.EncryptItemOutput): Result<Types.EncryptItemOutput, Types.Error> {
49+
Success(value)
50+
}
5351

54-
function method CreateDecryptItemSuccess(value: Types.DecryptItemOutput): Result<Types.DecryptItemOutput, Types.Error> {
55-
Success(value)
56-
}
52+
function method CreateEncryptItemFailure(error: Types.Error): Result<Types.EncryptItemOutput, Types.Error> {
53+
Failure(error)
54+
}
5755

58-
function method CreateDecryptItemFailure(error: Types.Error): Result<Types.DecryptItemOutput, Types.Error> {
59-
Failure(error)
60-
}
56+
function method CreateDecryptItemSuccess(value: Types.DecryptItemOutput): Result<Types.DecryptItemOutput, Types.Error> {
57+
Success(value)
58+
}
6159

60+
function method CreateDecryptItemFailure(error: Types.Error): Result<Types.DecryptItemOutput, Types.Error> {
61+
Failure(error)
6262
}
6363

6464
}

DynamoDbEncryption/runtimes/java/src/main/java/software/amazon/cryptography/dbencryptionsdk/dynamodb/itemencryptor/internaldafny/legacy/InternalLegacyOverride.java

+14-13
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@
2828
import software.amazon.awssdk.core.SdkBytes;
2929
import software.amazon.cryptography.dbencryptionsdk.dynamodb.ILegacyDynamoDbEncryptor;
3030
import software.amazon.cryptography.dbencryptionsdk.dynamodb.internaldafny.types.LegacyPolicy;
31-
import software.amazon.cryptography.dbencryptionsdk.dynamodb.itemencryptor.ToNative;
3231
import software.amazon.cryptography.dbencryptionsdk.dynamodb.itemencryptor.internaldafny.types.Error;
3332
import software.amazon.cryptography.dbencryptionsdk.structuredencryption.internaldafny.types.CryptoAction;
3433

34+
import software.amazon.cryptography.dbencryptionsdk.dynamodb.itemencryptor.internaldafny.legacy._ExternBase___default;
35+
3536
public class InternalLegacyOverride extends _ExternBase_InternalLegacyOverride {
3637

3738
private DynamoDBEncryptor encryptor;
@@ -95,7 +96,7 @@ > EncryptItem(
9596
) {
9697
// Precondition: Policy MUST allow the caller to encrypt.
9798
if (!_policy.is_FORCE__LEGACY__ENCRYPT__ALLOW__LEGACY__DECRYPT()) {
98-
return CreateEncryptItemFailure(
99+
return _ExternBase___default.CreateEncryptItemFailure(
99100
createError("Legacy Policy does not support encrypt.")
100101
);
101102
}
@@ -127,9 +128,9 @@ > EncryptItem(
127128
software.amazon.cryptography.dbencryptionsdk.dynamodb.itemencryptor.ToDafny.EncryptItemOutput(
128129
nativeOutput
129130
);
130-
return CreateEncryptItemSuccess(dafnyOutput);
131+
return _ExternBase___default.CreateEncryptItemSuccess(dafnyOutput);
131132
} catch (Exception ex) {
132-
return CreateEncryptItemFailure(Error.create_Opaque(ex));
133+
return _ExternBase___default.CreateEncryptItemFailure(Error.create_Opaque(ex));
133134
}
134135
}
135136

@@ -149,7 +150,7 @@ > DecryptItem(
149150
!_policy.is_FORCE__LEGACY__ENCRYPT__ALLOW__LEGACY__DECRYPT() &&
150151
!_policy.is_FORBID__LEGACY__ENCRYPT__ALLOW__LEGACY__DECRYPT()
151152
) {
152-
return CreateDecryptItemFailure(
153+
return _ExternBase___default.CreateDecryptItemFailure(
153154
createError("Legacy Policy does not support decrypt.")
154155
);
155156
}
@@ -180,9 +181,9 @@ > DecryptItem(
180181
software.amazon.cryptography.dbencryptionsdk.dynamodb.itemencryptor.ToDafny.DecryptItemOutput(
181182
nativeOutput
182183
);
183-
return CreateDecryptItemSuccess(dafnyOutput);
184+
return _ExternBase___default.CreateDecryptItemSuccess(dafnyOutput);
184185
} catch (Exception ex) {
185-
return CreateDecryptItemFailure(Error.create_Opaque(ex));
186+
return _ExternBase___default.CreateDecryptItemFailure(Error.create_Opaque(ex));
186187
}
187188
}
188189

@@ -191,7 +192,7 @@ public static Result<Option<InternalLegacyOverride>, Error> Build(
191192
) {
192193
// Check for early return (Postcondition): If there is no legacyOverride there is nothing to do.
193194
if (encryptorConfig.dtor_legacyOverride().is_None()) {
194-
return CreateBuildSuccess(CreateInternalLegacyOverrideNone());
195+
return _ExternBase___default.CreateBuildSuccess(_ExternBase___default.CreateInternalLegacyOverrideNone());
195196
}
196197
final software.amazon.cryptography.dbencryptionsdk.dynamodb.internaldafny.types.LegacyOverride legacyOverride =
197198
encryptorConfig.dtor_legacyOverride().dtor_value();
@@ -203,15 +204,15 @@ public static Result<Option<InternalLegacyOverride>, Error> Build(
203204

204205
// Precondition: The encryptor MUST be a DynamoDBEncryptor
205206
if (!isDynamoDBEncryptor(maybeEncryptor)) {
206-
return CreateBuildFailure(
207+
return _ExternBase___default.CreateBuildFailure(
207208
createError("Legacy encryptor is not supported")
208209
);
209210
}
210211
// Preconditions: MUST be able to create valid encryption context
211212
final InternalResult<EncryptionContext, Error> maybeEncryptionContext =
212213
legacyEncryptionContext(encryptorConfig);
213214
if (maybeEncryptionContext.isFailure()) {
214-
return CreateBuildFailure(maybeEncryptionContext.error());
215+
return _ExternBase___default.CreateBuildFailure(maybeEncryptionContext.error());
215216
}
216217
// Precondition: All actions MUST be supported types
217218
final InternalResult<
@@ -221,7 +222,7 @@ public static Result<Option<InternalLegacyOverride>, Error> Build(
221222
legacyOverride.dtor_attributeActionsOnEncrypt()
222223
);
223224
if (maybeActions.isFailure()) {
224-
return CreateBuildFailure(maybeEncryptionContext.error());
225+
return _ExternBase___default.CreateBuildFailure(maybeEncryptionContext.error());
225226
}
226227

227228
final InternalLegacyOverride internalLegacyOverride =
@@ -232,8 +233,8 @@ public static Result<Option<InternalLegacyOverride>, Error> Build(
232233
legacyOverride.dtor_policy()
233234
);
234235

235-
return CreateBuildSuccess(
236-
CreateInternalLegacyOverrideSome(internalLegacyOverride)
236+
return _ExternBase___default.CreateBuildSuccess(
237+
_ExternBase___default.CreateInternalLegacyOverrideSome(internalLegacyOverride)
237238
);
238239
}
239240

0 commit comments

Comments
 (0)