{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.KMS.Decrypt
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Decrypts ciphertext that was encrypted by a KMS key using any of the
-- following operations:
--
-- -   Encrypt
--
-- -   GenerateDataKey
--
-- -   GenerateDataKeyPair
--
-- -   GenerateDataKeyWithoutPlaintext
--
-- -   GenerateDataKeyPairWithoutPlaintext
--
-- You can use this operation to decrypt ciphertext that was encrypted
-- under a symmetric encryption KMS key or an asymmetric encryption KMS
-- key. When the KMS key is asymmetric, you must specify the KMS key and
-- the encryption algorithm that was used to encrypt the ciphertext. For
-- information about asymmetric KMS keys, see
-- <https://docs.aws.amazon.com/kms/latest/developerguide/symmetric-asymmetric.html Asymmetric KMS keys>
-- in the /Key Management Service Developer Guide/.
--
-- The @Decrypt@ operation also decrypts ciphertext that was encrypted
-- outside of KMS by the public key in an KMS asymmetric KMS key. However,
-- it cannot decrypt symmetric ciphertext produced by other libraries, such
-- as the
-- <https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/ Amazon Web Services Encryption SDK>
-- or
-- <https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingClientSideEncryption.html Amazon S3 client-side encryption>.
-- These libraries return a ciphertext format that is incompatible with
-- KMS.
--
-- If the ciphertext was encrypted under a symmetric encryption KMS key,
-- the @KeyId@ parameter is optional. KMS can get this information from
-- metadata that it adds to the symmetric ciphertext blob. This feature
-- adds durability to your implementation by ensuring that authorized users
-- can decrypt ciphertext decades after it was encrypted, even if they\'ve
-- lost track of the key ID. However, specifying the KMS key is always
-- recommended as a best practice. When you use the @KeyId@ parameter to
-- specify a KMS key, KMS only uses the KMS key you specify. If the
-- ciphertext was encrypted under a different KMS key, the @Decrypt@
-- operation fails. This practice ensures that you use the KMS key that you
-- intend.
--
-- Whenever possible, use key policies to give users permission to call the
-- @Decrypt@ operation on a particular KMS key, instead of using IAM
-- policies. Otherwise, you might create an IAM user policy that gives the
-- user @Decrypt@ permission on all KMS keys. This user could decrypt
-- ciphertext that was encrypted by KMS keys in other accounts if the key
-- policy for the cross-account KMS key permits it. If you must use an IAM
-- policy for @Decrypt@ permissions, limit the user to particular KMS keys
-- or particular trusted accounts. For details, see
-- <https://docs.aws.amazon.com/kms/latest/developerguide/iam-policies.html#iam-policies-best-practices Best practices for IAM policies>
-- in the /Key Management Service Developer Guide/.
--
-- Applications in Amazon Web Services Nitro Enclaves can call this
-- operation by using the
-- <https://github.com/aws/aws-nitro-enclaves-sdk-c Amazon Web Services Nitro Enclaves Development Kit>.
-- For information about the supporting parameters, see
-- <https://docs.aws.amazon.com/kms/latest/developerguide/services-nitro-enclaves.html How Amazon Web Services Nitro Enclaves use KMS>
-- in the /Key Management Service Developer Guide/.
--
-- The KMS key that you use for this operation must be in a compatible key
-- state. For details, see
-- <https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html Key states of KMS keys>
-- in the /Key Management Service Developer Guide/.
--
-- __Cross-account use__: Yes. To perform this operation with a KMS key in
-- a different Amazon Web Services account, specify the key ARN or alias
-- ARN in the value of the @KeyId@ parameter.
--
-- __Required permissions__:
-- <https://docs.aws.amazon.com/kms/latest/developerguide/kms-api-permissions-reference.html kms:Decrypt>
-- (key policy)
--
-- __Related operations:__
--
-- -   Encrypt
--
-- -   GenerateDataKey
--
-- -   GenerateDataKeyPair
--
-- -   ReEncrypt
module Amazonka.KMS.Decrypt
  ( -- * Creating a Request
    Decrypt (..),
    newDecrypt,

    -- * Request Lenses
    decrypt_encryptionAlgorithm,
    decrypt_encryptionContext,
    decrypt_grantTokens,
    decrypt_keyId,
    decrypt_ciphertextBlob,

    -- * Destructuring the Response
    DecryptResponse (..),
    newDecryptResponse,

    -- * Response Lenses
    decryptResponse_encryptionAlgorithm,
    decryptResponse_keyId,
    decryptResponse_plaintext,
    decryptResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.KMS.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newDecrypt' smart constructor.
data Decrypt = Decrypt'
  { -- | Specifies the encryption algorithm that will be used to decrypt the
    -- ciphertext. Specify the same algorithm that was used to encrypt the
    -- data. If you specify a different algorithm, the @Decrypt@ operation
    -- fails.
    --
    -- This parameter is required only when the ciphertext was encrypted under
    -- an asymmetric KMS key. The default value, @SYMMETRIC_DEFAULT@,
    -- represents the only supported algorithm that is valid for symmetric
    -- encryption KMS keys.
    Decrypt -> Maybe EncryptionAlgorithmSpec
encryptionAlgorithm :: Prelude.Maybe EncryptionAlgorithmSpec,
    -- | Specifies the encryption context to use when decrypting the data. An
    -- encryption context is valid only for
    -- <https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#cryptographic-operations cryptographic operations>
    -- with a symmetric encryption KMS key. The standard asymmetric encryption
    -- algorithms and HMAC algorithms that KMS uses do not support an
    -- encryption context.
    --
    -- An /encryption context/ is a collection of non-secret key-value pairs
    -- that represent additional authenticated data. When you use an encryption
    -- context to encrypt data, you must specify the same (an exact
    -- case-sensitive match) encryption context to decrypt the data. An
    -- encryption context is supported only on operations with symmetric
    -- encryption KMS keys. On operations with symmetric encryption KMS keys,
    -- an encryption context is optional, but it is strongly recommended.
    --
    -- For more information, see
    -- <https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#encrypt_context Encryption context>
    -- in the /Key Management Service Developer Guide/.
    Decrypt -> Maybe (HashMap Text Text)
encryptionContext :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | A list of grant tokens.
    --
    -- Use a grant token when your permission to call this operation comes from
    -- a new grant that has not yet achieved /eventual consistency/. For more
    -- information, see
    -- <https://docs.aws.amazon.com/kms/latest/developerguide/grants.html#grant_token Grant token>
    -- and
    -- <https://docs.aws.amazon.com/kms/latest/developerguide/grant-manage.html#using-grant-token Using a grant token>
    -- in the /Key Management Service Developer Guide/.
    Decrypt -> Maybe [Text]
grantTokens :: Prelude.Maybe [Prelude.Text],
    -- | Specifies the KMS key that KMS uses to decrypt the ciphertext.
    --
    -- Enter a key ID of the KMS key that was used to encrypt the ciphertext.
    -- If you identify a different KMS key, the @Decrypt@ operation throws an
    -- @IncorrectKeyException@.
    --
    -- This parameter is required only when the ciphertext was encrypted under
    -- an asymmetric KMS key. If you used a symmetric encryption KMS key, KMS
    -- can get the KMS key from metadata that it adds to the symmetric
    -- ciphertext blob. However, it is always recommended as a best practice.
    -- This practice ensures that you use the KMS key that you intend.
    --
    -- To specify a KMS key, use its key ID, key ARN, alias name, or alias ARN.
    -- When using an alias name, prefix it with @\"alias\/\"@. To specify a KMS
    -- key in a different Amazon Web Services account, you must use the key ARN
    -- or alias ARN.
    --
    -- For example:
    --
    -- -   Key ID: @1234abcd-12ab-34cd-56ef-1234567890ab@
    --
    -- -   Key ARN:
    --     @arn:aws:kms:us-east-2:111122223333:key\/1234abcd-12ab-34cd-56ef-1234567890ab@
    --
    -- -   Alias name: @alias\/ExampleAlias@
    --
    -- -   Alias ARN: @arn:aws:kms:us-east-2:111122223333:alias\/ExampleAlias@
    --
    -- To get the key ID and key ARN for a KMS key, use ListKeys or
    -- DescribeKey. To get the alias name and alias ARN, use ListAliases.
    Decrypt -> Maybe Text
keyId :: Prelude.Maybe Prelude.Text,
    -- | Ciphertext to be decrypted. The blob includes metadata.
    Decrypt -> Base64
ciphertextBlob :: Data.Base64
  }
  deriving (Decrypt -> Decrypt -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Decrypt -> Decrypt -> Bool
$c/= :: Decrypt -> Decrypt -> Bool
== :: Decrypt -> Decrypt -> Bool
$c== :: Decrypt -> Decrypt -> Bool
Prelude.Eq, ReadPrec [Decrypt]
ReadPrec Decrypt
Int -> ReadS Decrypt
ReadS [Decrypt]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Decrypt]
$creadListPrec :: ReadPrec [Decrypt]
readPrec :: ReadPrec Decrypt
$creadPrec :: ReadPrec Decrypt
readList :: ReadS [Decrypt]
$creadList :: ReadS [Decrypt]
readsPrec :: Int -> ReadS Decrypt
$creadsPrec :: Int -> ReadS Decrypt
Prelude.Read, Int -> Decrypt -> ShowS
[Decrypt] -> ShowS
Decrypt -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Decrypt] -> ShowS
$cshowList :: [Decrypt] -> ShowS
show :: Decrypt -> String
$cshow :: Decrypt -> String
showsPrec :: Int -> Decrypt -> ShowS
$cshowsPrec :: Int -> Decrypt -> ShowS
Prelude.Show, forall x. Rep Decrypt x -> Decrypt
forall x. Decrypt -> Rep Decrypt x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Decrypt x -> Decrypt
$cfrom :: forall x. Decrypt -> Rep Decrypt x
Prelude.Generic)

