{-# 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.MediaPackage.Types.CmafEncryption
-- 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.MediaPackage.Types.CmafEncryption where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.MediaPackage.Types.CmafEncryptionMethod
import Amazonka.MediaPackage.Types.SpekeKeyProvider
import qualified Amazonka.Prelude as Prelude

-- | A Common Media Application Format (CMAF) encryption configuration.
--
-- /See:/ 'newCmafEncryption' smart constructor.
data CmafEncryption = CmafEncryption'
  { -- | An optional 128-bit, 16-byte hex value represented by a 32-character
    -- string, used in conjunction with the key for encrypting blocks. If you
    -- don\'t specify a value, then MediaPackage creates the constant
    -- initialization vector (IV).
    CmafEncryption -> Maybe Text
constantInitializationVector :: Prelude.Maybe Prelude.Text,
    CmafEncryption -> Maybe CmafEncryptionMethod
encryptionMethod :: Prelude.Maybe CmafEncryptionMethod,
    -- | Time (in seconds) between each encryption key rotation.
    CmafEncryption -> Maybe Int
keyRotationIntervalSeconds :: Prelude.Maybe Prelude.Int,
    CmafEncryption -> SpekeKeyProvider
spekeKeyProvider :: SpekeKeyProvider
  }
  deriving (CmafEncryption -> CmafEncryption -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CmafEncryption -> CmafEncryption -> Bool
$c/= :: CmafEncryption -> CmafEncryption -> Bool
== :: CmafEncryption -> CmafEncryption -> Bool
$c== :: CmafEncryption -> CmafEncryption -> Bool
Prelude.Eq, ReadPrec [CmafEncryption]
ReadPrec CmafEncryption
Int -> ReadS CmafEncryption
ReadS [CmafEncryption]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CmafEncryption]
$creadListPrec :: ReadPrec [CmafEncryption]
readPrec :: ReadPrec CmafEncryption
$creadPrec :: ReadPrec CmafEncryption
readList :: ReadS [CmafEncryption]
$creadList :: ReadS [CmafEncryption]
readsPrec :: Int -> ReadS CmafEncryption
$creadsPrec :: Int -> ReadS CmafEncryption
Prelude.Read, Int -> CmafEncryption -> ShowS
[CmafEncryption] -> ShowS
CmafEncryption -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CmafEncryption] -> ShowS
$cshowList :: [CmafEncryption] -> ShowS
show :: CmafEncryption -> String
$cshow :: CmafEncryption -> String
showsPrec :: Int -> CmafEncryption -> ShowS
$cshowsPrec :: Int -> CmafEncryption -> ShowS
Prelude.Show, forall x. Rep CmafEncryption x -> CmafEncryption
forall x. CmafEncryption -> Rep CmafEncryption x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CmafEncryption x -> CmafEncryption
$cfrom :: forall x. CmafEncryption -> Rep CmafEncryption x
Prelude.Generic)

-- |
-- Create a value of 'CmafEncryption' 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:
--
-- 'constantInitializationVector', 'cmafEncryption_constantInitializationVector' - An optional 128-bit, 16-byte hex value represented by a 32-character
-- string, used in conjunction with the key for encrypting blocks. If you
-- don\'t specify a value, then MediaPackage creates the constant
-- initialization vector (IV).
--
-- 'encryptionMethod', 'cmafEncryption_encryptionMethod' - Undocumented member.
--
-- 'keyRotationIntervalSeconds', 'cmafEncryption_keyRotationIntervalSeconds' - Time (in seconds) between each encryption key rotation.
--
-- 'spekeKeyProvider', 'cmafEncryption_spekeKeyProvider' - Undocumented member.
newCmafEncryption ::
  -- | 'spekeKeyProvider'
  SpekeKeyProvider ->
  CmafEncryption
