-- | The @pgcrypto@ extension provides several cryptographic functions to
-- Postgres. This module provides a @beam-postgres@ extension to access this
-- functionality. For an example of usage, see the documentation for
-- 'PgExtensionEntity'.
module Database.Beam.Postgres.PgCrypto
  ( PgCrypto(..) ) where

import Database.Beam
import Database.Beam.Backend.SQL

import Database.Beam.Postgres.Extensions
import Database.Beam.Postgres.Extensions.Internal

import Data.Int
import Data.Text (Text)
import Data.ByteString (ByteString)
import Data.Vector (Vector)
import Data.UUID.Types (UUID)

-- | Data type representing definitions contained in the @pgcrypto@ extension
--
-- Each field maps closely to the underlying @pgcrypto@ function, which are
-- described in further detail in the
-- <https://www.postgresql.org/docs/current/static/pgcrypto.html pgcrypto manual>.
data PgCrypto
  = PgCrypto
  { PgCrypto
-> forall ctxt s. LiftPg ctxt s (Text -> Text -> ByteString)
pgCryptoDigestText ::
      forall ctxt s. LiftPg ctxt s (Text -> Text -> ByteString)
  , PgCrypto
-> forall ctxt s. LiftPg ctxt s (ByteString -> Text -> ByteString)
pgCryptoDigestBytes ::
      forall ctxt s. LiftPg ctxt s (ByteString -> Text -> ByteString)
  , PgCrypto
-> forall ctxt s.
   LiftPg ctxt s (Text -> Text -> Text -> ByteString)
pgCryptoHmacText ::
      forall ctxt s. LiftPg ctxt s (Text -> Text -> Text -> ByteString)
  , PgCrypto
-> forall ctxt s.
   LiftPg ctxt s (ByteString -> Text -> Text -> ByteString)
pgCryptoHmacBytes ::
      forall ctxt s. LiftPg ctxt s (ByteString -> Text -> Text -> ByteString)
  , PgCrypto -> forall ctxt s. LiftPg ctxt s (Text -> Text -> Text)
pgCryptoCrypt ::
      forall ctxt s. LiftPg ctxt s (Text -> Text -> Text)
  , PgCrypto
-> forall ctxt s. LiftPg ctxt s (Text -> Maybe Int32 -> Text)
pgCryptoGenSalt ::
      forall ctxt s. LiftPg ctxt s (Text -> Maybe Int32 -> Text)

  -- Pgp functions
  , PgCrypto
-> forall ctxt s.
   LiftPg ctxt s (Text -> Text -> Maybe Text -> ByteString)
pgCryptoPgpSymEncrypt ::
      forall ctxt s. LiftPg ctxt s (Text -> Text -> Maybe Text -> ByteString)
  , PgCrypto
-> forall ctxt s.
   LiftPg ctxt s (ByteString -> Text -> Maybe Text -> ByteString)
pgCryptoPgpSymEncryptBytea ::
      forall ctxt s. LiftPg ctxt s (ByteString -> Text -> Maybe Text -> ByteString)

  , PgCrypto
-> forall ctxt s.
   LiftPg ctxt s (ByteString -> Text -> Maybe Text -> Text)
pgCryptoPgpSymDecrypt ::
      forall ctxt s. LiftPg ctxt s (ByteString -> Text -> Maybe Text -> Text)
  , PgCrypto
-> forall ctxt s.
   LiftPg ctxt s (ByteString -> Text -> Maybe Text -> ByteString)
pgCryptoPgpSymDecryptBytea ::
      forall ctxt s. LiftPg ctxt s (ByteString -> Text -> Maybe Text -> ByteString)

  , PgCrypto
-> forall ctxt s.
   LiftPg ctxt s (Text -> ByteString -> Maybe Text -> ByteString)
pgCryptoPgpPubEncrypt ::
      forall ctxt s. LiftPg ctxt s (Text -> ByteString -> Maybe Text -> ByteString)
  , PgCrypto
-> forall ctxt s.
   LiftPg
     ctxt s (ByteString -> ByteString -> Maybe Text -> ByteString)
pgCryptoPgpPubEncryptBytea ::
      forall ctxt s. LiftPg ctxt s (ByteString -> ByteString -> Maybe Text -> ByteString)

  , PgCrypto
-> forall ctxt s.
   LiftPg
     ctxt
     s
     (ByteString -> ByteString -> Maybe Text -> Maybe Text -> Text)
pgCryptoPgpPubDecrypt ::
      forall ctxt s. LiftPg ctxt s (ByteString -> ByteString -> Maybe Text -> Maybe Text -> Text)
  , PgCrypto
-> forall ctxt s.
   LiftPg
     ctxt
     s
     (ByteString
      -> ByteString -> Maybe Text -> Maybe Text -> ByteString)
pgCryptoPgpPubDecryptBytea ::
      forall ctxt s. LiftPg ctxt s (ByteString -> ByteString -> Maybe Text -> Maybe Text -> ByteString)

  , PgCrypto -> forall ctxt s. LiftPg ctxt s (ByteString -> Text)
pgCryptoPgpKeyId ::
      forall ctxt s. LiftPg ctxt s (ByteString -> Text)

  , PgCrypto
-> forall ctxt s.
   PgExpr ctxt s ByteString
   -> Maybe (PgExpr ctxt s (Vector Text), PgExpr ctxt s (Vector Text))
   -> PgExpr ctxt s Text
pgCryptoArmor ::
      forall ctxt s. PgExpr ctxt s ByteString ->
                     Maybe (PgExpr ctxt s (Vector Text), PgExpr ctxt s (Vector Text)) ->
                     PgExpr ctxt s Text
  , PgCrypto -> forall ctxt s. LiftPg ctxt s (Text -> ByteString)
pgCryptoDearmor ::
      forall ctxt s. LiftPg ctxt s (Text -> ByteString)

-- TODO setof
--  , pgCryptoPgpArmorHeaders ::
--      forall ctxt s. LiftPg ctxt s (Text -> )

  , PgCrypto
-> forall ctxt s i.
   Integral i =>
   PgExpr ctxt s i -> PgExpr ctxt s ByteString
pgCryptoGenRandomBytes ::
      forall ctxt s i. Integral i => PgExpr ctxt s i -> PgExpr ctxt s ByteString
  , PgCrypto -> forall ctxt s. PgExpr ctxt s UUID
pgCryptoGenRandomUUID ::
      forall ctxt s. PgExpr ctxt s UUID
  }