-- |
-- Create a value of 'Decrypt' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'encryptionAlgorithm', 'decrypt_encryptionAlgorithm' - Specifies the encryption algorithm that will be used to decrypt the
-- ciphertext. Specify the same algorithm that was used to encrypt the
-- data. If you specify a different algorithm, the @Decrypt@ operation
-- fails.
--
-- This parameter is required only when the ciphertext was encrypted under
-- an asymmetric KMS key. The default value, @SYMMETRIC_DEFAULT@,
-- represents the only supported algorithm that is valid for symmetric
-- encryption KMS keys.
--
-- 'encryptionContext', 'decrypt_encryptionContext' - Specifies the encryption context to use when decrypting the data. An
-- encryption context is valid only for
-- <https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#cryptographic-operations cryptographic operations>
-- with a symmetric encryption KMS key. The standard asymmetric encryption
-- algorithms and HMAC algorithms that KMS uses do not support an
-- encryption context.
--
-- An /encryption context/ is a collection of non-secret key-value pairs
-- that represent additional authenticated data. When you use an encryption
-- context to encrypt data, you must specify the same (an exact
-- case-sensitive match) encryption context to decrypt the data. An
-- encryption context is supported only on operations with symmetric
-- encryption KMS keys. On operations with symmetric encryption KMS keys,
-- an encryption context is optional, but it is strongly recommended.
--
-- For more information, see
-- <https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#encrypt_context Encryption context>
-- in the /Key Management Service Developer Guide/.
--
-- 'grantTokens', 'decrypt_grantTokens' - A list of grant tokens.
--
-- Use a grant token when your permission to call this operation comes from
-- a new grant that has not yet achieved /eventual consistency/. For more
-- information, see
-- <https://docs.aws.amazon.com/kms/latest/developerguide/grants.html#grant_token Grant token>
-- and
-- <https://docs.aws.amazon.com/kms/latest/developerguide/grant-manage.html#using-grant-token Using a grant token>
-- in the /Key Management Service Developer Guide/.
--
-- 'keyId', 'decrypt_keyId' - Specifies the KMS key that KMS uses to decrypt the ciphertext.
--
-- Enter a key ID of the KMS key that was used to encrypt the ciphertext.
-- If you identify a different KMS key, the @Decrypt@ operation throws an
-- @IncorrectKeyException@.
--
-- This parameter is required only when the ciphertext was encrypted under
-- an asymmetric KMS key. If you used a symmetric encryption KMS key, KMS
-- can get the KMS key from metadata that it adds to the symmetric
-- ciphertext blob. However, it is always recommended as a best practice.
-- This practice ensures that you use the KMS key that you intend.
--
-- To specify a KMS key, use its key ID, key ARN, alias name, or alias ARN.
-- When using an alias name, prefix it with @\"alias\/\"@. To specify a KMS
-- key in a different Amazon Web Services account, you must use the key ARN
-- or alias ARN.
--
-- For example:
--
-- -   Key ID: @1234abcd-12ab-34cd-56ef-1234567890ab@
--
-- -   Key ARN:
--     @arn:aws:kms:us-east-2:111122223333:key\/1234abcd-12ab-34cd-56ef-1234567890ab@
--
-- -   Alias name: @alias\/ExampleAlias@
--
-- -   Alias ARN: @arn:aws:kms:us-east-2:111122223333:alias\/ExampleAlias@
--
-- To get the key ID and key ARN for a KMS key, use ListKeys or
-- DescribeKey. To get the alias name and alias ARN, use ListAliases.
--
-- 'ciphertextBlob', 'decrypt_ciphertextBlob' - Ciphertext to be decrypted. The blob includes metadata.--
-- -- /Note:/ This 'Lens' automatically encodes and decodes Base64 data.
-- -- The underlying isomorphism will encode to Base64 representation during
-- -- serialisation, and decode from Base64 representation during deserialisation.
-- -- This 'Lens' accepts and returns only raw unencoded data.
newDecrypt ::
  -- | 'ciphertextBlob'
  Prelude.ByteString ->
  Decrypt
