{-# 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.HlsEncryption
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.MediaPackage.Types.HlsEncryption where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.MediaPackage.Types.EncryptionMethod
import Amazonka.MediaPackage.Types.SpekeKeyProvider
import qualified Amazonka.Prelude as Prelude

-- | An HTTP Live Streaming (HLS) encryption configuration.
--
-- /See:/ 'newHlsEncryption' smart constructor.
data HlsEncryption = HlsEncryption'
  { -- | The encryption method to use.
    HlsEncryption -> Maybe EncryptionMethod
encryptionMethod :: Prelude.Maybe EncryptionMethod,
    -- | Interval (in seconds) between each encryption key rotation.
    HlsEncryption -> Maybe Int
keyRotationIntervalSeconds :: Prelude.Maybe Prelude.Int,
    -- | A constant initialization vector for encryption (optional). When not
    -- specified the initialization vector will be periodically rotated.
    HlsEncryption -> Maybe Text
constantInitializationVector :: Prelude.Maybe Prelude.Text,
    -- | When enabled, the EXT-X-KEY tag will be repeated in output manifests.
    HlsEncryption -> Maybe Bool
repeatExtXKey :: Prelude.Maybe Prelude.Bool,
    HlsEncryption -> SpekeKeyProvider
spekeKeyProvider :: SpekeKeyProvider
  }
  deriving (HlsEncryption -> HlsEncryption -> Bool
(HlsEncryption -> HlsEncryption -> Bool)
-> (HlsEncryption -> HlsEncryption -> Bool) -> Eq HlsEncryption
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HlsEncryption -> HlsEncryption -> Bool
$c/= :: HlsEncryption -> HlsEncryption -> Bool
== :: HlsEncryption -> HlsEncryption -> Bool
$c== :: HlsEncryption -> HlsEncryption -> Bool
Prelude.Eq, ReadPrec [HlsEncryption]
ReadPrec HlsEncryption
Int -> ReadS HlsEncryption
ReadS [HlsEncryption]
(Int -> ReadS HlsEncryption)
-> ReadS [HlsEncryption]
-> ReadPrec HlsEncryption
-> ReadPrec [HlsEncryption]
-> Read HlsEncryption
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [HlsEncryption]
$creadListPrec :: ReadPrec [HlsEncryption]
readPrec :: ReadPrec HlsEncryption
$creadPrec :: ReadPrec HlsEncryption
readList :: ReadS [HlsEncryption]
$creadList :: ReadS [HlsEncryption]
readsPrec :: Int -> ReadS HlsEncryption
$creadsPrec :: Int -> ReadS HlsEncryption
Prelude.Read, Int -> HlsEncryption -> ShowS
[HlsEncryption] -> ShowS
HlsEncryption -> String
(Int -> HlsEncryption -> ShowS)
-> (HlsEncryption -> String)
-> ([HlsEncryption] -> ShowS)
-> Show HlsEncryption
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HlsEncryption] -> ShowS
$cshowList :: [HlsEncryption] -> ShowS
show :: HlsEncryption -> String
$cshow :: HlsEncryption -> String
showsPrec :: Int -> HlsEncryption -> ShowS
$cshowsPrec :: Int -> HlsEncryption -> ShowS
Prelude.Show, (forall x. HlsEncryption -> Rep HlsEncryption x)
-> (forall x. Rep HlsEncryption x -> HlsEncryption)
-> Generic HlsEncryption
forall x. Rep HlsEncryption x -> HlsEncryption
forall x. HlsEncryption -> Rep HlsEncryption x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HlsEncryption x -> HlsEncryption
$cfrom :: forall x. HlsEncryption -> Rep HlsEncryption x
Prelude.Generic)

-- |
-- Create a value of 'HlsEncryption' 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:
--
-- 'encryptionMethod', 'hlsEncryption_encryptionMethod' - The encryption method to use.
--
-- 'keyRotationIntervalSeconds', 'hlsEncryption_keyRotationIntervalSeconds' - Interval (in seconds) between each encryption key rotation.
--
-- 'constantInitializationVector', 'hlsEncryption_constantInitializationVector' - A constant initialization vector for encryption (optional). When not
-- specified the initialization vector will be periodically rotated.
--
-- 'repeatExtXKey', 'hlsEncryption_repeatExtXKey' - When enabled, the EXT-X-KEY tag will be repeated in output manifests.
--
-- 'spekeKeyProvider', 'hlsEncryption_spekeKeyProvider' - Undocumented member.
newHlsEncryption ::
  -- | 'spekeKeyProvider'
  SpekeKeyProvider ->
  HlsEncryption