newCmafEncryption :: SpekeKeyProvider -> CmafEncryption
newCmafEncryption SpekeKeyProvider
pSpekeKeyProvider_ =
  CmafEncryption'
    { $sel:constantInitializationVector:CmafEncryption' :: Maybe Text
constantInitializationVector =
        forall a. Maybe a
Prelude.Nothing,
      $sel:encryptionMethod:CmafEncryption' :: Maybe CmafEncryptionMethod
encryptionMethod = forall a. Maybe a
Prelude.Nothing,
      $sel:keyRotationIntervalSeconds:CmafEncryption' :: Maybe Int
keyRotationIntervalSeconds = forall a. Maybe a
Prelude.Nothing,
      $sel:spekeKeyProvider:CmafEncryption' :: SpekeKeyProvider
spekeKeyProvider = SpekeKeyProvider
pSpekeKeyProvider_
    }

-- | An optional 128-bit, 16-byte hex value represented by a 32-character
-- string, used in conjunction with the key for encrypting blocks. If you
-- don\'t specify a value, then MediaPackage creates the constant
-- initialization vector (IV).
cmafEncryption_constantInitializationVector :: Lens.Lens' CmafEncryption (Prelude.Maybe Prelude.Text)
cmafEncryption_constantInitializationVector :: Lens' CmafEncryption (Maybe Text)
cmafEncryption_constantInitializationVector = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CmafEncryption' {Maybe Text
constantInitializationVector :: Maybe Text
$sel:constantInitializationVector:CmafEncryption' :: CmafEncryption -> Maybe Text
constantInitializationVector} -> Maybe Text
constantInitializationVector) (\s :: CmafEncryption
s@CmafEncryption' {} Maybe Text
a -> CmafEncryption
s {$sel:constantInitializationVector:CmafEncryption' :: Maybe Text
constantInitializationVector = Maybe Text
a} :: CmafEncryption)

-- | Undocumented member.
cmafEncryption_encryptionMethod :: Lens.Lens' CmafEncryption (Prelude.Maybe CmafEncryptionMethod)
cmafEncryption_encryptionMethod :: Lens' CmafEncryption (Maybe CmafEncryptionMethod)
cmafEncryption_encryptionMethod = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CmafEncryption' {Maybe CmafEncryptionMethod
encryptionMethod :: Maybe CmafEncryptionMethod
$sel:encryptionMethod:CmafEncryption' :: CmafEncryption -> Maybe CmafEncryptionMethod
encryptionMethod} -> Maybe CmafEncryptionMethod
encryptionMethod) (\s :: CmafEncryption
s@CmafEncryption' {} Maybe CmafEncryptionMethod
a -> CmafEncryption
s {$sel:encryptionMethod:CmafEncryption' :: Maybe CmafEncryptionMethod
encryptionMethod = Maybe CmafEncryptionMethod
a} :: CmafEncryption)

-- | Time (in seconds) between each encryption key rotation.
cmafEncryption_keyRotationIntervalSeconds :: Lens.Lens' CmafEncryption (Prelude.Maybe Prelude.Int)
cmafEncryption_keyRotationIntervalSeconds :: Lens' CmafEncryption (Maybe Int)
cmafEncryption_keyRotationIntervalSeconds = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CmafEncryption' {Maybe Int
keyRotationIntervalSeconds :: Maybe Int
$sel:keyRotationIntervalSeconds:CmafEncryption' :: CmafEncryption -> Maybe Int
keyRotationIntervalSeconds} -> Maybe Int
keyRotationIntervalSeconds) (\s :: CmafEncryption
s@CmafEncryption' {} Maybe Int
a -> CmafEncryption
s {$sel:keyRotationIntervalSeconds:CmafEncryption' :: Maybe Int
keyRotationIntervalSeconds = Maybe Int
a} :: CmafEncryption)

-- | Undocumented member.
cmafEncryption_spekeKeyProvider :: Lens.Lens' CmafEncryption SpekeKeyProvider
cmafEncryption_spekeKeyProvider :: Lens' CmafEncryption SpekeKeyProvider
cmafEncryption_spekeKeyProvider = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CmafEncryption' {SpekeKeyProvider
spekeKeyProvider :: SpekeKeyProvider
$sel:spekeKeyProvider:CmafEncryption' :: CmafEncryption -> SpekeKeyProvider
spekeKeyProvider} -> SpekeKeyProvider
spekeKeyProvider) (\s :: CmafEncryption
s@CmafEncryption' {} SpekeKeyProvider
a -> CmafEncryption
s {$sel:spekeKeyProvider:CmafEncryption' :: SpekeKeyProvider
spekeKeyProvider = SpekeKeyProvider
a} :: CmafEncryption)

