{-# 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.IoT.Types.CustomCodeSigning
-- 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.IoT.Types.CustomCodeSigning where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IoT.Types.CodeSigningCertificateChain
import Amazonka.IoT.Types.CodeSigningSignature
import qualified Amazonka.Prelude as Prelude

-- | Describes a custom method used to code sign a file.
--
-- /See:/ 'newCustomCodeSigning' smart constructor.
data CustomCodeSigning = CustomCodeSigning'
  { -- | The certificate chain.
    CustomCodeSigning -> Maybe CodeSigningCertificateChain
certificateChain :: Prelude.Maybe CodeSigningCertificateChain,
    -- | The hash algorithm used to code sign the file. You can use a string as
    -- the algorithm name if the target over-the-air (OTA) update devices are
    -- able to verify the signature that was generated using the same signature
    -- algorithm. For example, FreeRTOS uses @SHA256@ or @SHA1@, so you can
    -- pass either of them based on which was used for generating the
    -- signature.
    CustomCodeSigning -> Maybe Text
hashAlgorithm :: Prelude.Maybe Prelude.Text,
    -- | The signature for the file.
    CustomCodeSigning -> Maybe CodeSigningSignature
signature :: Prelude.Maybe CodeSigningSignature,
    -- | The signature algorithm used to code sign the file. You can use a string
    -- as the algorithm name if the target over-the-air (OTA) update devices
    -- are able to verify the signature that was generated using the same
    -- signature algorithm. For example, FreeRTOS uses @ECDSA@ or @RSA@, so you
    -- can pass either of them based on which was used for generating the
    -- signature.
    CustomCodeSigning -> Maybe Text
signatureAlgorithm :: Prelude.Maybe Prelude.Text
  }
  deriving (CustomCodeSigning -> CustomCodeSigning -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CustomCodeSigning -> CustomCodeSigning -> Bool
$c/= :: CustomCodeSigning -> CustomCodeSigning -> Bool
== :: CustomCodeSigning -> CustomCodeSigning -> Bool
$c== :: CustomCodeSigning -> CustomCodeSigning -> Bool
Prelude.Eq, ReadPrec [CustomCodeSigning]
ReadPrec CustomCodeSigning
Int -> ReadS CustomCodeSigning
ReadS [CustomCodeSigning]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CustomCodeSigning]
$creadListPrec :: ReadPrec [CustomCodeSigning]
readPrec :: ReadPrec CustomCodeSigning
$creadPrec :: ReadPrec CustomCodeSigning
readList :: ReadS [CustomCodeSigning]
$creadList :: ReadS [CustomCodeSigning]
readsPrec :: Int -> ReadS CustomCodeSigning
$creadsPrec :: Int -> ReadS CustomCodeSigning
Prelude.Read, Int -> CustomCodeSigning -> ShowS
[CustomCodeSigning] -> ShowS
CustomCodeSigning -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CustomCodeSigning] -> ShowS
$cshowList :: [CustomCodeSigning] -> ShowS
show :: CustomCodeSigning -> String
$cshow :: CustomCodeSigning -> String
showsPrec :: Int -> CustomCodeSigning -> ShowS
$cshowsPrec :: Int -> CustomCodeSigning -> ShowS
Prelude.Show, forall x. Rep CustomCodeSigning x -> CustomCodeSigning
forall x. CustomCodeSigning -> Rep CustomCodeSigning x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CustomCodeSigning x -> CustomCodeSigning
$cfrom :: forall x. CustomCodeSigning -> Rep CustomCodeSigning x
Prelude.Generic)

-- |
-- Create a value of 'CustomCodeSigning' 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:
--
-- 'certificateChain', 'customCodeSigning_certificateChain' - The certificate chain.
--
-- 'hashAlgorithm', 'customCodeSigning_hashAlgorithm' - The hash algorithm used to code sign the file. You can use a string as
-- the algorithm name if the target over-the-air (OTA) update devices are
-- able to verify the signature that was generated using the same signature
-- algorithm. For example, FreeRTOS uses @SHA256@ or @SHA1@, so you can
-- pass either of them based on which was used for generating the
-- signature.
--
-- 'signature', 'customCodeSigning_signature' - The signature for the file.
--
-- 'signatureAlgorithm', 'customCodeSigning_signatureAlgorithm' - The signature algorithm used to code sign the file. You can use a string
-- as the algorithm name if the target over-the-air (OTA) update devices
-- are able to verify the signature that was generated using the same
-- signature algorithm. For example, FreeRTOS uses @ECDSA@ or @RSA@, so you
-- can pass either of them based on which was used for generating the
-- signature.
newCustomCodeSigning ::
  CustomCodeSigning
