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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes a key pair.
--
-- /See:/ 'newKeyPair' smart constructor.
data KeyPair = KeyPair'
  { -- | The private key.
    KeyPair -> Maybe (Sensitive Text)
privateKey :: Prelude.Maybe (Core.Sensitive Prelude.Text),
    -- | The public key.
    KeyPair -> Maybe Text
publicKey :: Prelude.Maybe Prelude.Text
  }
  deriving (KeyPair -> KeyPair -> Bool
(KeyPair -> KeyPair -> Bool)
-> (KeyPair -> KeyPair -> Bool) -> Eq KeyPair
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: KeyPair -> KeyPair -> Bool
$c/= :: KeyPair -> KeyPair -> Bool
== :: KeyPair -> KeyPair -> Bool
$c== :: KeyPair -> KeyPair -> Bool
Prelude.Eq, Int -> KeyPair -> ShowS
[KeyPair] -> ShowS
KeyPair -> String
(Int -> KeyPair -> ShowS)
-> (KeyPair -> String) -> ([KeyPair] -> ShowS) -> Show KeyPair
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [KeyPair] -> ShowS
$cshowList :: [KeyPair] -> ShowS
show :: KeyPair -> String
$cshow :: KeyPair -> String
showsPrec :: Int -> KeyPair -> ShowS
$cshowsPrec :: Int -> KeyPair -> ShowS
Prelude.Show, (forall x. KeyPair -> Rep KeyPair x)
-> (forall x. Rep KeyPair x -> KeyPair) -> Generic KeyPair
forall x. Rep KeyPair x -> KeyPair
forall x. KeyPair -> Rep KeyPair x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep KeyPair x -> KeyPair
$cfrom :: forall x. KeyPair -> Rep KeyPair x
Prelude.Generic)

-- |
-- Create a value of 'KeyPair' 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:
--
-- 'privateKey', 'keyPair_privateKey' - The private key.
--
-- 'publicKey', 'keyPair_publicKey' - The public key.
newKeyPair ::
  KeyPair
newKeyPair :: KeyPair
newKeyPair =
  KeyPair' :: Maybe (Sensitive Text) -> Maybe Text -> KeyPair
KeyPair'
    { $sel:privateKey:KeyPair' :: Maybe (Sensitive Text)
privateKey = Maybe (Sensitive Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:publicKey:KeyPair' :: Maybe Text
publicKey = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The private key.
keyPair_privateKey :: Lens.Lens' KeyPair (Prelude.Maybe Prelude.Text)
keyPair_privateKey :: (Maybe Text -> f (Maybe Text)) -> KeyPair -> f KeyPair
keyPair_privateKey = (KeyPair -> Maybe (Sensitive Text))
-> (KeyPair -> Maybe (Sensitive Text) -> KeyPair)
-> Lens
     KeyPair KeyPair (Maybe (Sensitive Text)) (Maybe (Sensitive Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KeyPair' {Maybe (Sensitive Text)
privateKey :: Maybe (Sensitive Text)
$sel:privateKey:KeyPair' :: KeyPair -> Maybe (Sensitive Text)
privateKey} -> Maybe (Sensitive Text)
privateKey) (\s :: KeyPair
s@KeyPair' {} Maybe (Sensitive Text)
a -> KeyPair
s {$sel:privateKey:KeyPair' :: Maybe (Sensitive Text)
privateKey = Maybe (Sensitive Text)
a} :: KeyPair) ((Maybe (Sensitive Text) -> f (Maybe (Sensitive Text)))
 -> KeyPair -> f KeyPair)
-> ((Maybe Text -> f (Maybe Text))
    -> Maybe (Sensitive Text) -> f (Maybe (Sensitive Text)))
-> (Maybe Text -> f (Maybe Text))
-> KeyPair
-> f KeyPair
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso (Sensitive Text) (Sensitive Text) Text Text
-> Iso
     (Maybe (Sensitive Text))
     (Maybe (Sensitive Text))
     (Maybe Text)
     (Maybe Text)
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 AnIso (Sensitive Text) (Sensitive Text) Text Text
forall a. Iso' (Sensitive a) a
Core._Sensitive

-- | The public key.
keyPair_publicKey :: Lens.Lens' KeyPair (Prelude.Maybe Prelude.Text)
keyPair_publicKey :: (Maybe Text -> f (Maybe Text)) -> KeyPair -> f KeyPair
keyPair_publicKey = (KeyPair -> Maybe Text)
-> (KeyPair -> Maybe Text -> KeyPair)
-> Lens KeyPair KeyPair (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KeyPair' {Maybe Text
publicKey :: Maybe Text
$sel:publicKey:KeyPair' :: KeyPair -> Maybe Text
publicKey} -> Maybe Text
publicKey) (\s :: KeyPair
s@KeyPair' {} Maybe Text
a -> KeyPair
s {$sel:publicKey:KeyPair' :: Maybe Text
publicKey = Maybe Text
a} :: KeyPair)

instance Core.FromJSON KeyPair where
  parseJSON :: Value -> Parser KeyPair
parseJSON =
    String -> (Object -> Parser KeyPair) -> Value -> Parser KeyPair
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"KeyPair"
      ( \Object
x ->
          Maybe (Sensitive Text) -> Maybe Text -> KeyPair
KeyPair'
            (Maybe (Sensitive Text) -> Maybe Text -> KeyPair)
-> Parser (Maybe (Sensitive Text))
-> Parser (Maybe Text -> KeyPair)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Sensitive Text))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"PrivateKey")
            Parser (Maybe Text -> KeyPair)
-> Parser (Maybe Text) -> Parser KeyPair
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
"PublicKey")
      )

instance Prelude.Hashable KeyPair

instance Prelude.NFData KeyPair