instance Data.FromJSON CmafEncryption where
  parseJSON :: Value -> Parser CmafEncryption
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"CmafEncryption"
      ( \Object
x ->
          Maybe Text
-> Maybe CmafEncryptionMethod
-> Maybe Int
-> SpekeKeyProvider
-> CmafEncryption
CmafEncryption'
            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
"constantInitializationVector")
            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
"encryptionMethod")
            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
"keyRotationIntervalSeconds")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"spekeKeyProvider")
      )

instance Prelude.Hashable CmafEncryption where
  hashWithSalt :: Int -> CmafEncryption -> Int
hashWithSalt Int
_salt CmafEncryption' {Maybe Int
Maybe Text
Maybe CmafEncryptionMethod
SpekeKeyProvider
spekeKeyProvider :: SpekeKeyProvider
keyRotationIntervalSeconds :: Maybe Int
encryptionMethod :: Maybe CmafEncryptionMethod
constantInitializationVector :: Maybe Text
$sel:spekeKeyProvider:CmafEncryption' :: CmafEncryption -> SpekeKeyProvider
$sel:keyRotationIntervalSeconds:CmafEncryption' :: CmafEncryption -> Maybe Int
$sel:encryptionMethod:CmafEncryption' :: CmafEncryption -> Maybe CmafEncryptionMethod
$sel:constantInitializationVector:CmafEncryption' :: CmafEncryption -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
constantInitializationVector
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe CmafEncryptionMethod
encryptionMethod
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
keyRotationIntervalSeconds
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` SpekeKeyProvider
spekeKeyProvider

instance Prelude.NFData CmafEncryption where
  rnf :: CmafEncryption -> ()
rnf CmafEncryption' {Maybe Int
Maybe Text
Maybe CmafEncryptionMethod
SpekeKeyProvider
spekeKeyProvider :: SpekeKeyProvider
keyRotationIntervalSeconds :: Maybe Int
encryptionMethod :: Maybe CmafEncryptionMethod
constantInitializationVector :: Maybe Text
$sel:spekeKeyProvider:CmafEncryption' :: CmafEncryption -> SpekeKeyProvider
$sel:keyRotationIntervalSeconds:CmafEncryption' :: CmafEncryption -> Maybe Int
$sel:encryptionMethod:CmafEncryption' :: CmafEncryption -> Maybe CmafEncryptionMethod
$sel:constantInitializationVector:CmafEncryption' :: CmafEncryption -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
constantInitializationVector
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe CmafEncryptionMethod
encryptionMethod
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
keyRotationIntervalSeconds
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf SpekeKeyProvider
spekeKeyProvider

instance Data.ToJSON CmafEncryption where
  toJSON :: CmafEncryption -> Value
toJSON CmafEncryption' {Maybe Int
Maybe Text
Maybe CmafEncryptionMethod
SpekeKeyProvider
spekeKeyProvider :: SpekeKeyProvider
keyRotationIntervalSeconds :: Maybe Int
encryptionMethod :: Maybe CmafEncryptionMethod
constantInitializationVector :: Maybe Text
$sel:spekeKeyProvider:CmafEncryption' :: CmafEncryption -> SpekeKeyProvider
$sel:keyRotationIntervalSeconds:CmafEncryption' :: CmafEncryption -> Maybe Int
$sel:encryptionMethod:CmafEncryption' :: CmafEncryption -> Maybe CmafEncryptionMethod
$sel:constantInitializationVector:CmafEncryption' :: CmafEncryption -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"constantInitializationVector" 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
constantInitializationVector,
            (Key
"encryptionMethod" 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 CmafEncryptionMethod
encryptionMethod,
            (Key
"keyRotationIntervalSeconds" 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 Int
keyRotationIntervalSeconds,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"spekeKeyProvider" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= SpekeKeyProvider
spekeKeyProvider)
          ]
      )