newDecrypt :: ByteString -> Decrypt
newDecrypt ByteString
pCiphertextBlob_ =
  Decrypt'
    { $sel:encryptionAlgorithm:Decrypt' :: Maybe EncryptionAlgorithmSpec
encryptionAlgorithm = forall a. Maybe a
Prelude.Nothing,
      $sel:encryptionContext:Decrypt' :: Maybe (HashMap Text Text)
encryptionContext = forall a. Maybe a
Prelude.Nothing,
      $sel:grantTokens:Decrypt' :: Maybe [Text]
grantTokens = forall a. Maybe a
Prelude.Nothing,
      $sel:keyId:Decrypt' :: Maybe Text
keyId = forall a. Maybe a
Prelude.Nothing,
      $sel:ciphertextBlob:Decrypt' :: Base64
ciphertextBlob =
        Iso' Base64 ByteString
Data._Base64 forall t b. AReview t b -> b -> t
Lens.# ByteString
pCiphertextBlob_
    }

-- | Specifies the encryption algorithm that will be used to decrypt the
-- ciphertext. Specify the same algorithm that was used to encrypt the
-- data. If you specify a different algorithm, the @Decrypt@ operation
-- fails.
--
-- This parameter is required only when the ciphertext was encrypted under
-- an asymmetric KMS key. The default value, @SYMMETRIC_DEFAULT@,
-- represents the only supported algorithm that is valid for symmetric
-- encryption KMS keys.
decrypt_encryptionAlgorithm :: Lens.Lens' Decrypt (Prelude.Maybe EncryptionAlgorithmSpec)
decrypt_encryptionAlgorithm :: Lens' Decrypt (Maybe EncryptionAlgorithmSpec)
decrypt_encryptionAlgorithm = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Decrypt' {Maybe EncryptionAlgorithmSpec
encryptionAlgorithm :: Maybe EncryptionAlgorithmSpec
$sel:encryptionAlgorithm:Decrypt' :: Decrypt -> Maybe EncryptionAlgorithmSpec
encryptionAlgorithm} -> Maybe EncryptionAlgorithmSpec
encryptionAlgorithm) (\s :: Decrypt
s@Decrypt' {} Maybe EncryptionAlgorithmSpec
a -> Decrypt
s {$sel:encryptionAlgorithm:Decrypt' :: Maybe EncryptionAlgorithmSpec
encryptionAlgorithm = Maybe EncryptionAlgorithmSpec
a} :: Decrypt)