newCustomCodeSigning :: CustomCodeSigning
newCustomCodeSigning =
  CustomCodeSigning'
    { $sel:certificateChain:CustomCodeSigning' :: Maybe CodeSigningCertificateChain
certificateChain =
        forall a. Maybe a
Prelude.Nothing,
      $sel:hashAlgorithm:CustomCodeSigning' :: Maybe Text
hashAlgorithm = forall a. Maybe a
Prelude.Nothing,
      $sel:signature:CustomCodeSigning' :: Maybe CodeSigningSignature
signature = forall a. Maybe a
Prelude.Nothing,
      $sel:signatureAlgorithm:CustomCodeSigning' :: Maybe Text
signatureAlgorithm = forall a. Maybe a
Prelude.Nothing
    }

-- | The certificate chain.
customCodeSigning_certificateChain :: Lens.Lens' CustomCodeSigning (Prelude.Maybe CodeSigningCertificateChain)
customCodeSigning_certificateChain :: Lens' CustomCodeSigning (Maybe CodeSigningCertificateChain)
customCodeSigning_certificateChain = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomCodeSigning' {Maybe CodeSigningCertificateChain
certificateChain :: Maybe CodeSigningCertificateChain
$sel:certificateChain:CustomCodeSigning' :: CustomCodeSigning -> Maybe CodeSigningCertificateChain
certificateChain} -> Maybe CodeSigningCertificateChain
certificateChain) (\s :: CustomCodeSigning
s@CustomCodeSigning' {} Maybe CodeSigningCertificateChain
a -> CustomCodeSigning
s {$sel:certificateChain:CustomCodeSigning' :: Maybe CodeSigningCertificateChain
certificateChain = Maybe CodeSigningCertificateChain
a} :: CustomCodeSigning)

-- | The hash algorithm used to code sign the file. You can use a string as
-- the algorithm name if the target over-the-air (OTA) update devices are
-- able to verify the signature that was generated using the same signature
-- algorithm. For example, FreeRTOS uses @SHA256@ or @SHA1@, so you can
-- pass either of them based on which was used for generating the
-- signature.
customCodeSigning_hashAlgorithm :: Lens.Lens' CustomCodeSigning (Prelude.Maybe Prelude.Text)
customCodeSigning_hashAlgorithm :: Lens' CustomCodeSigning (Maybe Text)
customCodeSigning_hashAlgorithm = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomCodeSigning' {Maybe Text
hashAlgorithm :: Maybe Text
$sel:hashAlgorithm:CustomCodeSigning' :: CustomCodeSigning -> Maybe Text
hashAlgorithm} -> Maybe Text
hashAlgorithm) (\s :: CustomCodeSigning
s@CustomCodeSigning' {} Maybe Text
a -> CustomCodeSigning
s {$sel:hashAlgorithm:CustomCodeSigning' :: Maybe Text
hashAlgorithm = Maybe Text
a} :: CustomCodeSigning)

-- | The signature for the file.
customCodeSigning_signature :: Lens.Lens' CustomCodeSigning (Prelude.Maybe CodeSigningSignature)
customCodeSigning_signature :: Lens' CustomCodeSigning (Maybe CodeSigningSignature)
customCodeSigning_signature = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomCodeSigning' {Maybe CodeSigningSignature
signature :: Maybe CodeSigningSignature
$sel:signature:CustomCodeSigning' :: CustomCodeSigning -> Maybe CodeSigningSignature
signature} -> Maybe CodeSigningSignature
signature) (\s :: CustomCodeSigning
s@CustomCodeSigning' {} Maybe CodeSigningSignature
a -> CustomCodeSigning
s {$sel:signature:CustomCodeSigning' :: Maybe CodeSigningSignature
signature = Maybe CodeSigningSignature
a} :: CustomCodeSigning)

