func()

in releases/go/encryption-sdk/KeyDerivation/KeyDerivation.go [287:355]


func (_static *CompanionStruct_Default___) DeriveKey(messageId _dafny.Sequence, plaintextDataKey _dafny.Sequence, suite m_AwsCryptographyMaterialProvidersTypes.AlgorithmSuiteInfo, crypto *m_AtomicPrimitives.AtomicPrimitivesClient, onNetV4Retry bool) m_Wrappers.Result {
	var res m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(Companion_ExpandedKeyMaterial_.Default())
	_ = res
	var _source0 m_AwsCryptographyMaterialProvidersTypes.DerivationAlgorithm = (suite).Dtor_kdf()
	_ = _source0
	{
		{
			if _source0.Is_IDENTITY() {
				var _0_i m_AwsCryptographyMaterialProvidersTypes.IDENTITY = _source0.Get_().(m_AwsCryptographyMaterialProvidersTypes.DerivationAlgorithm_IDENTITY).IDENTITY
				_ = _0_i
				{
					res = m_Wrappers.Companion_Result_.Create_Success_(Companion_ExpandedKeyMaterial_.Create_ExpandedKeyMaterial_(plaintextDataKey, m_Wrappers.Companion_Option_.Create_None_()))
					return res
				}
				goto Lmatch0
			}
		}
		{
			if _source0.Is_HKDF() {
				var _1_hkdf m_AwsCryptographyMaterialProvidersTypes.HKDF = _source0.Get_().(m_AwsCryptographyMaterialProvidersTypes.DerivationAlgorithm_HKDF).HKDF
				_ = _1_hkdf
				{
					var _2_hkdfInput m_AwsCryptographyPrimitivesTypes.HkdfInput
					_ = _2_hkdfInput
					_2_hkdfInput = m_AwsCryptographyPrimitivesTypes.Companion_HkdfInput_.Create_HkdfInput_((_1_hkdf).Dtor_hmac(), m_Wrappers.Companion_Option_.Create_None_(), plaintextDataKey, _dafny.Companion_Sequence_.Concatenate((suite).Dtor_binaryId(), messageId), (_1_hkdf).Dtor_outputKeyLength())
					if onNetV4Retry {
						_2_hkdfInput = m_AwsCryptographyPrimitivesTypes.Companion_HkdfInput_.Create_HkdfInput_((_1_hkdf).Dtor_hmac(), m_Wrappers.Companion_Option_.Create_None_(), plaintextDataKey, (suite).Dtor_binaryId(), (_1_hkdf).Dtor_outputKeyLength())
					}
					var _3_maybeDerivedKey m_Wrappers.Result
					_ = _3_maybeDerivedKey
					var _out0 m_Wrappers.Result
					_ = _out0
					_out0 = (crypto).Hkdf(_2_hkdfInput)
					_3_maybeDerivedKey = _out0
					var _4_valueOrError0 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(_dafny.EmptySeq)
					_ = _4_valueOrError0
					_4_valueOrError0 = (_3_maybeDerivedKey).MapFailure(func(coer11 func(m_AwsCryptographyPrimitivesTypes.Error) m_AwsCryptographyEncryptionSdkTypes.Error) func(interface{}) interface{} {
						return func(arg12 interface{}) interface{} {
							return coer11(arg12.(m_AwsCryptographyPrimitivesTypes.Error))
						}
					}(func(_5_e m_AwsCryptographyPrimitivesTypes.Error) m_AwsCryptographyEncryptionSdkTypes.Error {
						return m_AwsCryptographyEncryptionSdkTypes.Companion_Error_.Create_AwsCryptographyPrimitives_(_5_e)
					}))
					if (_4_valueOrError0).IsFailure() {
						res = (_4_valueOrError0).PropagateFailure()
						return res
					}
					var _6_derivedKey _dafny.Sequence
					_ = _6_derivedKey
					_6_derivedKey = (_4_valueOrError0).Extract().(_dafny.Sequence)
					res = m_Wrappers.Companion_Result_.Create_Success_(Companion_ExpandedKeyMaterial_.Create_ExpandedKeyMaterial_(_6_derivedKey, m_Wrappers.Companion_Option_.Create_None_()))
					return res
				}
				goto Lmatch0
			}
		}
		{
			var _7_None m_AwsCryptographyMaterialProvidersTypes.DerivationAlgorithm = _source0
			_ = _7_None
			{
				res = m_Wrappers.Companion_Result_.Create_Failure_(m_AwsCryptographyEncryptionSdkTypes.Companion_Error_.Create_AwsEncryptionSdkException_(_dafny.SeqOfString("None is not a valid Key Derivation Function")))
				return res
			}
		}
		goto Lmatch0
	}
Lmatch0:
	return res
}