newHlsEncryption :: SpekeKeyProvider -> HlsEncryption
newHlsEncryption SpekeKeyProvider
pSpekeKeyProvider_ =
  HlsEncryption' :: Maybe EncryptionMethod
-> Maybe Int
-> Maybe Text
-> Maybe Bool
-> SpekeKeyProvider
-> HlsEncryption
HlsEncryption'
    { $sel:encryptionMethod:HlsEncryption' :: Maybe EncryptionMethod
encryptionMethod = Maybe EncryptionMethod
forall a. Maybe a
Prelude.Nothing,
      $sel:keyRotationIntervalSeconds:HlsEncryption' :: Maybe Int
keyRotationIntervalSeconds = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:constantInitializationVector:HlsEncryption' :: Maybe Text
constantInitializationVector = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:repeatExtXKey:HlsEncryption' :: Maybe Bool
repeatExtXKey = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:spekeKeyProvider:HlsEncryption' :: SpekeKeyProvider
spekeKeyProvider = SpekeKeyProvider
pSpekeKeyProvider_
    }

-- | The encryption method to use.
hlsEncryption_encryptionMethod :: Lens.Lens' HlsEncryption (Prelude.Maybe EncryptionMethod)
hlsEncryption_encryptionMethod :: (Maybe EncryptionMethod -> f (Maybe EncryptionMethod))
-> HlsEncryption -> f HlsEncryption
hlsEncryption_encryptionMethod = (HlsEncryption -> Maybe EncryptionMethod)
-> (HlsEncryption -> Maybe EncryptionMethod -> HlsEncryption)
-> Lens
     HlsEncryption
     HlsEncryption
     (Maybe EncryptionMethod)
     (Maybe EncryptionMethod)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HlsEncryption' {Maybe EncryptionMethod
encryptionMethod :: Maybe EncryptionMethod
$sel:encryptionMethod:HlsEncryption' :: HlsEncryption -> Maybe EncryptionMethod
encryptionMethod} -> Maybe EncryptionMethod
encryptionMethod) (\s :: HlsEncryption
s@HlsEncryption' {} Maybe EncryptionMethod
a -> HlsEncryption
s {$sel:encryptionMethod:HlsEncryption' :: Maybe EncryptionMethod
encryptionMethod = Maybe EncryptionMethod
a} :: HlsEncryption)

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

-- | A constant initialization vector for encryption (optional). When not
-- specified the initialization vector will be periodically rotated.
hlsEncryption_constantInitializationVector :: Lens.Lens' HlsEncryption (Prelude.Maybe Prelude.Text)
hlsEncryption_constantInitializationVector :: (Maybe Text -> f (Maybe Text)) -> HlsEncryption -> f HlsEncryption
hlsEncryption_constantInitializationVector = (HlsEncryption -> Maybe Text)
-> (HlsEncryption -> Maybe Text -> HlsEncryption)
-> Lens HlsEncryption HlsEncryption (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HlsEncryption' {Maybe Text
constantInitializationVector :: Maybe Text
$sel:constantInitializationVector:HlsEncryption' :: HlsEncryption -> Maybe Text
constantInitializationVector} -> Maybe Text
constantInitializationVector) (\s :: HlsEncryption
s@HlsEncryption' {} Maybe Text
a -> HlsEncryption
s {$sel:constantInitializationVector:HlsEncryption' :: Maybe Text
constantInitializationVector = Maybe Text
a} :: HlsEncryption)

