in v3/materials/kms_keyring.go [180:216]
func commonDecrypt(ctx context.Context, materials *DecryptionMaterials, encryptedDataKey DataKey, kmsKeyId *string, matDesc MaterialDescription, kmsClient KmsAPIClient) (*CryptographicMaterials, error) {
if matDesc != nil {
if v, ok := matDesc[kmsAWSCEKContextKey]; !ok {
return nil, fmt.Errorf("required key %v is missing from encryption context", kmsAWSCEKContextKey)
} else if v != materials.ContentAlgorithm {
return nil, fmt.Errorf(kmsMismatchCEKAlg)
}
}
in := &kms.DecryptInput{
EncryptionContext: materials.MaterialDescription,
CiphertextBlob: encryptedDataKey.EncryptedDataKey,
KeyId: kmsKeyId,
}
grantTokens := ctx.Value(GrantTokens)
if grantTokens != nil {
in.GrantTokens = grantTokens.([]string)
}
out, err := kmsClient.Decrypt(ctx, in)
if err != nil {
return nil, err
}
materials.DataKey.KeyMaterial = out.Plaintext
cryptoMaterials := &CryptographicMaterials{
Key: out.Plaintext,
IV: materials.ContentIV,
KeyringAlgorithm: materials.DataKey.DataKeyAlgorithm,
CEKAlgorithm: materials.ContentAlgorithm,
TagLength: materials.TagLength,
MaterialDescription: materials.MaterialDescription,
EncryptedKey: materials.DataKey.EncryptedDataKey,
}
return cryptoMaterials, nil
}