{-# 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.Sign
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates a
-- <https://en.wikipedia.org/wiki/Digital_signature digital signature> for
-- a message or message digest by using the private key in an asymmetric
-- signing KMS key. To verify the signature, use the Verify operation, or
-- use the public key in the same asymmetric KMS key outside of KMS. 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/.
--
-- Digital signatures are generated and verified by using asymmetric key
-- pair, such as an RSA or ECC pair that is represented by an asymmetric
-- KMS key. The key owner (or an authorized user) uses their private key to
-- sign a message. Anyone with the public key can verify that the message
-- was signed with that particular private key and that the message hasn\'t
-- changed since it was signed.
--
-- To use the @Sign@ operation, provide the following information:
--
-- -   Use the @KeyId@ parameter to identify an asymmetric KMS key with a
--     @KeyUsage@ value of @SIGN_VERIFY@. To get the @KeyUsage@ value of a
--     KMS key, use the DescribeKey operation. The caller must have
--     @kms:Sign@ permission on the KMS key.
--
-- -   Use the @Message@ parameter to specify the message or message digest
--     to sign. You can submit messages of up to 4096 bytes. To sign a
--     larger message, generate a hash digest of the message, and then
--     provide the hash digest in the @Message@ parameter. To indicate
--     whether the message is a full message or a digest, use the
--     @MessageType@ parameter.
--
-- -   Choose a signing algorithm that is compatible with the KMS key.
--
-- When signing a message, be sure to record the KMS key and the signing
-- algorithm. This information is required to verify the signature.
--
-- Best practices recommend that you limit the time during which any
-- signature is effective. This deters an attack where the actor uses a
-- signed message to establish validity repeatedly or long after the
-- message is superseded. Signatures do not include a timestamp, but you
-- can include a timestamp in the signed message to help you detect when
-- its time to refresh the signature.
--
-- To verify the signature that this operation generates, use the Verify
-- operation. Or use the GetPublicKey operation to download the public key
-- and then use the public key to verify the signature outside of KMS.
--
-- 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:Sign>
-- (key policy)
--
-- __Related operations__: Verify
module Amazonka.KMS.Sign
  ( -- * Creating a Request
    Sign (..),
    newSign,

    -- * Request Lenses
    sign_grantTokens,
    sign_messageType,
    sign_keyId,
    sign_message,
    sign_signingAlgorithm,

    -- * Destructuring the Response
    SignResponse (..),
    newSignResponse,

    -- * Response Lenses
    signResponse_keyId,
    signResponse_signature,
    signResponse_signingAlgorithm,
    signResponse_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:/ 'newSign' smart constructor.
data Sign = Sign'
  { -- | 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/.
    Sign -> Maybe [Text]
grantTokens :: Prelude.Maybe [Prelude.Text],
    -- | Tells KMS whether the value of the @Message@ parameter is a message or
    -- message digest. The default value, RAW, indicates a message. To indicate
    -- a message digest, enter @DIGEST@.
    Sign -> Maybe MessageType
messageType :: Prelude.Maybe MessageType,
    -- | Identifies an asymmetric KMS key. KMS uses the private key in the
    -- asymmetric KMS key to sign the message. The @KeyUsage@ type of the KMS
    -- key must be @SIGN_VERIFY@. To find the @KeyUsage@ of a KMS key, use the
    -- DescribeKey operation.
    --
    -- 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.
    Sign -> Text
keyId :: Prelude.Text,
    -- | Specifies the message or message digest to sign. Messages can be 0-4096
    -- bytes. To sign a larger message, provide the message digest.
    --
    -- If you provide a message, KMS generates a hash digest of the message and
    -- then signs it.
    Sign -> Sensitive Base64
message :: Data.Sensitive Data.Base64,
    -- | Specifies the signing algorithm to use when signing the message.
    --
    -- Choose an algorithm that is compatible with the type and size of the
    -- specified asymmetric KMS key.
    Sign -> SigningAlgorithmSpec
signingAlgorithm :: SigningAlgorithmSpec
  }
  deriving (Sign -> Sign -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Sign -> Sign -> Bool
$c/= :: Sign -> Sign -> Bool
== :: Sign -> Sign -> Bool
$c== :: Sign -> Sign -> Bool
Prelude.Eq, Int -> Sign -> ShowS
[Sign] -> ShowS
Sign -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Sign] -> ShowS
$cshowList :: [Sign] -> ShowS
show :: Sign -> String
$cshow :: Sign -> String
showsPrec :: Int -> Sign -> ShowS
$cshowsPrec :: Int -> Sign -> ShowS
Prelude.Show, forall x. Rep Sign x -> Sign
forall x. Sign -> Rep Sign x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Sign x -> Sign
$cfrom :: forall x. Sign -> Rep Sign x
Prelude.Generic)

-- |
-- Create a value of 'Sign' 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:
--
-- 'grantTokens', 'sign_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/.
--
-- 'messageType', 'sign_messageType' - Tells KMS whether the value of the @Message@ parameter is a message or
-- message digest. The default value, RAW, indicates a message. To indicate
-- a message digest, enter @DIGEST@.
--
-- 'keyId', 'sign_keyId' - Identifies an asymmetric KMS key. KMS uses the private key in the
-- asymmetric KMS key to sign the message. The @KeyUsage@ type of the KMS
-- key must be @SIGN_VERIFY@. To find the @KeyUsage@ of a KMS key, use the
-- DescribeKey operation.
--
-- 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.
--
-- 'message', 'sign_message' - Specifies the message or message digest to sign. Messages can be 0-4096
-- bytes. To sign a larger message, provide the message digest.
--
-- If you provide a message, KMS generates a hash digest of the message and
-- then signs it.--
-- -- /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.
--
-- 'signingAlgorithm', 'sign_signingAlgorithm' - Specifies the signing algorithm to use when signing the message.
--
-- Choose an algorithm that is compatible with the type and size of the
-- specified asymmetric KMS key.
newSign ::
  -- | 'keyId'
  Prelude.Text ->
  -- | 'message'
  Prelude.ByteString ->
  -- | 'signingAlgorithm'
  SigningAlgorithmSpec ->
  Sign
newSign :: Text -> ByteString -> SigningAlgorithmSpec -> Sign
newSign Text
pKeyId_ ByteString
pMessage_ SigningAlgorithmSpec
pSigningAlgorithm_ =
  Sign'
    { $sel:grantTokens:Sign' :: Maybe [Text]
grantTokens = forall a. Maybe a
Prelude.Nothing,
      $sel:messageType:Sign' :: Maybe MessageType
messageType = forall a. Maybe a
Prelude.Nothing,
      $sel:keyId:Sign' :: Text
keyId = Text
pKeyId_,
      $sel:message:Sign' :: Sensitive Base64
message =
        forall a. Iso' (Sensitive a) a
Data._Sensitive
          forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. Iso' Base64 ByteString
Data._Base64
          forall t b. AReview t b -> b -> t
Lens.# ByteString
pMessage_,
      $sel:signingAlgorithm:Sign' :: SigningAlgorithmSpec
signingAlgorithm = SigningAlgorithmSpec
pSigningAlgorithm_
    }

-- | 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/.
sign_grantTokens :: Lens.Lens' Sign (Prelude.Maybe [Prelude.Text])
sign_grantTokens :: Lens' Sign (Maybe [Text])
sign_grantTokens = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Sign' {Maybe [Text]
grantTokens :: Maybe [Text]
$sel:grantTokens:Sign' :: Sign -> Maybe [Text]
grantTokens} -> Maybe [Text]
grantTokens) (\s :: Sign
s@Sign' {} Maybe [Text]
a -> Sign
s {$sel:grantTokens:Sign' :: Maybe [Text]
grantTokens = Maybe [Text]
a} :: Sign) 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

