{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE PatternSynonyms #-}

-- |
-- Module      : Network.TLS.Crypto.Types
-- License     : BSD-style
-- Maintainer  : Kazu Yamamoto <kazu@iij.ad.jp>
-- Stability   : experimental
-- Portability : unknown
module Network.TLS.Crypto.Types (
    Group (
        Group,
        P256,
        P384,
        P521,
        X25519,
        X448,
        FFDHE2048,
        FFDHE3072,
        FFDHE4096,
        FFDHE6144,
        FFDHE8192
    ),
    availableFFGroups,
    availableECGroups,
    supportedNamedGroups,
    KeyExchangeSignatureAlg (..),
) where

import Codec.Serialise
import Data.Word
import GHC.Generics

newtype Group = Group Word16 deriving (Group -> Group -> Bool
(Group -> Group -> Bool) -> (Group -> Group -> Bool) -> Eq Group
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Group -> Group -> Bool
== :: Group -> Group -> Bool
$c/= :: Group -> Group -> Bool
/= :: Group -> Group -> Bool
Eq, (forall x. Group -> Rep Group x)
-> (forall x. Rep Group x -> Group) -> Generic Group
forall x. Rep Group x -> Group
forall x. Group -> Rep Group x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Group -> Rep Group x
from :: forall x. Group -> Rep Group x
$cto :: forall x. Rep Group x -> Group
to :: forall x. Rep Group x -> Group
Generic)
instance Serialise Group

{- FOURMOLU_DISABLE -}
pattern P256      :: Group
pattern $mP256 :: forall {r}. Group -> ((# #) -> r) -> ((# #) -> r) -> r
$bP256 :: Group
P256       = Group 23
pattern P384      :: Group
pattern $mP384 :: forall {r}. Group -> ((# #) -> r) -> ((# #) -> r) -> r
$bP384 :: Group
P384       = Group 24
pattern P521      :: Group
pattern $mP521 :: forall {r}. Group -> ((# #) -> r) -> ((# #) -> r) -> r
$bP521 :: Group
P521       = Group 25
pattern X25519    :: Group
pattern $mX25519 :: forall {r}. Group -> ((# #) -> r) -> ((# #) -> r) -> r
$bX25519 :: Group
X25519     = Group 29
pattern X448      :: Group
pattern $mX448 :: forall {r}. Group -> ((# #) -> r) -> ((# #) -> r) -> r
$bX448 :: Group
X448       = Group 30
pattern FFDHE2048 :: Group
pattern $mFFDHE2048 :: forall {r}. Group -> ((# #) -> r) -> ((# #) -> r) -> r
$bFFDHE2048 :: Group
FFDHE2048  = Group 256
pattern FFDHE3072 :: Group
pattern $mFFDHE3072 :: forall {r}. Group -> ((# #) -> r) -> ((# #) -> r) -> r
$bFFDHE3072 :: Group
FFDHE3072  = Group 257
pattern FFDHE4096 :: Group
pattern $mFFDHE4096 :: forall {r}. Group -> ((# #) -> r) -> ((# #) -> r) -> r
$bFFDHE4096 :: Group
FFDHE4096  = Group 258
pattern FFDHE6144 :: Group
pattern $mFFDHE6144 :: forall {r}. Group -> ((# #) -> r) -> ((# #) -> r) -> r
$bFFDHE6144 :: Group
FFDHE6144  = Group 259
pattern FFDHE8192 :: Group
pattern $mFFDHE8192 :: forall {r}. Group -> ((# #) -> r) -> ((# #) -> r) -> r
$bFFDHE8192 :: Group
FFDHE8192  = Group 260

instance Show Group where
    show :: Group -> String
show Group
P256      = String
"P256"
    show Group
P384      = String
"P384"
    show Group
P521      = String
"P521"
    show Group
X25519    = String
"X25519"
    show Group
X448      = String
"X448"
    show Group
FFDHE2048 = String
"FFDHE2048"
    show Group
FFDHE3072 = String
"FFDHE3072"
    show Group
FFDHE4096 = String
"FFDHE4096"
    show Group
FFDHE6144 = String
"FFDHE6144"
    show Group
FFDHE8192 = String
"FFDHE8192"
    show (Group Word16
x) = String
"Group " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word16 -> String
forall a. Show a => a -> String
show Word16
x
{- FOURMOLU_ENABLE -}

availableFFGroups :: [Group]
availableFFGroups :: [Group]
availableFFGroups = [Group
FFDHE2048, Group
FFDHE3072, Group
FFDHE4096, Group
FFDHE6144, Group
FFDHE8192]

availableECGroups :: [Group]
availableECGroups :: [Group]
availableECGroups = [Group
P256, Group
P384, Group
P521, Group
X25519, Group
X448]

supportedNamedGroups :: [Group]
supportedNamedGroups :: [Group]
supportedNamedGroups = [Group
X25519, Group
X448, Group
P256, Group
FFDHE3072, Group
FFDHE4096, Group
P384, Group
FFDHE6144, Group
FFDHE8192, Group
P521]

-- Key-exchange signature algorithm, in close relation to ciphers
-- (before TLS 1.3).
data KeyExchangeSignatureAlg = KX_RSA | KX_DSA | KX_ECDSA
    deriving (Int -> KeyExchangeSignatureAlg -> ShowS
[KeyExchangeSignatureAlg] -> ShowS
KeyExchangeSignatureAlg -> String
(Int -> KeyExchangeSignatureAlg -> ShowS)
-> (KeyExchangeSignatureAlg -> String)
-> ([KeyExchangeSignatureAlg] -> ShowS)
-> Show KeyExchangeSignatureAlg
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> KeyExchangeSignatureAlg -> ShowS
showsPrec :: Int -> KeyExchangeSignatureAlg -> ShowS
$cshow :: KeyExchangeSignatureAlg -> String
show :: KeyExchangeSignatureAlg -> String
$cshowList :: [KeyExchangeSignatureAlg] -> ShowS
showList :: [KeyExchangeSignatureAlg] -> ShowS
Show, KeyExchangeSignatureAlg -> KeyExchangeSignatureAlg -> Bool
(KeyExchangeSignatureAlg -> KeyExchangeSignatureAlg -> Bool)
-> (KeyExchangeSignatureAlg -> KeyExchangeSignatureAlg -> Bool)
-> Eq KeyExchangeSignatureAlg
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: KeyExchangeSignatureAlg -> KeyExchangeSignatureAlg -> Bool
== :: KeyExchangeSignatureAlg -> KeyExchangeSignatureAlg -> Bool
$c/= :: KeyExchangeSignatureAlg -> KeyExchangeSignatureAlg -> Bool
/= :: KeyExchangeSignatureAlg -> KeyExchangeSignatureAlg -> Bool
Eq)