instance IsPgExtension PgCrypto where
  pgExtensionName :: Proxy PgCrypto -> Text
pgExtensionName Proxy PgCrypto
_ = Text
"pgcrypto"
  pgExtensionBuild :: PgCrypto
pgExtensionBuild = PgCrypto {
    pgCryptoDigestText :: forall ctxt s. LiftPg ctxt s (Text -> Text -> ByteString)
pgCryptoDigestText  =
        \(QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
data_) (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
type_) -> forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (forall expr. IsSql99ExpressionSyntax expr => Text -> [expr] -> expr
funcE Text
"digest" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA [Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
data_, Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
type_]),
    pgCryptoDigestBytes :: forall ctxt s. LiftPg ctxt s (ByteString -> Text -> ByteString)
pgCryptoDigestBytes =
        \(QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
data_) (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
type_) -> forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (forall expr. IsSql99ExpressionSyntax expr => Text -> [expr] -> expr
funcE Text
"digest" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA [Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
data_, Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
type_]),
    pgCryptoHmacText :: forall ctxt s. LiftPg ctxt s (Text -> Text -> Text -> ByteString)
pgCryptoHmacText =
        \(QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
data_) (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
key) (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
type_) -> forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (forall expr. IsSql99ExpressionSyntax expr => Text -> [expr] -> expr
funcE Text
"hmac" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA [Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
data_, Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
key, Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
type_]),
    pgCryptoHmacBytes :: forall ctxt s.
LiftPg ctxt s (ByteString -> Text -> Text -> ByteString)
pgCryptoHmacBytes =
        \(QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
data_) (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
key) (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
type_) -> forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (forall expr. IsSql99ExpressionSyntax expr => Text -> [expr] -> expr
funcE Text
"hmac" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA [Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
data_, Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
key, Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
type_]),

    pgCryptoCrypt :: forall ctxt s. LiftPg ctxt s (Text -> Text -> Text)
pgCryptoCrypt =
        \(QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
pw) (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
salt) ->
           forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (forall expr. IsSql99ExpressionSyntax expr => Text -> [expr] -> expr
funcE Text
"crypt" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA [Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
pw, Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
salt]),
    pgCryptoGenSalt :: forall ctxt s. LiftPg ctxt s (Text -> Maybe Int32 -> Text)
pgCryptoGenSalt =
        \(QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
text) Maybe (QGenExpr ctxt Postgres s Int32)
iterCount ->
           forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (forall expr. IsSql99ExpressionSyntax expr => Text -> [expr] -> expr
funcE Text
"gen_salt" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA ([Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
text] forall a. [a] -> [a] -> [a]
++ forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\(QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
iterCount') -> [Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
iterCount']) Maybe (QGenExpr ctxt Postgres s Int32)
iterCount)),

    pgCryptoPgpSymEncrypt :: forall ctxt s.
LiftPg ctxt s (Text -> Text -> Maybe Text -> ByteString)
pgCryptoPgpSymEncrypt =
        \(QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
data_) (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
pw) Maybe (QGenExpr ctxt Postgres s Text)
options ->
           forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (forall expr. IsSql99ExpressionSyntax expr => Text -> [expr] -> expr
funcE Text
"pgp_sym_encrypt" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA ([Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
data_, Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
pw] forall a. [a] -> [a] -> [a]
++ forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\(QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
options') -> [Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
options']) Maybe (QGenExpr ctxt Postgres s Text)
options)),
    pgCryptoPgpSymEncryptBytea :: forall ctxt s.
LiftPg ctxt s (ByteString -> Text -> Maybe Text -> ByteString)
pgCryptoPgpSymEncryptBytea =
        \(QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
data_) (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
pw) Maybe (QGenExpr ctxt Postgres s Text)
options ->
           forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (forall expr. IsSql99ExpressionSyntax expr => Text -> [expr] -> expr
funcE Text
"pgp_sym_encrypt_bytea" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA ([Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
data_, Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
pw] forall a. [a] -> [a] -> [a]
++ forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\(QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
options') -> [Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
options']) Maybe (QGenExpr ctxt Postgres s Text)
options)),

    pgCryptoPgpSymDecrypt :: forall ctxt s.
LiftPg ctxt s (ByteString -> Text -> Maybe Text -> Text)
pgCryptoPgpSymDecrypt =
        \(QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
data_) (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
pw) Maybe (QGenExpr ctxt Postgres s Text)
options ->
             forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr
             (forall expr. IsSql99ExpressionSyntax expr => Text -> [expr] -> expr
funcE Text
"pgp_sym_decrypt" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA ([Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
data_, Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
pw] forall a. [a] -> [a] -> [a]
++ forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\(QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
options') -> [Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
options']) Maybe (QGenExpr ctxt Postgres s Text)
options)),
    pgCryptoPgpSymDecryptBytea :: forall ctxt s.
LiftPg ctxt s (ByteString -> Text -> Maybe Text -> ByteString)
pgCryptoPgpSymDecryptBytea =
        \(QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
data_) (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
pw) Maybe (QGenExpr ctxt Postgres s Text)
options ->
             forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr
             (forall expr. IsSql99ExpressionSyntax expr => Text -> [expr] -> expr
funcE Text
"pgp_sym_decrypt_bytea" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA ([Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
data_, Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
pw] forall a. [a] -> [a] -> [a]
++ forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\(QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
options') -> [Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
options']) Maybe (QGenExpr ctxt Postgres s Text)
options)),

    pgCryptoPgpPubEncrypt :: forall ctxt s.
LiftPg ctxt s (Text -> ByteString -> Maybe Text -> ByteString)
pgCryptoPgpPubEncrypt =
        \(QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
data_) (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
key) Maybe (QGenExpr ctxt Postgres s Text)
options ->
             forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr
             (forall expr. IsSql99ExpressionSyntax expr => Text -> [expr] -> expr
funcE Text
"pgp_pub_encrypt" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA ([Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
data_, Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
key] forall a. [a] -> [a] -> [a]
++ forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\(QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
options') -> [Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
options']) Maybe (QGenExpr ctxt Postgres s Text)
options)),
    pgCryptoPgpPubEncryptBytea :: forall ctxt s.
LiftPg
  ctxt s (ByteString -> ByteString -> Maybe Text -> ByteString)
pgCryptoPgpPubEncryptBytea =
        \(QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
data_) (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
key) Maybe (QGenExpr ctxt Postgres s Text)
options ->
             forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr
             (forall expr. IsSql99ExpressionSyntax expr => Text -> [expr] -> expr
funcE Text
"pgp_pub_encrypt_bytea" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA ([Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
data_, Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
key] forall a. [a] -> [a] -> [a]
++ forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\(QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
options') -> [Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
options']) Maybe (QGenExpr ctxt Postgres s Text)
options)),

    pgCryptoPgpPubDecrypt :: forall ctxt s.
LiftPg
  ctxt
  s
  (ByteString -> ByteString -> Maybe Text -> Maybe Text -> Text)
pgCryptoPgpPubDecrypt =
        \(QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
msg) (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
key) Maybe (QGenExpr ctxt Postgres s Text)
pw Maybe (QGenExpr ctxt Postgres s Text)
options ->
              forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr
              (forall expr. IsSql99ExpressionSyntax expr => Text -> [expr] -> expr
funcE Text
"pgp_pub_decrypt" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
                   forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA
                   ( [Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
msg, Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
key] forall a. [a] -> [a] -> [a]
++
                     case (Maybe (QGenExpr ctxt Postgres s Text)
pw, Maybe (QGenExpr ctxt Postgres s Text)
options) of
                       (Maybe (QGenExpr ctxt Postgres s Text)
Nothing, Maybe (QGenExpr ctxt Postgres s Text)
Nothing) -> []
                       (Just (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
pw'), Maybe (QGenExpr ctxt Postgres s Text)
Nothing) -> [Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
pw']
                       (Maybe (QGenExpr ctxt Postgres s Text)
Nothing, Just (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
options')) -> [ \Text
_ -> forall expr.
IsSql92ExpressionSyntax expr =>
Sql92ExpressionValueSyntax expr -> expr
valueE (forall expr ty. HasSqlValueSyntax expr ty => ty -> expr
sqlValueSyntax (String
"" :: String))
                                                           , Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
options' ]
                       (Just (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
pw'), Just (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
options')) -> [Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
pw', Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
options'] )),
    pgCryptoPgpPubDecryptBytea :: forall ctxt s.
LiftPg
  ctxt
  s
  (ByteString
   -> ByteString -> Maybe Text -> Maybe Text -> ByteString)
pgCryptoPgpPubDecryptBytea =
        \(QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
msg) (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
key) Maybe (QGenExpr ctxt Postgres s Text)
pw Maybe (QGenExpr ctxt Postgres s Text)
options ->
              forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr forall a b. (a -> b) -> a -> b
$
              (forall expr. IsSql99ExpressionSyntax expr => Text -> [expr] -> expr
funcE Text
"pgp_pub_decrypt_bytea" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
                   forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA
                   ( [Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
msg, Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
key] forall a. [a] -> [a] -> [a]
++
                     case (Maybe (QGenExpr ctxt Postgres s Text)
pw, Maybe (QGenExpr ctxt Postgres s Text)
options) of
                       (Maybe (QGenExpr ctxt Postgres s Text)
Nothing, Maybe (QGenExpr ctxt Postgres s Text)
Nothing) -> []
                       (Just (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
pw'), Maybe (QGenExpr ctxt Postgres s Text)
Nothing) -> [Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
pw']
                       (Maybe (QGenExpr ctxt Postgres s Text)
Nothing, Just (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
options')) -> [ \Text
_ -> forall expr.
IsSql92ExpressionSyntax expr =>
Sql92ExpressionValueSyntax expr -> expr
valueE (forall expr ty. HasSqlValueSyntax expr ty => ty -> expr
sqlValueSyntax (String
"" :: String))
                                                           , Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
options' ]
                       (Just (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
pw'), Just (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
options')) -> [Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
pw', Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
options'] )),

    pgCryptoPgpKeyId :: forall ctxt s. LiftPg ctxt s (ByteString -> Text)
pgCryptoPgpKeyId =
        \(QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
data_) -> forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (forall expr. IsSql99ExpressionSyntax expr => Text -> [expr] -> expr
funcE Text
"pgp_key_id" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA [Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
data_]),

    pgCryptoArmor :: forall ctxt s.
PgExpr ctxt s ByteString
-> Maybe (PgExpr ctxt s (Vector Text), PgExpr ctxt s (Vector Text))
-> PgExpr ctxt s Text
pgCryptoArmor =
        \(QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
data_) Maybe (PgExpr ctxt s (Vector Text), PgExpr ctxt s (Vector Text))
keysData ->
            forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (forall expr. IsSql99ExpressionSyntax expr => Text -> [expr] -> expr
funcE Text
"armor" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA
                     ([Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
data_] forall a. [a] -> [a] -> [a]
++
                      case Maybe (PgExpr ctxt s (Vector Text), PgExpr ctxt s (Vector Text))
keysData of
                        Maybe (PgExpr ctxt s (Vector Text), PgExpr ctxt s (Vector Text))
Nothing -> []
                        Just (QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
keys, QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
values) ->
                          [Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
keys, Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
values])),
    pgCryptoDearmor :: forall ctxt s. LiftPg ctxt s (Text -> ByteString)
pgCryptoDearmor =
        \(QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
data_) -> forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (forall expr. IsSql99ExpressionSyntax expr => Text -> [expr] -> expr
funcE Text
"dearmor" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA [Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
data_]),

    pgCryptoGenRandomBytes :: forall ctxt s i.
Integral i =>
PgExpr ctxt s i -> PgExpr ctxt s ByteString
pgCryptoGenRandomBytes =
        \(QExpr Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
count) ->
            forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (forall expr. IsSql99ExpressionSyntax expr => Text -> [expr] -> expr
funcE Text
"gen_random_bytes" forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA [Text
-> Sql92SelectTableExpressionSyntax
     (Sql92SelectSelectTableSyntax
        (Sql92SelectSyntax (BeamSqlBackendSyntax Postgres)))
count]),
    pgCryptoGenRandomUUID :: forall ctxt s. PgExpr ctxt s UUID
pgCryptoGenRandomUUID =
         forall context be s t.
(Text -> BeamSqlBackendExpressionSyntax be)
-> QGenExpr context be s t
QExpr (\Text
_ -> forall expr. IsSql99ExpressionSyntax expr => Text -> [expr] -> expr
funcE Text
"gen_random_uuid" [])
    }