-- | Tells KMS whether the value of the @Message@ parameter is a message or
-- message digest. The default value, RAW, indicates a message. To indicate
-- a message digest, enter @DIGEST@.
sign_messageType :: Lens.Lens' Sign (Prelude.Maybe MessageType)
sign_messageType :: Lens' Sign (Maybe MessageType)
sign_messageType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Sign' {Maybe MessageType
messageType :: Maybe MessageType
$sel:messageType:Sign' :: Sign -> Maybe MessageType
messageType} -> Maybe MessageType
messageType) (\s :: Sign
s@Sign' {} Maybe MessageType
a -> Sign
s {$sel:messageType:Sign' :: Maybe MessageType
messageType = Maybe MessageType
a} :: Sign)

-- | Identifies an asymmetric KMS key. KMS uses the private key in the
-- asymmetric KMS key to sign the message. The @KeyUsage@ type of the KMS
-- key must be @SIGN_VERIFY@. To find the @KeyUsage@ of a KMS key, use the
-- DescribeKey operation.
--
-- 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.
sign_keyId :: Lens.Lens' Sign Prelude.Text
sign_keyId :: Lens' Sign Text
sign_keyId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Sign' {Text
keyId :: Text
$sel:keyId:Sign' :: Sign -> Text
keyId} -> Text
keyId) (\s :: Sign
s@Sign' {} Text
a -> Sign
s {$sel:keyId:Sign' :: Text
keyId = Text
a} :: Sign)

-- | Specifies the message or message digest to sign. Messages can be 0-4096
-- bytes. To sign a larger message, provide the message digest.
--
-- If you provide a message, KMS generates a hash digest of the message and
-- then signs it.--
-- -- /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.
sign_message :: Lens.Lens' Sign Prelude.ByteString
sign_message :: Lens' Sign ByteString
sign_message = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Sign' {Sensitive Base64
message :: Sensitive Base64
$sel:message:Sign' :: Sign -> Sensitive Base64
message} -> Sensitive Base64
message) (\s :: Sign
s@Sign' {} Sensitive Base64
a -> Sign
s {$sel:message:Sign' :: Sensitive Base64
message = Sensitive Base64
a} :: Sign) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a. Iso' (Sensitive a) a
Data._Sensitive forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. Iso' Base64 ByteString
Data._Base64

-- | Specifies the signing algorithm to use when signing the message.
--
-- Choose an algorithm that is compatible with the type and size of the
-- specified asymmetric KMS key.
sign_signingAlgorithm :: Lens.Lens' Sign SigningAlgorithmSpec
sign_signingAlgorithm :: Lens' Sign SigningAlgorithmSpec
sign_signingAlgorithm = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Sign' {SigningAlgorithmSpec
signingAlgorithm :: SigningAlgorithmSpec
$sel:signingAlgorithm:Sign' :: Sign -> SigningAlgorithmSpec
signingAlgorithm} -> SigningAlgorithmSpec
signingAlgorithm) (\s :: Sign
s@Sign' {} SigningAlgorithmSpec
a -> Sign
s {$sel:signingAlgorithm:Sign' :: SigningAlgorithmSpec
signingAlgorithm = SigningAlgorithmSpec
a} :: Sign)

instance Core.AWSRequest Sign where
  type AWSResponse Sign = SignResponse
  request :: (Service -> Service) -> Sign -> Request Sign
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 Sign
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse Sign)))
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 Text
-> Maybe Base64
-> Maybe SigningAlgorithmSpec
-> Int
-> SignResponse
SignResponse'
            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
"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
"Signature")
            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
"SigningAlgorithm")
            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 Sign where
  hashWithSalt :: Int -> Sign -> Int
