
MultiKeyring_Compile.MultiKeyring Maven / Gradle / Ivy
// Class MultiKeyring
// Dafny class MultiKeyring compiled into Java
package MultiKeyring_Compile;
import software.amazon.cryptography.keystore.internaldafny.types.*;
import software.amazon.cryptography.materialproviders.internaldafny.types.*;
import AwsArnParsing_Compile.*;
import AwsKmsMrkMatchForDecrypt_Compile.*;
import AwsKmsUtils_Compile.*;
import KeyStoreErrorMessages_Compile.*;
import KmsArn_Compile.*;
import Structure_Compile.*;
import KMSKeystoreOperations_Compile.*;
import DDBKeystoreOperations_Compile.*;
import CreateKeys_Compile.*;
import CreateKeyStoreTable_Compile.*;
import GetKeys_Compile.*;
import AwsCryptographyKeyStoreOperations_Compile.*;
import software.amazon.cryptography.keystore.internaldafny.*;
import AlgorithmSuites_Compile.*;
import Materials_Compile.*;
import Keyring_Compile.*;
@SuppressWarnings({"unchecked", "deprecation"})
public class MultiKeyring implements Keyring_Compile.VerifiableInterface, software.amazon.cryptography.materialproviders.internaldafny.types.IKeyring {
public MultiKeyring() {
this._generatorKeyring = Wrappers_Compile.Option.Default(((dafny.TypeDescriptor)(java.lang.Object)dafny.TypeDescriptor.reference(software.amazon.cryptography.materialproviders.internaldafny.types.IKeyring.class)));
this._childKeyrings = dafny.DafnySequence. empty(((dafny.TypeDescriptor)(java.lang.Object)dafny.TypeDescriptor.reference(software.amazon.cryptography.materialproviders.internaldafny.types.IKeyring.class)));
}
public Wrappers_Compile.Result OnDecrypt(software.amazon.cryptography.materialproviders.internaldafny.types.OnDecryptInput input)
{
Wrappers_Compile.Result _out1;
_out1 = software.amazon.cryptography.materialproviders.internaldafny.types._Companion_IKeyring.OnDecrypt(this, input);
return _out1;
}
public Wrappers_Compile.Result OnEncrypt(software.amazon.cryptography.materialproviders.internaldafny.types.OnEncryptInput input)
{
Wrappers_Compile.Result _out1;
_out1 = software.amazon.cryptography.materialproviders.internaldafny.types._Companion_IKeyring.OnEncrypt(this, input);
return _out1;
}
public void __ctor(Wrappers_Compile.Option generatorKeyring, dafny.DafnySequence extends software.amazon.cryptography.materialproviders.internaldafny.types.IKeyring> childKeyrings)
{
(this)._generatorKeyring = generatorKeyring;
(this)._childKeyrings = childKeyrings;
}
public Wrappers_Compile.Result OnEncrypt_k(software.amazon.cryptography.materialproviders.internaldafny.types.OnEncryptInput input)
{
Wrappers_Compile.Result res = (Wrappers_Compile.Result)null;
if ((((this).generatorKeyring()).is_None()) && ((((input).dtor_materials()).dtor_plaintextDataKey()).is_None())) {
dafny.DafnySequence extends Character> _0_exception;
_0_exception = dafny.DafnySequence.asString("Need either a generator keyring or input encryption materials which contain a plaintext data key");
res = Wrappers_Compile.Result.create_Failure(software.amazon.cryptography.materialproviders.internaldafny.types.OnEncryptOutput._typeDescriptor(), software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor(), software.amazon.cryptography.materialproviders.internaldafny.types.Error.create_AwsCryptographicMaterialProvidersException(_0_exception));
return res;
}
software.amazon.cryptography.materialproviders.internaldafny.types.EncryptionMaterials _1_returnMaterials;
_1_returnMaterials = (input).dtor_materials();
if (((this).generatorKeyring()).is_Some()) {
Wrappers_Compile.Outcome _2_valueOrError0 = Wrappers_Compile.Outcome.Default(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor());
_2_valueOrError0 = Wrappers_Compile.__default.Need(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor(), (((input).dtor_materials()).dtor_plaintextDataKey()).is_None(), software.amazon.cryptography.materialproviders.internaldafny.types.Error.create_AwsCryptographicMaterialProvidersException(dafny.DafnySequence.asString("This multi keyring has a generator but provided Encryption Materials already contain plaintext data key")));
if ((_2_valueOrError0).IsFailure(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor())) {
res = (_2_valueOrError0).PropagateFailure(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor(), software.amazon.cryptography.materialproviders.internaldafny.types.OnEncryptOutput._typeDescriptor());
return res;
}
Wrappers_Compile.Result _3_onEncryptOutput;
Wrappers_Compile.Result _out0;
_out0 = (((this).generatorKeyring()).dtor_value()).OnEncrypt(input);
_3_onEncryptOutput = _out0;
Wrappers_Compile.Outcome _4_valueOrError1 = Wrappers_Compile.Outcome.Default(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor());
_4_valueOrError1 = Wrappers_Compile.__default.Need(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor(), (_3_onEncryptOutput).is_Success(), (((_3_onEncryptOutput).is_Failure()) ? ((_3_onEncryptOutput).dtor_error()) : (software.amazon.cryptography.materialproviders.internaldafny.types.Error.create_AwsCryptographicMaterialProvidersException(dafny.DafnySequence.asString("Unexpected failure. Input to Need is !Success.")))));
if ((_4_valueOrError1).IsFailure(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor())) {
res = (_4_valueOrError1).PropagateFailure(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor(), software.amazon.cryptography.materialproviders.internaldafny.types.OnEncryptOutput._typeDescriptor());
return res;
}
Wrappers_Compile.Outcome _5_valueOrError2 = Wrappers_Compile.Outcome.Default(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor());
_5_valueOrError2 = Wrappers_Compile.__default.Need(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor(), Materials_Compile.__default.ValidEncryptionMaterialsTransition((input).dtor_materials(), ((_3_onEncryptOutput).dtor_value()).dtor_materials()), software.amazon.cryptography.materialproviders.internaldafny.types.Error.create_AwsCryptographicMaterialProvidersException(dafny.DafnySequence.asString("Generator keyring returned invalid encryption materials")));
if ((_5_valueOrError2).IsFailure(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor())) {
res = (_5_valueOrError2).PropagateFailure(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor(), software.amazon.cryptography.materialproviders.internaldafny.types.OnEncryptOutput._typeDescriptor());
return res;
}
_1_returnMaterials = ((_3_onEncryptOutput).dtor_value()).dtor_materials();
}
java.math.BigInteger _hi0 = java.math.BigInteger.valueOf(((this).childKeyrings()).length());
for (java.math.BigInteger _6_i = java.math.BigInteger.ZERO; _6_i.compareTo(_hi0) < 0; _6_i = _6_i.add(java.math.BigInteger.ONE)) {
software.amazon.cryptography.materialproviders.internaldafny.types.OnEncryptInput _7_onEncryptInput;
_7_onEncryptInput = software.amazon.cryptography.materialproviders.internaldafny.types.OnEncryptInput.create(_1_returnMaterials);
Wrappers_Compile.Result _8_onEncryptOutput;
Wrappers_Compile.Result _out1;
_out1 = (((software.amazon.cryptography.materialproviders.internaldafny.types.IKeyring)(java.lang.Object)(((this).childKeyrings()).select(dafny.Helpers.toInt((_6_i)))))).OnEncrypt(_7_onEncryptInput);
_8_onEncryptOutput = _out1;
Wrappers_Compile.Outcome _9_valueOrError3 = Wrappers_Compile.Outcome.Default(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor());
_9_valueOrError3 = Wrappers_Compile.__default.Need(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor(), (_8_onEncryptOutput).is_Success(), software.amazon.cryptography.materialproviders.internaldafny.types.Error.create_AwsCryptographicMaterialProvidersException(dafny.DafnySequence.asString("Child keyring failed to encrypt plaintext data key")));
if ((_9_valueOrError3).IsFailure(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor())) {
res = (_9_valueOrError3).PropagateFailure(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor(), software.amazon.cryptography.materialproviders.internaldafny.types.OnEncryptOutput._typeDescriptor());
return res;
}
Wrappers_Compile.Outcome _10_valueOrError4 = Wrappers_Compile.Outcome.Default(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor());
_10_valueOrError4 = Wrappers_Compile.__default.Need(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor(), Materials_Compile.__default.ValidEncryptionMaterialsTransition(_1_returnMaterials, ((_8_onEncryptOutput).dtor_value()).dtor_materials()), software.amazon.cryptography.materialproviders.internaldafny.types.Error.create_AwsCryptographicMaterialProvidersException(dafny.DafnySequence.asString("Child keyring performed invalid transition on encryption materials")));
if ((_10_valueOrError4).IsFailure(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor())) {
res = (_10_valueOrError4).PropagateFailure(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor(), software.amazon.cryptography.materialproviders.internaldafny.types.OnEncryptOutput._typeDescriptor());
return res;
}
_1_returnMaterials = ((_8_onEncryptOutput).dtor_value()).dtor_materials();
}
Wrappers_Compile.Outcome _11_valueOrError5 = Wrappers_Compile.Outcome.Default(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor());
_11_valueOrError5 = Wrappers_Compile.__default.Need(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor(), Materials_Compile.__default.ValidEncryptionMaterialsTransition((input).dtor_materials(), _1_returnMaterials), software.amazon.cryptography.materialproviders.internaldafny.types.Error.create_AwsCryptographicMaterialProvidersException(dafny.DafnySequence.asString("A child or generator keyring modified the encryption materials in illegal ways.")));
if ((_11_valueOrError5).IsFailure(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor())) {
res = (_11_valueOrError5).PropagateFailure(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor(), software.amazon.cryptography.materialproviders.internaldafny.types.OnEncryptOutput._typeDescriptor());
return res;
}
res = Wrappers_Compile.Result.create_Success(software.amazon.cryptography.materialproviders.internaldafny.types.OnEncryptOutput._typeDescriptor(), software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor(), software.amazon.cryptography.materialproviders.internaldafny.types.OnEncryptOutput.create(_1_returnMaterials));
return res;
}
public Wrappers_Compile.Result OnDecrypt_k(software.amazon.cryptography.materialproviders.internaldafny.types.OnDecryptInput input)
{
Wrappers_Compile.Result res = (Wrappers_Compile.Result)null;
software.amazon.cryptography.materialproviders.internaldafny.types.DecryptionMaterials _0_materials;
_0_materials = (input).dtor_materials();
Wrappers_Compile.Outcome _1_valueOrError0 = Wrappers_Compile.Outcome.Default(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor());
_1_valueOrError0 = Wrappers_Compile.__default.Need(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor(), Materials_Compile.__default.DecryptionMaterialsWithoutPlaintextDataKey((input).dtor_materials()), software.amazon.cryptography.materialproviders.internaldafny.types.Error.create_AwsCryptographicMaterialProvidersException(dafny.DafnySequence.asString("Keyring received decryption materials that already contain a plaintext data key.")));
if ((_1_valueOrError0).IsFailure(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor())) {
res = (_1_valueOrError0).PropagateFailure(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor(), software.amazon.cryptography.materialproviders.internaldafny.types.OnDecryptOutput._typeDescriptor());
return res;
}
dafny.DafnySequence extends software.amazon.cryptography.materialproviders.internaldafny.types.Error> _2_failures;
_2_failures = dafny.DafnySequence. empty(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor());
if (((this).generatorKeyring()).is_Some()) {
Wrappers_Compile.Result _3_result;
Wrappers_Compile.Result _out0;
_out0 = __default.AttemptDecryptDataKey(((this).generatorKeyring()).dtor_value(), input);
_3_result = _out0;
if ((_3_result).is_Success()) {
if (((((_3_result).dtor_value()).dtor_materials()).dtor_plaintextDataKey()).is_Some()) {
res = Wrappers_Compile.Result.create_Success(software.amazon.cryptography.materialproviders.internaldafny.types.OnDecryptOutput._typeDescriptor(), software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor(), (_3_result).dtor_value());
return res;
}
} else {
_2_failures = dafny.DafnySequence.concatenate(_2_failures, dafny.DafnySequence. of(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor(), (_3_result).dtor_error()));
}
}
java.math.BigInteger _hi0 = java.math.BigInteger.valueOf(((this).childKeyrings()).length());
for (java.math.BigInteger _4_j = java.math.BigInteger.ZERO; _4_j.compareTo(_hi0) < 0; _4_j = _4_j.add(java.math.BigInteger.ONE)) {
Wrappers_Compile.Result _5_result;
Wrappers_Compile.Result _out1;
_out1 = __default.AttemptDecryptDataKey(((software.amazon.cryptography.materialproviders.internaldafny.types.IKeyring)(java.lang.Object)(((this).childKeyrings()).select(dafny.Helpers.toInt((_4_j))))), input);
_5_result = _out1;
if ((_5_result).is_Success()) {
res = Wrappers_Compile.Result.create_Success(software.amazon.cryptography.materialproviders.internaldafny.types.OnDecryptOutput._typeDescriptor(), software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor(), (_5_result).dtor_value());
return res;
} else {
_2_failures = dafny.DafnySequence.concatenate(_2_failures, dafny.DafnySequence. of(software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor(), (_5_result).dtor_error()));
}
}
software.amazon.cryptography.materialproviders.internaldafny.types.Error _6_combinedResult;
_6_combinedResult = software.amazon.cryptography.materialproviders.internaldafny.types.Error.create_CollectionOfErrors(_2_failures, dafny.DafnySequence.asString("No Configured Keyring was able to decrypt the Data Key. The list of encountered Exceptions is available via `list`."));
res = Wrappers_Compile.Result.create_Failure(software.amazon.cryptography.materialproviders.internaldafny.types.OnDecryptOutput._typeDescriptor(), software.amazon.cryptography.materialproviders.internaldafny.types.Error._typeDescriptor(), _6_combinedResult);
return res;
}
public Wrappers_Compile.Option _generatorKeyring;
public Wrappers_Compile.Option generatorKeyring()
{
return this._generatorKeyring;
}
public dafny.DafnySequence extends software.amazon.cryptography.materialproviders.internaldafny.types.IKeyring> _childKeyrings;
public dafny.DafnySequence extends software.amazon.cryptography.materialproviders.internaldafny.types.IKeyring> childKeyrings()
{
return this._childKeyrings;
}
private static final dafny.TypeDescriptor _TYPE = dafny.TypeDescriptor.referenceWithInitializer(MultiKeyring.class, () -> (MultiKeyring) null);
public static dafny.TypeDescriptor _typeDescriptor() {
return (dafny.TypeDescriptor) (dafny.TypeDescriptor>) _TYPE;
}
@Override
public java.lang.String toString() {
return "MultiKeyring.MultiKeyring";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy