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

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

-- |
-- Module      : Amazonka.Glacier.Types.Encryption
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Glacier.Types.Encryption where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Glacier.Types.EncryptionType
import qualified Amazonka.Prelude as Prelude

-- | Contains information about the encryption used to store the job results
-- in Amazon S3.
--
-- /See:/ 'newEncryption' smart constructor.
data Encryption = Encryption'
  { -- | The server-side encryption algorithm used when storing job results in
    -- Amazon S3, for example @AES256@ or @aws:kms@.
    Encryption -> Maybe EncryptionType
encryptionType :: Prelude.Maybe EncryptionType,
    -- | Optional. If the encryption type is @aws:kms@, you can use this value to
    -- specify the encryption context for the job results.
    Encryption -> Maybe Text
kmsContext :: Prelude.Maybe Prelude.Text,
    -- | The AWS KMS key ID to use for object encryption. All GET and PUT
    -- requests for an object protected by AWS KMS fail if not made by using
    -- Secure Sockets Layer (SSL) or Signature Version 4.
    Encryption -> Maybe Text
kmsKeyId :: Prelude.Maybe Prelude.Text
  }
  deriving (Encryption -> Encryption -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Encryption -> Encryption -> Bool
$c/= :: Encryption -> Encryption -> Bool
== :: Encryption -> Encryption -> Bool
$c== :: Encryption -> Encryption -> Bool
Prelude.Eq, ReadPrec [Encryption]
ReadPrec Encryption
Int -> ReadS Encryption
ReadS [Encryption]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Encryption]
$creadListPrec :: ReadPrec [Encryption]
readPrec :: ReadPrec Encryption
$creadPrec :: ReadPrec Encryption
readList :: ReadS [Encryption]
$creadList :: ReadS [Encryption]
readsPrec :: Int -> ReadS Encryption
$creadsPrec :: Int -> ReadS Encryption
Prelude.Read, Int -> Encryption -> ShowS
[Encryption] -> ShowS
Encryption -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Encryption] -> ShowS
$cshowList :: [Encryption] -> ShowS
show :: Encryption -> String
$cshow :: Encryption -> String
showsPrec :: Int -> Encryption -> ShowS
$cshowsPrec :: Int -> Encryption -> ShowS
Prelude.Show, forall x. Rep Encryption x -> Encryption
forall x. Encryption -> Rep Encryption x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Encryption x -> Encryption
$cfrom :: forall x. Encryption -> Rep Encryption x
Prelude.Generic)

-- |
-- Create a value of 'Encryption' 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:
--
-- 'encryptionType', 'encryption_encryptionType' - The server-side encryption algorithm used when storing job results in
-- Amazon S3, for example @AES256@ or @aws:kms@.
--
-- 'kmsContext', 'encryption_kmsContext' - Optional. If the encryption type is @aws:kms@, you can use this value to
-- specify the encryption context for the job results.
--
-- 'kmsKeyId', 'encryption_kmsKeyId' - The AWS KMS key ID to use for object encryption. All GET and PUT
-- requests for an object protected by AWS KMS fail if not made by using
-- Secure Sockets Layer (SSL) or Signature Version 4.
newEncryption ::
  Encryption
newEncryption :: Encryption
newEncryption =
  Encryption'
    { $sel:encryptionType:Encryption' :: Maybe EncryptionType
encryptionType = forall a. Maybe a
Prelude.Nothing,
      $sel:kmsContext:Encryption' :: Maybe Text
kmsContext = forall a. Maybe a
Prelude.Nothing,
      $sel:kmsKeyId:Encryption' :: Maybe Text
kmsKeyId = forall a. Maybe a
Prelude.Nothing
    }

-- | The server-side encryption algorithm used when storing job results in
-- Amazon S3, for example @AES256@ or @aws:kms@.
encryption_encryptionType :: Lens.Lens' Encryption (Prelude.Maybe EncryptionType)
encryption_encryptionType :: Lens' Encryption (Maybe EncryptionType)
encryption_encryptionType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Encryption' {Maybe EncryptionType
encryptionType :: Maybe EncryptionType
$sel:encryptionType:Encryption' :: Encryption -> Maybe EncryptionType
encryptionType} -> Maybe EncryptionType
encryptionType) (\s :: Encryption
s@Encryption' {} Maybe EncryptionType
a -> Encryption
s {$sel:encryptionType:Encryption' :: Maybe EncryptionType
encryptionType = Maybe EncryptionType
a} :: Encryption)