-- | Specifies the encryption context to use when decrypting the data. An
-- encryption context is valid only for
-- <https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#cryptographic-operations cryptographic operations>
-- with a symmetric encryption KMS key. The standard asymmetric encryption
-- algorithms and HMAC algorithms that KMS uses do not support an
-- encryption context.
--
-- An /encryption context/ is a collection of non-secret key-value pairs
-- that represent additional authenticated data. When you use an encryption
-- context to encrypt data, you must specify the same (an exact
-- case-sensitive match) encryption context to decrypt the data. An
-- encryption context is supported only on operations with symmetric
-- encryption KMS keys. On operations with symmetric encryption KMS keys,
-- an encryption context is optional, but it is strongly recommended.
--
-- For more information, see
-- <https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#encrypt_context Encryption context>
-- in the /Key Management Service Developer Guide/.
decrypt_encryptionContext :: Lens.Lens' Decrypt (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
decrypt_encryptionContext :: Lens' Decrypt (Maybe (HashMap Text Text))
decrypt_encryptionContext = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Decrypt' {Maybe (HashMap Text Text)
encryptionContext :: Maybe (HashMap Text Text)
$sel:encryptionContext:Decrypt' :: Decrypt -> Maybe (HashMap Text Text)
encryptionContext} -> Maybe (HashMap Text Text)
encryptionContext) (\s :: Decrypt
s@Decrypt' {} Maybe (HashMap Text Text)
a -> Decrypt
s {$sel:encryptionContext:Decrypt' :: Maybe (HashMap Text Text)
encryptionContext = Maybe (HashMap Text Text)
a} :: Decrypt) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A list of grant tokens.
--
-- Use a grant token when your permission to call this operation comes from
-- a new grant that has not yet achieved /eventual consistency/. For more
-- information, see
-- <https://docs.aws.amazon.com/kms/latest/developerguide/grants.html#grant_token Grant token>
-- and
-- <https://docs.aws.amazon.com/kms/latest/developerguide/grant-manage.html#using-grant-token Using a grant token>
-- in the /Key Management Service Developer Guide/.
decrypt_grantTokens :: Lens.Lens' Decrypt (Prelude.Maybe [Prelude.Text])
decrypt_grantTokens :: Lens' Decrypt (Maybe [Text])
decrypt_grantTokens = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Decrypt' {Maybe [Text]
grantTokens :: Maybe [Text]
$sel:grantTokens:Decrypt' :: Decrypt -> Maybe [Text]
grantTokens} -> Maybe [Text]
grantTokens) (\s :: Decrypt
s@Decrypt' {} Maybe [Text]
a -> Decrypt
s {$sel:grantTokens:Decrypt' :: Maybe [Text]
grantTokens = Maybe [Text]
a} :: Decrypt) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Specifies the KMS key that KMS uses to decrypt the ciphertext.
--
-- Enter a key ID of the KMS key that was used to encrypt the ciphertext.
-- If you identify a different KMS key, the @Decrypt@ operation throws an
-- @IncorrectKeyException@.
--
-- This parameter is required only when the ciphertext was encrypted under
-- an asymmetric KMS key. If you used a symmetric encryption KMS key, KMS
-- can get the KMS key from metadata that it adds to the symmetric
-- ciphertext blob. However, it is always recommended as a best practice.
-- This practice ensures that you use the KMS key that you intend.
--
-- To specify a KMS key, use its key ID, key ARN, alias name, or alias ARN.
-- When using an alias name, prefix it with @\"alias\/\"@. To specify a KMS
-- key in a different Amazon Web Services account, you must use the key ARN
-- or alias ARN.
--
-- For example:
--
-- -   Key ID: @1234abcd-12ab-34cd-56ef-1234567890ab@
--
-- -   Key ARN:
--     @arn:aws:kms:us-east-2:111122223333:key\/1234abcd-12ab-34cd-56ef-1234567890ab@
--
-- -   Alias name: @alias\/ExampleAlias@
--
-- -   Alias ARN: @arn:aws:kms:us-east-2:111122223333:alias\/ExampleAlias@
--
-- To get the key ID and key ARN for a KMS key, use ListKeys or
-- DescribeKey. To get the alias name and alias ARN, use ListAliases.
decrypt_keyId :: Lens.Lens' Decrypt (Prelude.Maybe Prelude.Text)
decrypt_keyId :: Lens' Decrypt (Maybe Text)
decrypt_keyId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Decrypt' {Maybe Text
keyId :: Maybe Text
$sel:keyId:Decrypt' :: Decrypt -> Maybe Text
keyId} -> Maybe Text
keyId) (\s :: Decrypt
s@Decrypt' {} Maybe Text
a -> Decrypt
s {$sel:keyId:Decrypt' :: Maybe Text
keyId = Maybe Text
a} :: Decrypt)