-- | When enabled, the EXT-X-KEY tag will be repeated in output manifests.
hlsEncryption_repeatExtXKey :: Lens.Lens' HlsEncryption (Prelude.Maybe Prelude.Bool)
hlsEncryption_repeatExtXKey :: (Maybe Bool -> f (Maybe Bool)) -> HlsEncryption -> f HlsEncryption
hlsEncryption_repeatExtXKey = (HlsEncryption -> Maybe Bool)
-> (HlsEncryption -> Maybe Bool -> HlsEncryption)
-> Lens HlsEncryption HlsEncryption (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HlsEncryption' {Maybe Bool
repeatExtXKey :: Maybe Bool
$sel:repeatExtXKey:HlsEncryption' :: HlsEncryption -> Maybe Bool
repeatExtXKey} -> Maybe Bool
repeatExtXKey) (\s :: HlsEncryption
s@HlsEncryption' {} Maybe Bool
a -> HlsEncryption
s {$sel:repeatExtXKey:HlsEncryption' :: Maybe Bool
repeatExtXKey = Maybe Bool
a} :: HlsEncryption)

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

instance Core.FromJSON HlsEncryption where
  parseJSON :: Value -> Parser HlsEncryption
parseJSON =
    String
-> (Object -> Parser HlsEncryption)
-> Value
-> Parser HlsEncryption
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"HlsEncryption"
      ( \Object
x ->
          Maybe EncryptionMethod
-> Maybe Int
-> Maybe Text
-> Maybe Bool
-> SpekeKeyProvider
-> HlsEncryption
HlsEncryption'
            (Maybe EncryptionMethod
 -> Maybe Int
 -> Maybe Text
 -> Maybe Bool
 -> SpekeKeyProvider
 -> HlsEncryption)
-> Parser (Maybe EncryptionMethod)
-> Parser
     (Maybe Int
      -> Maybe Text -> Maybe Bool -> SpekeKeyProvider -> HlsEncryption)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe EncryptionMethod)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"encryptionMethod")
            Parser
  (Maybe Int
   -> Maybe Text -> Maybe Bool -> SpekeKeyProvider -> HlsEncryption)
-> Parser (Maybe Int)
-> Parser
     (Maybe Text -> Maybe Bool -> SpekeKeyProvider -> HlsEncryption)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"keyRotationIntervalSeconds")
            Parser
  (Maybe Text -> Maybe Bool -> SpekeKeyProvider -> HlsEncryption)
-> Parser (Maybe Text)
-> Parser (Maybe Bool -> SpekeKeyProvider -> HlsEncryption)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"constantInitializationVector")
            Parser (Maybe Bool -> SpekeKeyProvider -> HlsEncryption)
-> Parser (Maybe Bool)
-> Parser (SpekeKeyProvider -> HlsEncryption)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"repeatExtXKey")
            Parser (SpekeKeyProvider -> HlsEncryption)
-> Parser SpekeKeyProvider -> Parser HlsEncryption
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser SpekeKeyProvider
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"spekeKeyProvider")
      )

instance Prelude.Hashable HlsEncryption

instance Prelude.NFData HlsEncryption

instance Core.ToJSON HlsEncryption where
  toJSON :: HlsEncryption -> Value
toJSON HlsEncryption' {Maybe Bool
Maybe Int
Maybe Text
Maybe EncryptionMethod
SpekeKeyProvider
spekeKeyProvider :: SpekeKeyProvider
repeatExtXKey :: Maybe Bool
constantInitializationVector :: Maybe Text
keyRotationIntervalSeconds :: Maybe Int
encryptionMethod :: Maybe EncryptionMethod
$sel:spekeKeyProvider:HlsEncryption' :: HlsEncryption -> SpekeKeyProvider
$sel:repeatExtXKey:HlsEncryption' :: HlsEncryption -> Maybe Bool
$sel:constantInitializationVector:HlsEncryption' :: HlsEncryption -> Maybe Text
$sel:keyRotationIntervalSeconds:HlsEncryption' :: HlsEncryption -> Maybe Int
$sel:encryptionMethod:HlsEncryption' :: HlsEncryption -> Maybe EncryptionMethod
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"encryptionMethod" Text -> EncryptionMethod -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (EncryptionMethod -> Pair) -> Maybe EncryptionMethod -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe EncryptionMethod
encryptionMethod,
            (Text
"keyRotationIntervalSeconds" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
keyRotationIntervalSeconds,
            (Text
"constantInitializationVector" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
constantInitializationVector,
            (Text
"repeatExtXKey" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
repeatExtXKey,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"spekeKeyProvider" Text -> SpekeKeyProvider -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= SpekeKeyProvider
spekeKeyProvider)
          ]
      )