hashWithSalt Int
_salt Sign' {Maybe [Text]
Maybe MessageType
Text
Sensitive Base64
SigningAlgorithmSpec
signingAlgorithm :: SigningAlgorithmSpec
message :: Sensitive Base64
keyId :: Text
messageType :: Maybe MessageType
grantTokens :: Maybe [Text]
$sel:signingAlgorithm:Sign' :: Sign -> SigningAlgorithmSpec
$sel:message:Sign' :: Sign -> Sensitive Base64
$sel:keyId:Sign' :: Sign -> Text
$sel:messageType:Sign' :: Sign -> Maybe MessageType
$sel:grantTokens:Sign' :: Sign -> Maybe [Text]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
grantTokens
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe MessageType
messageType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
keyId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Sensitive Base64
message
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` SigningAlgorithmSpec
signingAlgorithm

instance Prelude.NFData Sign where
  rnf :: Sign -> ()
rnf Sign' {Maybe [Text]
Maybe MessageType
Text
Sensitive Base64
SigningAlgorithmSpec
signingAlgorithm :: SigningAlgorithmSpec
message :: Sensitive Base64
keyId :: Text
messageType :: Maybe MessageType
grantTokens :: Maybe [Text]
$sel:signingAlgorithm:Sign' :: Sign -> SigningAlgorithmSpec
$sel:message:Sign' :: Sign -> Sensitive Base64
$sel:keyId:Sign' :: Sign -> Text
$sel:messageType:Sign' :: Sign -> Maybe MessageType
$sel:grantTokens:Sign' :: Sign -> Maybe [Text]
..} =
    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 MessageType
messageType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
keyId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Sensitive Base64
message
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf SigningAlgorithmSpec
signingAlgorithm

instance Data.ToHeaders Sign where
  toHeaders :: Sign -> 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.Sign" :: 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 Sign where
  toJSON :: Sign -> Value
toJSON Sign' {Maybe [Text]
Maybe MessageType
Text
Sensitive Base64
SigningAlgorithmSpec
signingAlgorithm :: SigningAlgorithmSpec
message :: Sensitive Base64
keyId :: Text
messageType :: Maybe MessageType
grantTokens :: Maybe [Text]
$sel:signingAlgorithm:Sign' :: Sign -> SigningAlgorithmSpec
$sel:message:Sign' :: Sign -> Sensitive Base64
$sel:keyId:Sign' :: Sign -> Text
$sel:messageType:Sign' :: Sign -> Maybe MessageType
$sel:grantTokens:Sign' :: Sign -> Maybe [Text]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (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
"MessageType" 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 MessageType
messageType,
            forall a. a -> Maybe a
Prelude.Just (Key
"KeyId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
keyId),
            forall a. a -> Maybe a
Prelude.Just (Key
"Message" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Sensitive Base64
message),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"SigningAlgorithm" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= SigningAlgorithmSpec
signingAlgorithm)
          ]
      )

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

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

-- | /See:/ 'newSignResponse' smart constructor.
data SignResponse = SignResponse'
  { -- | The Amazon Resource Name
    -- (<https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id-key-ARN key ARN>)
    -- of the asymmetric KMS key that was used to sign the message.
    SignResponse -> Maybe Text
keyId :: Prelude.Maybe Prelude.Text,
    -- | The cryptographic signature that was generated for the message.
    --
    -- -   When used with the supported RSA signing algorithms, the encoding of
    --     this value is defined by
    --     <https://tools.ietf.org/html/rfc8017 PKCS #1 in RFC 8017>.
    --
    -- -   When used with the @ECDSA_SHA_256@, @ECDSA_SHA_384@, or
    --     @ECDSA_SHA_512@ signing algorithms, this value is a DER-encoded
    --     object as defined by ANS X9.62–2005 and
    --     <https://tools.ietf.org/html/rfc3279#section-2.2.3 RFC 3279 Section 2.2.3>.
    --     This is the most commonly used signature format and is appropriate
    --     for most uses.
    --
    -- When you use the HTTP API or the Amazon Web Services CLI, the value is
    -- Base64-encoded. Otherwise, it is not Base64-encoded.
    SignResponse -> Maybe Base64
signature :: Prelude.Maybe Data.Base64,
    -- | The signing algorithm that was used to sign the message.
    SignResponse -> Maybe SigningAlgorithmSpec
signingAlgorithm :: Prelude.Maybe SigningAlgorithmSpec,
    -- | The response's http status code.
    SignResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (SignResponse -> SignResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SignResponse -> SignResponse -> Bool
$c/= :: SignResponse -> SignResponse -> Bool
== :: SignResponse -> SignResponse -> Bool
$c== :: SignResponse -> SignResponse -> Bool
Prelude.Eq, ReadPrec [SignResponse]
ReadPrec SignResponse
Int -> ReadS SignResponse
ReadS [SignResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SignResponse]
$creadListPrec :: ReadPrec [SignResponse]
readPrec :: ReadPrec SignResponse
$creadPrec :: ReadPrec SignResponse
readList :: ReadS [SignResponse]
$creadList :: ReadS [SignResponse]
readsPrec :: Int -> ReadS SignResponse
$creadsPrec :: Int -> ReadS SignResponse
Prelude.Read, Int -> SignResponse -> ShowS
[SignResponse] -> ShowS
SignResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SignResponse] -> ShowS
$cshowList :: [SignResponse] -> ShowS
show :: SignResponse -> String
$cshow :: SignResponse -> String
showsPrec :: Int -> SignResponse -> ShowS
$cshowsPrec :: Int -> SignResponse -> ShowS
Prelude.Show, forall x. Rep SignResponse x -> SignResponse
forall x. SignResponse -> Rep SignResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SignResponse x -> SignResponse
$cfrom :: forall x. SignResponse -> Rep SignResponse x
Prelude.Generic)

-- |
-- Create a value of 'SignResponse' 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:
--
-- 'keyId', 'signResponse_keyId' - The Amazon Resource Name
-- (<https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id-key-ARN key ARN>)
-- of the asymmetric KMS key that was used to sign the message.
--
-- 'signature', 'signResponse_signature' - The cryptographic signature that was generated for the message.
--
-- -   When used with the supported RSA signing algorithms, the encoding of
--     this value is defined by
--     <https://tools.ietf.org/html/rfc8017 PKCS #1 in RFC 8017>.
--
-- -   When used with the @ECDSA_SHA_256@, @ECDSA_SHA_384@, or
--     @ECDSA_SHA_512@ signing algorithms, this value is a DER-encoded
--     object as defined by ANS X9.62–2005 and
--     <https://tools.ietf.org/html/rfc3279#section-2.2.3 RFC 3279 Section 2.2.3>.
--     This is the most commonly used signature format and is appropriate
--     for most uses.
--
-- 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.
--
-- 'signingAlgorithm', 'signResponse_signingAlgorithm' - The signing algorithm that was used to sign the message.
--
-- 'httpStatus', 'signResponse_httpStatus' - The response's http status code.
newSignResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  SignResponse
newSignResponse :: Int -> SignResponse
newSignResponse Int
pHttpStatus_ =
  SignResponse'
    { $sel:keyId:SignResponse' :: Maybe Text
keyId = forall a. Maybe a
Prelude.Nothing,
      $sel:signature:SignResponse' :: Maybe Base64
signature = forall a. Maybe a
Prelude.Nothing,
      $sel:signingAlgorithm:SignResponse' :: Maybe SigningAlgorithmSpec
signingAlgorithm = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:SignResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

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

-- | The cryptographic signature that was generated for the message.
--
-- -   When used with the supported RSA signing algorithms, the encoding of
--     this value is defined by
--     <https://tools.ietf.org/html/rfc8017 PKCS #1 in RFC 8017>.
--
-- -   When used with the @ECDSA_SHA_256@, @ECDSA_SHA_384@, or
--     @ECDSA_SHA_512@ signing algorithms, this value is a DER-encoded
--     object as defined by ANS X9.62–2005 and
--     <https://tools.ietf.org/html/rfc3279#section-2.2.3 RFC 3279 Section 2.2.3>.
--     This is the most commonly used signature format and is appropriate
--     for most uses.
--
-- 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.
signResponse_signature :: Lens.Lens' SignResponse (Prelude.Maybe Prelude.ByteString)
signResponse_signature :: Lens' SignResponse (Maybe ByteString)
signResponse_signature = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SignResponse' {Maybe Base64
signature :: Maybe Base64
$sel:signature:SignResponse' :: SignResponse -> Maybe Base64
signature} -> Maybe Base64
signature) (\s :: SignResponse
s@SignResponse' {} Maybe Base64
a -> SignResponse
s {$sel:signature:SignResponse' :: Maybe Base64
signature = Maybe Base64
a} :: SignResponse) 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 Iso' Base64 ByteString
Data._Base64

-- | The signing algorithm that was used to sign the message.
signResponse_signingAlgorithm :: Lens.Lens' SignResponse (Prelude.Maybe SigningAlgorithmSpec)
signResponse_signingAlgorithm :: Lens' SignResponse (Maybe SigningAlgorithmSpec)
signResponse_signingAlgorithm = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SignResponse' {Maybe SigningAlgorithmSpec
signingAlgorithm :: Maybe SigningAlgorithmSpec
$sel:signingAlgorithm:SignResponse' :: SignResponse -> Maybe SigningAlgorithmSpec
signingAlgorithm} -> Maybe SigningAlgorithmSpec
signingAlgorithm) (\s :: SignResponse
s@SignResponse' {} Maybe SigningAlgorithmSpec
a -> SignResponse
s {$sel:signingAlgorithm:SignResponse' :: Maybe SigningAlgorithmSpec
signingAlgorithm = Maybe SigningAlgorithmSpec
a} :: SignResponse)

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

instance Prelude.NFData SignResponse where
  rnf :: SignResponse -> ()
rnf SignResponse' {Int
Maybe Text
Maybe Base64
Maybe SigningAlgorithmSpec
httpStatus :: Int
signingAlgorithm :: Maybe SigningAlgorithmSpec
signature :: Maybe Base64
keyId :: Maybe Text
$sel:httpStatus:SignResponse' :: SignResponse -> Int
$sel:signingAlgorithm:SignResponse' :: SignResponse -> Maybe SigningAlgorithmSpec
$sel:signature:SignResponse' :: SignResponse -> Maybe Base64
$sel:keyId:SignResponse' :: SignResponse -> Maybe Text
..} =
    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 Base64
signature
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe SigningAlgorithmSpec
signingAlgorithm
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus