func()

in releases/go/mpl/AwsKmsHierarchicalKeyring/AwsKmsHierarchicalKeyring.go [1098:1278]


func (_this *DecryptSingleEncryptedDataKey) Invoke(edk interface{}) interface{} {
	{
		var edk m_AwsCryptographyMaterialProvidersTypes.EncryptedDataKey = edk.(m_AwsCryptographyMaterialProvidersTypes.EncryptedDataKey)
		_ = edk
		var res m_Wrappers.Result = m_Wrappers.Result{}
		_ = res
		var _0_valueOrError0 m_Wrappers.Outcome = m_Wrappers.Companion_Outcome_.Default()
		_ = _0_valueOrError0
		_0_valueOrError0 = m_Wrappers.Companion_Default___.Need(m_UTF8.Companion_Default___.ValidUTF8Seq((edk).Dtor_keyProviderInfo()), m_AwsCryptographyMaterialProvidersTypes.Companion_Error_.Create_AwsCryptographicMaterialProvidersException_(_dafny.SeqOfString("Received invalid EDK provider info for Hierarchical Keyring")))
		if (_0_valueOrError0).IsFailure() {
			res = (_0_valueOrError0).PropagateFailure()
			return res
		}
		var _1_suite m_AwsCryptographyMaterialProvidersTypes.AlgorithmSuiteInfo
		_ = _1_suite
		_1_suite = ((_this).Materials()).Dtor_algorithmSuite()
		var _2_keyProviderId _dafny.Sequence
		_ = _2_keyProviderId
		_2_keyProviderId = (edk).Dtor_keyProviderId()
		var _3_branchKeyIdUtf8 _dafny.Sequence
		_ = _3_branchKeyIdUtf8
		_3_branchKeyIdUtf8 = (edk).Dtor_keyProviderInfo()
		var _4_ciphertext _dafny.Sequence
		_ = _4_ciphertext
		_4_ciphertext = (edk).Dtor_ciphertext()
		var _5_valueOrError1 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(_dafny.EmptySeq)
		_ = _5_valueOrError1
		_5_valueOrError1 = m_EdkWrapping.Companion_Default___.GetProviderWrappedMaterial(_4_ciphertext, _1_suite)
		if (_5_valueOrError1).IsFailure() {
			res = (_5_valueOrError1).PropagateFailure()
			return res
		}
		var _6_providerWrappedMaterial _dafny.Sequence
		_ = _6_providerWrappedMaterial
		_6_providerWrappedMaterial = (_5_valueOrError1).Extract().(_dafny.Sequence)
		var _7_valueOrError2 m_Wrappers.Outcome = m_Wrappers.Companion_Outcome_.Default()
		_ = _7_valueOrError2
		_7_valueOrError2 = m_Wrappers.Companion_Default___.Need((_dafny.IntOfUint32((_6_providerWrappedMaterial).Cardinality())).Cmp(_dafny.IntOfInt32(Companion_Default___.EDK__CIPHERTEXT__VERSION__INDEX())) >= 0, m_AwsCryptographyMaterialProvidersTypes.Companion_Error_.Create_AwsCryptographicMaterialProvidersException_(_dafny.SeqOfString("Received EDK Ciphertext of incorrect length.")))
		if (_7_valueOrError2).IsFailure() {
			res = (_7_valueOrError2).PropagateFailure()
			return res
		}
		var _8_branchKeyVersionUuid _dafny.Sequence
		_ = _8_branchKeyVersionUuid
		_8_branchKeyVersionUuid = (_6_providerWrappedMaterial).Subsequence(uint32(Companion_Default___.EDK__CIPHERTEXT__BRANCH__KEY__VERSION__INDEX()), uint32(Companion_Default___.EDK__CIPHERTEXT__VERSION__INDEX()))
		var _9_valueOrError3 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(_dafny.EmptySeq.SetString())
		_ = _9_valueOrError3
		_9_valueOrError3 = (m_UUID.FromByteArray(_8_branchKeyVersionUuid)).MapFailure(func(coer85 func(_dafny.Sequence) m_AwsCryptographyMaterialProvidersTypes.Error) func(interface{}) interface{} {
			return func(arg86 interface{}) interface{} {
				return coer85(arg86.(_dafny.Sequence))
			}
		}(m_AwsKmsUtils.Companion_Default___.WrapStringToError))
		if (_9_valueOrError3).IsFailure() {
			res = (_9_valueOrError3).PropagateFailure()
			return res
		}
		var _10_version _dafny.Sequence
		_ = _10_version
		_10_version = (_9_valueOrError3).Extract().(_dafny.Sequence)
		var _11_valueOrError4 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(_dafny.EmptySeq)
		_ = _11_valueOrError4
		var _out0 m_Wrappers.Result
		_ = _out0
		_out0 = (_this).GetVersionCacheId(_3_branchKeyIdUtf8, _10_version, (_this).CryptoPrimitives())
		_11_valueOrError4 = _out0
		if (_11_valueOrError4).IsFailure() {
			res = (_11_valueOrError4).PropagateFailure()
			return res
		}
		var _12_cacheId _dafny.Sequence
		_ = _12_cacheId
		_12_cacheId = (_11_valueOrError4).Extract().(_dafny.Sequence)
		var _13_valueOrError5 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(m_AwsCryptographyKeyStoreTypes.Companion_BranchKeyMaterials_.Default())
		_ = _13_valueOrError5
		var _out1 m_Wrappers.Result
		_ = _out1
		_out1 = (_this).GetHierarchicalMaterialsVersion((_this).BranchKeyId(), _3_branchKeyIdUtf8, _10_version, _12_cacheId)
		_13_valueOrError5 = _out1
		if (_13_valueOrError5).IsFailure() {
			res = (_13_valueOrError5).PropagateFailure()
			return res
		}
		var _14_hierarchicalMaterials m_AwsCryptographyKeyStoreTypes.BranchKeyMaterials
		_ = _14_hierarchicalMaterials
		_14_hierarchicalMaterials = (_13_valueOrError5).Extract().(m_AwsCryptographyKeyStoreTypes.BranchKeyMaterials)
		var _15_branchKey _dafny.Sequence
		_ = _15_branchKey
		_15_branchKey = (_14_hierarchicalMaterials).Dtor_branchKey()
		var _16_branchKeyVersion _dafny.Sequence
		_ = _16_branchKeyVersion
		_16_branchKeyVersion = (_14_hierarchicalMaterials).Dtor_branchKeyVersion()
		var _17_valueOrError6 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(_dafny.EmptySeq.SetString())
		_ = _17_valueOrError6
		_17_valueOrError6 = (m_UTF8.Decode(_16_branchKeyVersion)).MapFailure(func(coer86 func(_dafny.Sequence) m_AwsCryptographyMaterialProvidersTypes.Error) func(interface{}) interface{} {
			return func(arg87 interface{}) interface{} {
				return coer86(arg87.(_dafny.Sequence))
			}
		}(m_AwsKmsUtils.Companion_Default___.WrapStringToError))
		if (_17_valueOrError6).IsFailure() {
			res = (_17_valueOrError6).PropagateFailure()
			return res
		}
		var _18_branchKeyVersionAsString _dafny.Sequence
		_ = _18_branchKeyVersionAsString
		_18_branchKeyVersionAsString = (_17_valueOrError6).Extract().(_dafny.Sequence)
		var _19_valueOrError7 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(_dafny.EmptySeq)
		_ = _19_valueOrError7
		_19_valueOrError7 = (m_UUID.ToByteArray(_18_branchKeyVersionAsString)).MapFailure(func(coer87 func(_dafny.Sequence) m_AwsCryptographyMaterialProvidersTypes.Error) func(interface{}) interface{} {
			return func(arg88 interface{}) interface{} {
				return coer87(arg88.(_dafny.Sequence))
			}
		}(m_AwsKmsUtils.Companion_Default___.WrapStringToError))
		if (_19_valueOrError7).IsFailure() {
			res = (_19_valueOrError7).PropagateFailure()
			return res
		}
		var _20_branchKeyVersionAsBytes _dafny.Sequence
		_ = _20_branchKeyVersionAsBytes
		_20_branchKeyVersionAsBytes = (_19_valueOrError7).Extract().(_dafny.Sequence)
		var _21_maybeCrypto m_Wrappers.Result
		_ = _21_maybeCrypto
		var _out2 m_Wrappers.Result
		_ = _out2
		_out2 = m_AtomicPrimitives.Companion_Default___.AtomicPrimitives(m_AtomicPrimitives.Companion_Default___.DefaultCryptoConfig())
		_21_maybeCrypto = _out2
		var _22_valueOrError8 m_Wrappers.Result = m_Wrappers.Result{}
		_ = _22_valueOrError8
		_22_valueOrError8 = (_21_maybeCrypto).MapFailure(func(coer88 func(m_AwsCryptographyPrimitivesTypes.Error) m_AwsCryptographyMaterialProvidersTypes.Error) func(interface{}) interface{} {
			return func(arg89 interface{}) interface{} {
				return coer88(arg89.(m_AwsCryptographyPrimitivesTypes.Error))
			}
		}(func(_23_e m_AwsCryptographyPrimitivesTypes.Error) m_AwsCryptographyMaterialProvidersTypes.Error {
			return m_AwsCryptographyMaterialProvidersTypes.Companion_Error_.Create_AwsCryptographyPrimitives_(_23_e)
		}))
		if (_22_valueOrError8).IsFailure() {
			res = (_22_valueOrError8).PropagateFailure()
			return res
		}
		var _24_cryptoPrimitivesX m_AwsCryptographyPrimitivesTypes.IAwsCryptographicPrimitivesClient
		_ = _24_cryptoPrimitivesX
		_24_cryptoPrimitivesX = (_22_valueOrError8).Extract().(*m_AtomicPrimitives.AtomicPrimitivesClient)
		var _25_cryptoPrimitives *m_AtomicPrimitives.AtomicPrimitivesClient
		_ = _25_cryptoPrimitives
		_25_cryptoPrimitives = _24_cryptoPrimitivesX.(*m_AtomicPrimitives.AtomicPrimitivesClient)
		var _26_kmsHierarchyUnwrap *KmsHierarchyUnwrapKeyMaterial
		_ = _26_kmsHierarchyUnwrap
		var _nw0 *KmsHierarchyUnwrapKeyMaterial = New_KmsHierarchyUnwrapKeyMaterial_()
		_ = _nw0
		_nw0.Ctor__(_15_branchKey, _3_branchKeyIdUtf8, _20_branchKeyVersionAsBytes, _25_cryptoPrimitives)
		_26_kmsHierarchyUnwrap = _nw0
		var _27_unwrapOutputRes m_Wrappers.Result
		_ = _27_unwrapOutputRes
		var _out3 m_Wrappers.Result
		_ = _out3
		_out3 = m_EdkWrapping.Companion_Default___.UnwrapEdkMaterial((edk).Dtor_ciphertext(), (_this).Materials(), _26_kmsHierarchyUnwrap)
		_27_unwrapOutputRes = _out3
		var _28_valueOrError9 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(m_EdkWrapping.Companion_UnwrapEdkMaterialOutput_.Default(Companion_HierarchyUnwrapInfo_.Default()))
		_ = _28_valueOrError9
		_28_valueOrError9 = _27_unwrapOutputRes
		if (_28_valueOrError9).IsFailure() {
			res = (_28_valueOrError9).PropagateFailure()
			return res
		}
		var _29_unwrapOutput m_EdkWrapping.UnwrapEdkMaterialOutput
		_ = _29_unwrapOutput
		_29_unwrapOutput = (_28_valueOrError9).Extract().(m_EdkWrapping.UnwrapEdkMaterialOutput)
		var _30_valueOrError10 m_Wrappers.Result = m_Wrappers.Result{}
		_ = _30_valueOrError10
		_30_valueOrError10 = m_Materials.Companion_Default___.DecryptionMaterialsAddDataKey((_this).Materials(), (_29_unwrapOutput).Dtor_plaintextDataKey(), (_29_unwrapOutput).Dtor_symmetricSigningKey())
		if (_30_valueOrError10).IsFailure() {
			res = (_30_valueOrError10).PropagateFailure()
			return res
		}
		var _31_result m_AwsCryptographyMaterialProvidersTypes.DecryptionMaterials
		_ = _31_result
		_31_result = (_30_valueOrError10).Extract().(m_AwsCryptographyMaterialProvidersTypes.DecryptionMaterials)
		res = m_Wrappers.Companion_Result_.Create_Success_(_31_result)
		return res
		return res
	}
}