-- | Ciphertext to be decrypted. The blob includes metadata.--
-- -- /Note:/ This 'Lens' automatically encodes and decodes Base64 data.
-- -- The underlying isomorphism will encode to Base64 representation during
-- -- serialisation, and decode from Base64 representation during deserialisation.
-- -- This 'Lens' accepts and returns only raw unencoded data.
decrypt_ciphertextBlob :: Lens.Lens' Decrypt Prelude.ByteString
decrypt_ciphertextBlob :: Lens' Decrypt ByteString
decrypt_ciphertextBlob = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Decrypt' {Base64
ciphertextBlob :: Base64
$sel:ciphertextBlob:Decrypt' :: Decrypt -> Base64
ciphertextBlob} -> Base64
ciphertextBlob) (\s :: Decrypt
s@Decrypt' {} Base64
a -> Decrypt
s {$sel:ciphertextBlob:Decrypt' :: Base64
ciphertextBlob = Base64
a} :: Decrypt) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. Iso' Base64 ByteString
Data._Base64

instance Core.AWSRequest Decrypt where
  type AWSResponse Decrypt = DecryptResponse
  request :: (Service -> Service) -> Decrypt -> Request Decrypt
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy Decrypt
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse Decrypt)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe EncryptionAlgorithmSpec
-> Maybe Text -> Maybe (Sensitive Base64) -> Int -> DecryptResponse
DecryptResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"EncryptionAlgorithm")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"KeyId")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"Plaintext")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable Decrypt where
  hashWithSalt :: Int -> Decrypt -> Int