-- | The signature algorithm used to code sign the file. You can use a string
-- as the algorithm name if the target over-the-air (OTA) update devices
-- are able to verify the signature that was generated using the same
-- signature algorithm. For example, FreeRTOS uses @ECDSA@ or @RSA@, so you
-- can pass either of them based on which was used for generating the
-- signature.
customCodeSigning_signatureAlgorithm :: Lens.Lens' CustomCodeSigning (Prelude.Maybe Prelude.Text)
customCodeSigning_signatureAlgorithm :: Lens' CustomCodeSigning (Maybe Text)
customCodeSigning_signatureAlgorithm = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomCodeSigning' {Maybe Text
signatureAlgorithm :: Maybe Text
$sel:signatureAlgorithm:CustomCodeSigning' :: CustomCodeSigning -> Maybe Text
signatureAlgorithm} -> Maybe Text
signatureAlgorithm) (\s :: CustomCodeSigning
s@CustomCodeSigning' {} Maybe Text
a -> CustomCodeSigning
s {$sel:signatureAlgorithm:CustomCodeSigning' :: Maybe Text
signatureAlgorithm = Maybe Text
a} :: CustomCodeSigning)

instance Data.FromJSON CustomCodeSigning where
  parseJSON :: Value -> Parser CustomCodeSigning
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"CustomCodeSigning"
      ( \Object
x ->
          Maybe CodeSigningCertificateChain
-> Maybe Text
-> Maybe CodeSigningSignature
-> Maybe Text
-> CustomCodeSigning
CustomCodeSigning'
            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
"certificateChain")
            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
"hashAlgorithm")
            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
"signature")
            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
"signatureAlgorithm")
      )

instance Prelude.Hashable CustomCodeSigning where
  hashWithSalt :: Int -> CustomCodeSigning -> Int
hashWithSalt Int
_salt CustomCodeSigning' {Maybe Text
Maybe CodeSigningCertificateChain
Maybe CodeSigningSignature
signatureAlgorithm :: Maybe Text
signature :: Maybe CodeSigningSignature
hashAlgorithm :: Maybe Text
certificateChain :: Maybe CodeSigningCertificateChain
$sel:signatureAlgorithm:CustomCodeSigning' :: CustomCodeSigning -> Maybe Text
$sel:signature:CustomCodeSigning' :: CustomCodeSigning -> Maybe CodeSigningSignature
$sel:hashAlgorithm:CustomCodeSigning' :: CustomCodeSigning -> Maybe Text
$sel:certificateChain:CustomCodeSigning' :: CustomCodeSigning -> Maybe CodeSigningCertificateChain
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe CodeSigningCertificateChain
certificateChain
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
hashAlgorithm
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe CodeSigningSignature
signature
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
signatureAlgorithm

instance Prelude.NFData CustomCodeSigning where
  rnf :: CustomCodeSigning -> ()
rnf CustomCodeSigning' {Maybe Text
Maybe CodeSigningCertificateChain
Maybe CodeSigningSignature
signatureAlgorithm :: Maybe Text
signature :: Maybe CodeSigningSignature
hashAlgorithm :: Maybe Text
certificateChain :: Maybe CodeSigningCertificateChain
$sel:signatureAlgorithm:CustomCodeSigning' :: CustomCodeSigning -> Maybe Text
$sel:signature:CustomCodeSigning' :: CustomCodeSigning -> Maybe CodeSigningSignature
$sel:hashAlgorithm:CustomCodeSigning' :: CustomCodeSigning -> Maybe Text
$sel:certificateChain:CustomCodeSigning' :: CustomCodeSigning -> Maybe CodeSigningCertificateChain
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe CodeSigningCertificateChain
certificateChain
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
hashAlgorithm
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe CodeSigningSignature
signature
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
signatureAlgorithm

instance Data.ToJSON CustomCodeSigning where
  toJSON :: CustomCodeSigning -> Value
toJSON CustomCodeSigning' {Maybe Text
Maybe CodeSigningCertificateChain
Maybe CodeSigningSignature
signatureAlgorithm :: Maybe Text
signature :: Maybe CodeSigningSignature
hashAlgorithm :: Maybe Text
certificateChain :: Maybe CodeSigningCertificateChain
$sel:signatureAlgorithm:CustomCodeSigning' :: CustomCodeSigning -> Maybe Text
$sel:signature:CustomCodeSigning' :: CustomCodeSigning -> Maybe CodeSigningSignature
$sel:hashAlgorithm:CustomCodeSigning' :: CustomCodeSigning -> Maybe Text
$sel:certificateChain:CustomCodeSigning' :: CustomCodeSigning -> Maybe CodeSigningCertificateChain
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"certificateChain" 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 CodeSigningCertificateChain
certificateChain,
            (Key
"hashAlgorithm" 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
hashAlgorithm,
            (Key
"signature" 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 CodeSigningSignature
signature,
            (Key
"signatureAlgorithm" 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
signatureAlgorithm
          ]
      )