-- | Optional. If the encryption type is @aws:kms@, you can use this value to
-- specify the encryption context for the job results.
encryption_kmsContext :: Lens.Lens' Encryption (Prelude.Maybe Prelude.Text)
encryption_kmsContext :: Lens' Encryption (Maybe Text)
encryption_kmsContext = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Encryption' {Maybe Text
kmsContext :: Maybe Text
$sel:kmsContext:Encryption' :: Encryption -> Maybe Text
kmsContext} -> Maybe Text
kmsContext) (\s :: Encryption
s@Encryption' {} Maybe Text
a -> Encryption
s {$sel:kmsContext:Encryption' :: Maybe Text
kmsContext = Maybe Text
a} :: Encryption)

-- | The AWS KMS key ID to use for object encryption. All GET and PUT
-- requests for an object protected by AWS KMS fail if not made by using
-- Secure Sockets Layer (SSL) or Signature Version 4.
encryption_kmsKeyId :: Lens.Lens' Encryption (Prelude.Maybe Prelude.Text)
encryption_kmsKeyId :: Lens' Encryption (Maybe Text)
encryption_kmsKeyId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Encryption' {Maybe Text
kmsKeyId :: Maybe Text
$sel:kmsKeyId:Encryption' :: Encryption -> Maybe Text
kmsKeyId} -> Maybe Text
kmsKeyId) (\s :: Encryption
s@Encryption' {} Maybe Text
a -> Encryption
s {$sel:kmsKeyId:Encryption' :: Maybe Text
kmsKeyId = Maybe Text
a} :: Encryption)

instance Data.FromJSON Encryption where
  parseJSON :: Value -> Parser Encryption
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Encryption"
      ( \Object
x ->
          Maybe EncryptionType -> Maybe Text -> Maybe Text -> Encryption
Encryption'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"EncryptionType")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"KMSContext")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"KMSKeyId")
      )

instance Prelude.Hashable Encryption where
  hashWithSalt :: Int -> Encryption -> Int
hashWithSalt Int
_salt Encryption' {Maybe Text
Maybe EncryptionType
kmsKeyId :: Maybe Text
kmsContext :: Maybe Text
encryptionType :: Maybe EncryptionType
$sel:kmsKeyId:Encryption' :: Encryption -> Maybe Text
$sel:kmsContext:Encryption' :: Encryption -> Maybe Text
$sel:encryptionType:Encryption' :: Encryption -> Maybe EncryptionType
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe EncryptionType
encryptionType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
kmsContext
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
kmsKeyId

instance Prelude.NFData Encryption where
  rnf :: Encryption -> ()
rnf Encryption' {Maybe Text
Maybe EncryptionType
kmsKeyId :: Maybe Text
kmsContext :: Maybe Text
encryptionType :: Maybe EncryptionType
$sel:kmsKeyId:Encryption' :: Encryption -> Maybe Text
$sel:kmsContext:Encryption' :: Encryption -> Maybe Text
$sel:encryptionType:Encryption' :: Encryption -> Maybe EncryptionType
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe EncryptionType
encryptionType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
kmsContext
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
kmsKeyId

instance Data.ToJSON Encryption where
  toJSON :: Encryption -> Value
toJSON Encryption' {Maybe Text
Maybe EncryptionType
kmsKeyId :: Maybe Text
kmsContext :: Maybe Text
encryptionType :: Maybe EncryptionType
$sel:kmsKeyId:Encryption' :: Encryption -> Maybe Text
$sel:kmsContext:Encryption' :: Encryption -> Maybe Text
$sel:encryptionType:Encryption' :: Encryption -> Maybe EncryptionType
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"EncryptionType" 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 EncryptionType
encryptionType,
            (Key
"KMSContext" 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
kmsContext,
            (Key
"KMSKeyId" 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
kmsKeyId
          ]
      )