hashWithSalt Int
_salt Decrypt' {Maybe [Text]
Maybe Text
Maybe (HashMap Text Text)
Maybe EncryptionAlgorithmSpec
Base64
ciphertextBlob :: Base64
keyId :: Maybe Text
grantTokens :: Maybe [Text]
encryptionContext :: Maybe (HashMap Text Text)
encryptionAlgorithm :: Maybe EncryptionAlgorithmSpec
$sel:ciphertextBlob:Decrypt' :: Decrypt -> Base64
$sel:keyId:Decrypt' :: Decrypt -> Maybe Text
$sel:grantTokens:Decrypt' :: Decrypt -> Maybe [Text]
$sel:encryptionContext:Decrypt' :: Decrypt -> Maybe (HashMap Text Text)
$sel:encryptionAlgorithm:Decrypt' :: Decrypt -> Maybe EncryptionAlgorithmSpec
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe EncryptionAlgorithmSpec
encryptionAlgorithm
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
encryptionContext
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
grantTokens
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
keyId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Base64
ciphertextBlob

instance Prelude.NFData Decrypt where
  rnf :: Decrypt -> ()
rnf Decrypt' {Maybe [Text]
Maybe Text
Maybe (HashMap Text Text)
Maybe EncryptionAlgorithmSpec
Base64
ciphertextBlob :: Base64
keyId :: Maybe Text
grantTokens :: Maybe [Text]
encryptionContext :: Maybe (HashMap Text Text)
encryptionAlgorithm :: Maybe EncryptionAlgorithmSpec
$sel:ciphertextBlob:Decrypt' :: Decrypt -> Base64
$sel:keyId:Decrypt' :: Decrypt -> Maybe Text
$sel:grantTokens:Decrypt' :: Decrypt -> Maybe [Text]
$sel:encryptionContext:Decrypt' :: Decrypt -> Maybe (HashMap Text Text)
$sel:encryptionAlgorithm:Decrypt' :: Decrypt -> Maybe EncryptionAlgorithmSpec
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe EncryptionAlgorithmSpec
encryptionAlgorithm
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
encryptionContext
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
grantTokens
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
keyId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Base64
ciphertextBlob

instance Data.ToHeaders Decrypt where
  toHeaders :: Decrypt -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# (ByteString
"TrentService.Decrypt" :: Prelude.ByteString),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON Decrypt where
  toJSON :: Decrypt -> Value
toJSON Decrypt' {Maybe [Text]
Maybe Text
Maybe (HashMap Text Text)
Maybe EncryptionAlgorithmSpec
Base64
ciphertextBlob :: Base64
keyId :: Maybe Text
grantTokens :: Maybe [Text]
encryptionContext :: Maybe (HashMap Text Text)
encryptionAlgorithm :: Maybe EncryptionAlgorithmSpec
$sel:ciphertextBlob:Decrypt' :: Decrypt -> Base64
$sel:keyId:Decrypt' :: Decrypt -> Maybe Text
$sel:grantTokens:Decrypt' :: Decrypt -> Maybe [Text]
$sel:encryptionContext:Decrypt' :: Decrypt -> Maybe (HashMap Text Text)
$sel:encryptionAlgorithm:Decrypt' :: Decrypt -> Maybe EncryptionAlgorithmSpec
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"EncryptionAlgorithm" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe EncryptionAlgorithmSpec
encryptionAlgorithm,
            (Key
"EncryptionContext" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
encryptionContext,
            (Key
"GrantTokens" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
grantTokens,
            (Key
"KeyId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
keyId,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"CiphertextBlob" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Base64
ciphertextBlob)
          ]
      )

instance Data.ToPath Decrypt where
  toPath :: Decrypt -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Data.ToQuery Decrypt where
  toQuery :: Decrypt -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newDecryptResponse' smart constructor.
data DecryptResponse = DecryptResponse'
  { -- | The encryption algorithm that was used to decrypt the ciphertext.
    DecryptResponse -> Maybe EncryptionAlgorithmSpec
encryptionAlgorithm :: Prelude.Maybe EncryptionAlgorithmSpec,
    -- | The Amazon Resource Name
    -- (<https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id-key-ARN key ARN>)
    -- of the KMS key that was used to decrypt the ciphertext.
    DecryptResponse -> Maybe Text
keyId :: Prelude.Maybe Prelude.Text,
    -- | Decrypted plaintext data. When you use the HTTP API or the Amazon Web
    -- Services CLI, the value is Base64-encoded. Otherwise, it is not
    -- Base64-encoded.
    DecryptResponse -> Maybe (Sensitive Base64)
plaintext :: Prelude.Maybe (Data.Sensitive Data.Base64),
    -- | The response's http status code.
    DecryptResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DecryptResponse -> DecryptResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DecryptResponse -> DecryptResponse -> Bool
$c/= :: DecryptResponse -> DecryptResponse -> Bool
== :: DecryptResponse -> DecryptResponse -> Bool
$c== :: DecryptResponse -> DecryptResponse -> Bool
Prelude.Eq, Int -> DecryptResponse -> ShowS
[DecryptResponse] -> ShowS
DecryptResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DecryptResponse] -> ShowS
$cshowList :: [DecryptResponse] -> ShowS
show :: DecryptResponse -> String
$cshow :: DecryptResponse -> String
showsPrec :: Int -> DecryptResponse -> ShowS
$cshowsPrec :: Int -> DecryptResponse -> ShowS
Prelude.Show, forall x. Rep DecryptResponse x -> DecryptResponse
forall x. DecryptResponse -> Rep DecryptResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DecryptResponse x -> DecryptResponse
$cfrom :: forall x. DecryptResponse -> Rep DecryptResponse x
Prelude.Generic)

-- |
-- Create a value of 'DecryptResponse' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'encryptionAlgorithm', 'decryptResponse_encryptionAlgorithm' - The encryption algorithm that was used to decrypt the ciphertext.
--
-- 'keyId', 'decryptResponse_keyId' - The Amazon Resource Name
-- (<https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id-key-ARN key ARN>)
-- of the KMS key that was used to decrypt the ciphertext.
--
-- 'plaintext', 'decryptResponse_plaintext' - Decrypted plaintext data. When you use the HTTP API or the Amazon Web
-- Services CLI, the value is Base64-encoded. Otherwise, it is not
-- Base64-encoded.--
-- -- /Note:/ This 'Lens' automatically encodes and decodes Base64 data.
-- -- The underlying isomorphism will encode to Base64 representation during
-- -- serialisation, and decode from Base64 representation during deserialisation.
-- -- This 'Lens' accepts and returns only raw unencoded data.
--
-- 'httpStatus', 'decryptResponse_httpStatus' - The response's http status code.
newDecryptResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DecryptResponse
newDecryptResponse :: Int -> DecryptResponse
newDecryptResponse Int
pHttpStatus_ =
  DecryptResponse'
    { $sel:encryptionAlgorithm:DecryptResponse' :: Maybe EncryptionAlgorithmSpec
encryptionAlgorithm =
        forall a. Maybe a
Prelude.Nothing,
      $sel:keyId:DecryptResponse' :: Maybe Text
keyId = forall a. Maybe a
Prelude.Nothing,
      $sel:plaintext:DecryptResponse' :: Maybe (Sensitive Base64)
plaintext = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DecryptResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The encryption algorithm that was used to decrypt the ciphertext.
decryptResponse_encryptionAlgorithm :: Lens.Lens' DecryptResponse (Prelude.Maybe EncryptionAlgorithmSpec)
decryptResponse_encryptionAlgorithm :: Lens' DecryptResponse (Maybe EncryptionAlgorithmSpec)
decryptResponse_encryptionAlgorithm = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DecryptResponse' {Maybe EncryptionAlgorithmSpec
encryptionAlgorithm :: Maybe EncryptionAlgorithmSpec
$sel:encryptionAlgorithm:DecryptResponse' :: DecryptResponse -> Maybe EncryptionAlgorithmSpec
encryptionAlgorithm} -> Maybe EncryptionAlgorithmSpec
encryptionAlgorithm) (\s :: DecryptResponse
s@DecryptResponse' {} Maybe EncryptionAlgorithmSpec
a -> DecryptResponse
s {$sel:encryptionAlgorithm:DecryptResponse' :: Maybe EncryptionAlgorithmSpec
encryptionAlgorithm = Maybe EncryptionAlgorithmSpec
a} :: DecryptResponse)

-- | The Amazon Resource Name
-- (<https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id-key-ARN key ARN>)
-- of the KMS key that was used to decrypt the ciphertext.
decryptResponse_keyId :: Lens.Lens' DecryptResponse (Prelude.Maybe Prelude.Text)
decryptResponse_keyId :: Lens' DecryptResponse (Maybe Text)
decryptResponse_keyId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DecryptResponse' {Maybe Text
keyId :: Maybe Text
$sel:keyId:DecryptResponse' :: DecryptResponse -> Maybe Text
keyId} -> Maybe Text
keyId) (\s :: DecryptResponse
s@DecryptResponse' {} Maybe Text
a -> DecryptResponse
s {$sel:keyId:DecryptResponse' :: Maybe Text
keyId = Maybe Text
a} :: DecryptResponse)

-- | Decrypted plaintext data. When you use the HTTP API or the Amazon Web
-- Services CLI, the value is Base64-encoded. Otherwise, it is not
-- Base64-encoded.--
-- -- /Note:/ This 'Lens' automatically encodes and decodes Base64 data.
-- -- The underlying isomorphism will encode to Base64 representation during
-- -- serialisation, and decode from Base64 representation during deserialisation.
-- -- This 'Lens' accepts and returns only raw unencoded data.
decryptResponse_plaintext :: Lens.Lens' DecryptResponse (Prelude.Maybe Prelude.ByteString)
decryptResponse_plaintext :: Lens' DecryptResponse (Maybe ByteString)
decryptResponse_plaintext = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DecryptResponse' {Maybe (Sensitive Base64)
plaintext :: Maybe (Sensitive Base64)
$sel:plaintext:DecryptResponse' :: DecryptResponse -> Maybe (Sensitive Base64)
plaintext} -> Maybe (Sensitive Base64)
plaintext) (\s :: DecryptResponse
s@DecryptResponse' {} Maybe (Sensitive Base64)
a -> DecryptResponse
s {$sel:plaintext:DecryptResponse' :: Maybe (Sensitive Base64)
plaintext = Maybe (Sensitive Base64)
a} :: DecryptResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping (forall a. Iso' (Sensitive a) a
Data._Sensitive forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. Iso' Base64 ByteString
Data._Base64)

-- | The response's http status code.
decryptResponse_httpStatus :: Lens.Lens' DecryptResponse Prelude.Int
decryptResponse_httpStatus :: Lens' DecryptResponse Int
decryptResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DecryptResponse' {Int
httpStatus :: Int
$sel:httpStatus:DecryptResponse' :: DecryptResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: DecryptResponse
s@DecryptResponse' {} Int
a -> DecryptResponse
s {$sel:httpStatus:DecryptResponse' :: Int
httpStatus = Int
a} :: DecryptResponse)

instance Prelude.NFData DecryptResponse where
  rnf :: DecryptResponse -> ()
rnf DecryptResponse' {Int
Maybe Text
Maybe (Sensitive Base64)
Maybe EncryptionAlgorithmSpec
httpStatus :: Int
plaintext :: Maybe (Sensitive Base64)
keyId :: Maybe Text
encryptionAlgorithm :: Maybe EncryptionAlgorithmSpec
$sel:httpStatus:DecryptResponse' :: DecryptResponse -> Int
$sel:plaintext:DecryptResponse' :: DecryptResponse -> Maybe (Sensitive Base64)
$sel:keyId:DecryptResponse' :: DecryptResponse -> Maybe Text
$sel:encryptionAlgorithm:DecryptResponse' :: DecryptResponse -> Maybe EncryptionAlgorithmSpec
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe EncryptionAlgorithmSpec
encryptionAlgorithm
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
keyId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (Sensitive Base64)
plaintext
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus