-- This file is part of the Wire Server implementation.
--
-- Copyright (C) 2022 Wire Swiss GmbH <opensource@wire.com>
--
-- This program is free software: you can redistribute it and/or modify it under
-- the terms of the GNU Affero General Public License as published by the Free
-- Software Foundation, either version 3 of the License, or (at your option) any
-- later version.
--
-- This program is distributed in the hope that it will be useful, but WITHOUT
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
-- details.
--
-- You should have received a copy of the GNU Affero General Public License along
-- with this program. If not, see <https://www.gnu.org/licenses/>.

module Wire.API.MLS.LeafNode
  ( LeafIndex,
    LeafNode (..),
    LeafNodeCore (..),
    LeafNodeTBS (..),
    LeafNodeTBSExtra (..),
    LeafNodeSource (..),
    LeafNodeSourceTag (..),
    leafNodeSourceTag,
  )
where

import Data.Binary
import Data.OpenApi qualified as S
import GHC.Records
import Imports
import Test.QuickCheck
import Wire.API.MLS.Capabilities
import Wire.API.MLS.Credential
import Wire.API.MLS.Extension
import Wire.API.MLS.Group
import Wire.API.MLS.HPKEPublicKey
import Wire.API.MLS.Lifetime
import Wire.API.MLS.Serialisation
import Wire.Arbitrary

type LeafIndex = Word32

-- LeafNodeCore contains fields in the intersection of LeafNode and LeafNodeTBS
--
-- https://messaginglayersecurity.rocks/mls-protocol/draft-ietf-mls-protocol-20/draft-ietf-mls-protocol.html#section-7.2-2
data LeafNodeCore = LeafNodeCore
  { LeafNodeCore -> HPKEPublicKey
encryptionKey :: HPKEPublicKey,
    LeafNodeCore -> ByteString
signatureKey :: ByteString,
    LeafNodeCore -> Credential
credential :: Credential,
    LeafNodeCore -> Capabilities
capabilities :: Capabilities,
    LeafNodeCore -> LeafNodeSource
source :: LeafNodeSource,
    LeafNodeCore -> [Extension]
extensions :: [Extension]
  }
  deriving (Int -> LeafNodeCore -> ShowS
[LeafNodeCore] -> ShowS
LeafNodeCore -> String
(Int -> LeafNodeCore -> ShowS)
-> (LeafNodeCore -> String)
-> ([LeafNodeCore] -> ShowS)
-> Show LeafNodeCore
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LeafNodeCore -> ShowS
showsPrec :: Int -> LeafNodeCore -> ShowS
$cshow :: LeafNodeCore -> String
show :: LeafNodeCore -> String
$cshowList :: [LeafNodeCore] -> ShowS
showList :: [LeafNodeCore] -> ShowS
Show, LeafNodeCore -> LeafNodeCore -> Bool
(LeafNodeCore -> LeafNodeCore -> Bool)
-> (LeafNodeCore -> LeafNodeCore -> Bool) -> Eq LeafNodeCore
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LeafNodeCore -> LeafNodeCore -> Bool
== :: LeafNodeCore -> LeafNodeCore -> Bool
$c/= :: LeafNodeCore -> LeafNodeCore -> Bool
/= :: LeafNodeCore -> LeafNodeCore -> Bool
Eq, (forall x. LeafNodeCore -> Rep LeafNodeCore x)
-> (forall x. Rep LeafNodeCore x -> LeafNodeCore)
-> Generic LeafNodeCore
forall x. Rep LeafNodeCore x -> LeafNodeCore
forall x. LeafNodeCore -> Rep LeafNodeCore x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. LeafNodeCore -> Rep LeafNodeCore x
from :: forall x. LeafNodeCore -> Rep LeafNodeCore x
$cto :: forall x. Rep LeafNodeCore x -> LeafNodeCore
to :: forall x. Rep LeafNodeCore x -> LeafNodeCore
Generic)
  deriving (Gen LeafNodeCore
Gen LeafNodeCore
-> (LeafNodeCore -> [LeafNodeCore]) -> Arbitrary LeafNodeCore
LeafNodeCore -> [LeafNodeCore]
forall a. Gen a -> (a -> [a]) -> Arbitrary a
$carbitrary :: Gen LeafNodeCore
arbitrary :: Gen LeafNodeCore
$cshrink :: LeafNodeCore -> [LeafNodeCore]
shrink :: LeafNodeCore -> [LeafNodeCore]
Arbitrary) via (GenericUniform LeafNodeCore)

-- extra fields in LeafNodeTBS, but not in LeafNode
--
-- https://messaginglayersecurity.rocks/mls-protocol/draft-ietf-mls-protocol-20/draft-ietf-mls-protocol.html#section-7.2-2
data LeafNodeTBSExtra
  = LeafNodeTBSExtraKeyPackage
  | LeafNodeTBSExtraUpdate GroupId LeafIndex
  | LeafNodeTBSExtraCommit GroupId LeafIndex

serialiseUntaggedLeafNodeTBSExtra :: LeafNodeTBSExtra -> Put
serialiseUntaggedLeafNodeTBSExtra :: LeafNodeTBSExtra -> Put
serialiseUntaggedLeafNodeTBSExtra LeafNodeTBSExtra
LeafNodeTBSExtraKeyPackage = () -> Put
forall a. a -> PutM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
serialiseUntaggedLeafNodeTBSExtra (LeafNodeTBSExtraUpdate GroupId
gid LeafIndex
idx) = do
  GroupId -> Put
forall a. SerialiseMLS a => a -> Put
serialiseMLS GroupId
gid
  LeafIndex -> Put
forall a. SerialiseMLS a => a -> Put
serialiseMLS LeafIndex
idx
serialiseUntaggedLeafNodeTBSExtra (LeafNodeTBSExtraCommit GroupId
gid LeafIndex
idx) = do
  GroupId -> Put
forall a. SerialiseMLS a => a -> Put
serialiseMLS GroupId
gid
  LeafIndex -> Put
forall a. SerialiseMLS a => a -> Put
serialiseMLS LeafIndex
idx

instance HasField "tag" LeafNodeTBSExtra LeafNodeSourceTag where
  getField :: LeafNodeTBSExtra -> LeafNodeSourceTag
getField = \case
    LeafNodeTBSExtra
LeafNodeTBSExtraKeyPackage -> LeafNodeSourceTag
LeafNodeSourceKeyPackageTag
    LeafNodeTBSExtraCommit GroupId
_ LeafIndex
_ -> LeafNodeSourceTag
LeafNodeSourceCommitTag
    LeafNodeTBSExtraUpdate GroupId
_ LeafIndex
_ -> LeafNodeSourceTag
LeafNodeSourceUpdateTag

-- | https://messaginglayersecurity.rocks/mls-protocol/draft-ietf-mls-protocol-20/draft-ietf-mls-protocol.html#section-7.2-2
data LeafNodeTBS = LeafNodeTBS
  { LeafNodeTBS -> RawMLS LeafNodeCore
core :: RawMLS LeafNodeCore,
    LeafNodeTBS -> LeafNodeTBSExtra
extra :: LeafNodeTBSExtra
  }

instance SerialiseMLS LeafNodeTBS where
  serialiseMLS :: LeafNodeTBS -> Put
serialiseMLS LeafNodeTBS
tbs = do
    RawMLS LeafNodeCore -> Put
forall a. SerialiseMLS a => a -> Put
serialiseMLS LeafNodeTBS
tbs.core
    LeafNodeTBSExtra -> Put
serialiseUntaggedLeafNodeTBSExtra LeafNodeTBS
tbs.extra

instance ParseMLS LeafNodeCore where
  parseMLS :: Get LeafNodeCore
parseMLS =
    HPKEPublicKey
-> ByteString
-> Credential
-> Capabilities
-> LeafNodeSource
-> [Extension]
-> LeafNodeCore
LeafNodeCore
      (HPKEPublicKey
 -> ByteString
 -> Credential
 -> Capabilities
 -> LeafNodeSource
 -> [Extension]
 -> LeafNodeCore)
-> Get HPKEPublicKey
-> Get
     (ByteString
      -> Credential
      -> Capabilities
      -> LeafNodeSource
      -> [Extension]
      -> LeafNodeCore)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get HPKEPublicKey
forall a. ParseMLS a => Get a
parseMLS
      Get
  (ByteString
   -> Credential
   -> Capabilities
   -> LeafNodeSource
   -> [Extension]
   -> LeafNodeCore)
-> Get ByteString
-> Get
     (Credential
      -> Capabilities -> LeafNodeSource -> [Extension] -> LeafNodeCore)
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall w. (Binary w, Integral w) => Get ByteString
parseMLSBytes @VarInt
      Get
  (Credential
   -> Capabilities -> LeafNodeSource -> [Extension] -> LeafNodeCore)
-> Get Credential
-> Get
     (Capabilities -> LeafNodeSource -> [Extension] -> LeafNodeCore)
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Credential
forall a. ParseMLS a => Get a
parseMLS
      Get (Capabilities -> LeafNodeSource -> [Extension] -> LeafNodeCore)
-> Get Capabilities
-> Get (LeafNodeSource -> [Extension] -> LeafNodeCore)
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get Capabilities
forall a. ParseMLS a => Get a
parseMLS
      Get (LeafNodeSource -> [Extension] -> LeafNodeCore)
-> Get LeafNodeSource -> Get ([Extension] -> LeafNodeCore)
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Get LeafNodeSource
forall a. ParseMLS a => Get a
parseMLS
      Get ([Extension] -> LeafNodeCore)
-> Get [Extension] -> Get LeafNodeCore
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall w a. (Binary w, Integral w) => Get a -> Get [a]
parseMLSVector @VarInt Get Extension
forall a. ParseMLS a => Get a
parseMLS

instance SerialiseMLS LeafNodeCore where
  serialiseMLS :: LeafNodeCore -> Put
serialiseMLS LeafNodeCore
core = do
    HPKEPublicKey -> Put
forall a. SerialiseMLS a => a -> Put
serialiseMLS LeafNodeCore
core.encryptionKey
    forall w. (Binary w, Integral w) => ByteString -> Put
serialiseMLSBytes @VarInt LeafNodeCore
core.signatureKey
    Credential -> Put
forall a. SerialiseMLS a => a -> Put
serialiseMLS LeafNodeCore
core.credential
    Capabilities -> Put
forall a. SerialiseMLS a => a -> Put
serialiseMLS LeafNodeCore
core.capabilities
    LeafNodeSource -> Put
forall a. SerialiseMLS a => a -> Put
serialiseMLS LeafNodeCore
core.source
    forall w a. (Binary w, Integral w) => (a -> Put) -> [a] -> Put
serialiseMLSVector @VarInt Extension -> Put
forall a. SerialiseMLS a => a -> Put
serialiseMLS LeafNodeCore
core.extensions

-- | This type can only verify the signature when the LeafNodeSource is
-- LeafNodeSourceKeyPackage
--
-- https://messaginglayersecurity.rocks/mls-protocol/draft-ietf-mls-protocol-20/draft-ietf-mls-protocol.html#section-7.2-2
data LeafNode = LeafNode
  { LeafNode -> RawMLS LeafNodeCore
core :: RawMLS LeafNodeCore,
    LeafNode -> ByteString
signature_ :: ByteString
  }
  deriving (Int -> LeafNode -> ShowS
[LeafNode] -> ShowS
LeafNode -> String
(Int -> LeafNode -> ShowS)
-> (LeafNode -> String) -> ([LeafNode] -> ShowS) -> Show LeafNode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LeafNode -> ShowS
showsPrec :: Int -> LeafNode -> ShowS
$cshow :: LeafNode -> String
show :: LeafNode -> String
$cshowList :: [LeafNode] -> ShowS
showList :: [LeafNode] -> ShowS
Show, LeafNode -> LeafNode -> Bool
(LeafNode -> LeafNode -> Bool)
-> (LeafNode -> LeafNode -> Bool) -> Eq LeafNode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LeafNode -> LeafNode -> Bool
== :: LeafNode -> LeafNode -> Bool
$c/= :: LeafNode -> LeafNode -> Bool
/= :: LeafNode -> LeafNode -> Bool
Eq, (forall x. LeafNode -> Rep LeafNode x)
-> (forall x. Rep LeafNode x -> LeafNode) -> Generic LeafNode
forall x. Rep LeafNode x -> LeafNode
forall x. LeafNode -> Rep LeafNode x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. LeafNode -> Rep LeafNode x
from :: forall x. LeafNode -> Rep LeafNode x
$cto :: forall x. Rep LeafNode x -> LeafNode
to :: forall x. Rep LeafNode x -> LeafNode
Generic)
  deriving (Gen LeafNode
Gen LeafNode -> (LeafNode -> [LeafNode]) -> Arbitrary LeafNode
LeafNode -> [LeafNode]
forall a. Gen a -> (a -> [a]) -> Arbitrary a
$carbitrary :: Gen LeafNode
arbitrary :: Gen LeafNode
$cshrink :: LeafNode -> [LeafNode]
shrink :: LeafNode -> [LeafNode]
Arbitrary) via (GenericUniform LeafNode)

instance ParseMLS LeafNode where
  parseMLS :: Get LeafNode
parseMLS =
    RawMLS LeafNodeCore -> ByteString -> LeafNode
LeafNode
      (RawMLS LeafNodeCore -> ByteString -> LeafNode)
-> Get (RawMLS LeafNodeCore) -> Get (ByteString -> LeafNode)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get (RawMLS LeafNodeCore)
forall a. ParseMLS a => Get a
parseMLS
      Get (ByteString -> LeafNode) -> Get ByteString -> Get LeafNode
forall a b. Get (a -> b) -> Get a -> Get b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall w. (Binary w, Integral w) => Get ByteString
parseMLSBytes @VarInt

instance SerialiseMLS LeafNode where
  serialiseMLS :: LeafNode -> Put
serialiseMLS LeafNode
ln = do
    RawMLS LeafNodeCore -> Put
forall a. SerialiseMLS a => a -> Put
serialiseMLS LeafNode
ln.core
    forall w. (Binary w, Integral w) => ByteString -> Put
serialiseMLSBytes @VarInt LeafNode
ln.signature_

instance S.ToSchema LeafNode where
  declareNamedSchema :: Proxy LeafNode -> Declare (Definitions Schema) NamedSchema
declareNamedSchema Proxy LeafNode
_ = NamedSchema -> Declare (Definitions Schema) NamedSchema
forall a. a -> DeclareT (Definitions Schema) Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Text -> NamedSchema
mlsSwagger Text
"LeafNode")

instance HasField "encryptionKey" LeafNode HPKEPublicKey where
  getField :: LeafNode -> HPKEPublicKey
getField = (.core.value.encryptionKey)

instance HasField "signatureKey" LeafNode ByteString where
  getField :: LeafNode -> ByteString
getField = (.core.value.signatureKey)

instance HasField "credential" LeafNode Credential where
  getField :: LeafNode -> Credential
getField = (.core.value.credential)

instance HasField "capabilities" LeafNode Capabilities where
  getField :: LeafNode -> Capabilities
getField = (.core.value.capabilities)

instance HasField "source" LeafNode LeafNodeSource where
  getField :: LeafNode -> LeafNodeSource
getField = (.core.value.source)

instance HasField "extensions" LeafNode [Extension] where
  getField :: LeafNode -> [Extension]
getField = (.core.value.extensions)

-- | https://messaginglayersecurity.rocks/mls-protocol/draft-ietf-mls-protocol-20/draft-ietf-mls-protocol.html#section-7.2-2
data LeafNodeSource
  = LeafNodeSourceKeyPackage Lifetime
  | LeafNodeSourceUpdate
  | LeafNodeSourceCommit ByteString
  deriving (Int -> LeafNodeSource -> ShowS
[LeafNodeSource] -> ShowS
LeafNodeSource -> String
(Int -> LeafNodeSource -> ShowS)
-> (LeafNodeSource -> String)
-> ([LeafNodeSource] -> ShowS)
-> Show LeafNodeSource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LeafNodeSource -> ShowS
showsPrec :: Int -> LeafNodeSource -> ShowS
$cshow :: LeafNodeSource -> String
show :: LeafNodeSource -> String
$cshowList :: [LeafNodeSource] -> ShowS
showList :: [LeafNodeSource] -> ShowS
Show, LeafNodeSource -> LeafNodeSource -> Bool
(LeafNodeSource -> LeafNodeSource -> Bool)
-> (LeafNodeSource -> LeafNodeSource -> Bool) -> Eq LeafNodeSource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LeafNodeSource -> LeafNodeSource -> Bool
== :: LeafNodeSource -> LeafNodeSource -> Bool
$c/= :: LeafNodeSource -> LeafNodeSource -> Bool
/= :: LeafNodeSource -> LeafNodeSource -> Bool
Eq, (forall x. LeafNodeSource -> Rep LeafNodeSource x)
-> (forall x. Rep LeafNodeSource x -> LeafNodeSource)
-> Generic LeafNodeSource
forall x. Rep LeafNodeSource x -> LeafNodeSource
forall x. LeafNodeSource -> Rep LeafNodeSource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. LeafNodeSource -> Rep LeafNodeSource x
from :: forall x. LeafNodeSource -> Rep LeafNodeSource x
$cto :: forall x. Rep LeafNodeSource x -> LeafNodeSource
to :: forall x. Rep LeafNodeSource x -> LeafNodeSource
Generic)
  deriving (Gen LeafNodeSource
Gen LeafNodeSource
-> (LeafNodeSource -> [LeafNodeSource]) -> Arbitrary LeafNodeSource
LeafNodeSource -> [LeafNodeSource]
forall a. Gen a -> (a -> [a]) -> Arbitrary a
$carbitrary :: Gen LeafNodeSource
arbitrary :: Gen LeafNodeSource
$cshrink :: LeafNodeSource -> [LeafNodeSource]
shrink :: LeafNodeSource -> [LeafNodeSource]
Arbitrary) via (GenericUniform LeafNodeSource)

instance ParseMLS LeafNodeSource where
  parseMLS :: Get LeafNodeSource
parseMLS =
    Get LeafNodeSourceTag
forall a. ParseMLS a => Get a
parseMLS Get LeafNodeSourceTag
-> (LeafNodeSourceTag -> Get LeafNodeSource) -> Get LeafNodeSource
forall a b. Get a -> (a -> Get b) -> Get b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
      LeafNodeSourceTag
LeafNodeSourceKeyPackageTag -> Lifetime -> LeafNodeSource
LeafNodeSourceKeyPackage (Lifetime -> LeafNodeSource) -> Get Lifetime -> Get LeafNodeSource
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get Lifetime
forall a. ParseMLS a => Get a
parseMLS
      LeafNodeSourceTag
LeafNodeSourceUpdateTag -> LeafNodeSource -> Get LeafNodeSource
forall a. a -> Get a
forall (f :: * -> *) a. Applicative f => a -> f a
pure LeafNodeSource
LeafNodeSourceUpdate
      LeafNodeSourceTag
LeafNodeSourceCommitTag -> ByteString -> LeafNodeSource
LeafNodeSourceCommit (ByteString -> LeafNodeSource)
-> Get ByteString -> Get LeafNodeSource
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall w. (Binary w, Integral w) => Get ByteString
parseMLSBytes @VarInt

instance SerialiseMLS LeafNodeSource where
  serialiseMLS :: LeafNodeSource -> Put
serialiseMLS (LeafNodeSourceKeyPackage Lifetime
lt) = do
    LeafNodeSourceTag -> Put
forall a. SerialiseMLS a => a -> Put
serialiseMLS LeafNodeSourceTag
LeafNodeSourceKeyPackageTag
    Lifetime -> Put
forall a. SerialiseMLS a => a -> Put
serialiseMLS Lifetime
lt
  serialiseMLS LeafNodeSource
LeafNodeSourceUpdate =
    LeafNodeSourceTag -> Put
forall a. SerialiseMLS a => a -> Put
serialiseMLS LeafNodeSourceTag
LeafNodeSourceUpdateTag
  serialiseMLS (LeafNodeSourceCommit ByteString
bs) = do
    LeafNodeSourceTag -> Put
forall a. SerialiseMLS a => a -> Put
serialiseMLS LeafNodeSourceTag
LeafNodeSourceCommitTag
    forall w. (Binary w, Integral w) => ByteString -> Put
serialiseMLSBytes @VarInt ByteString
bs

data LeafNodeSourceTag
  = LeafNodeSourceKeyPackageTag
  | LeafNodeSourceUpdateTag
  | LeafNodeSourceCommitTag
  deriving (Int -> LeafNodeSourceTag -> ShowS
[LeafNodeSourceTag] -> ShowS
LeafNodeSourceTag -> String
(Int -> LeafNodeSourceTag -> ShowS)
-> (LeafNodeSourceTag -> String)
-> ([LeafNodeSourceTag] -> ShowS)
-> Show LeafNodeSourceTag
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LeafNodeSourceTag -> ShowS
showsPrec :: Int -> LeafNodeSourceTag -> ShowS
$cshow :: LeafNodeSourceTag -> String
show :: LeafNodeSourceTag -> String
$cshowList :: [LeafNodeSourceTag] -> ShowS
showList :: [LeafNodeSourceTag] -> ShowS
Show, LeafNodeSourceTag -> LeafNodeSourceTag -> Bool
(LeafNodeSourceTag -> LeafNodeSourceTag -> Bool)
-> (LeafNodeSourceTag -> LeafNodeSourceTag -> Bool)
-> Eq LeafNodeSourceTag
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LeafNodeSourceTag -> LeafNodeSourceTag -> Bool
== :: LeafNodeSourceTag -> LeafNodeSourceTag -> Bool
$c/= :: LeafNodeSourceTag -> LeafNodeSourceTag -> Bool
/= :: LeafNodeSourceTag -> LeafNodeSourceTag -> Bool
Eq, Eq LeafNodeSourceTag
Eq LeafNodeSourceTag =>
(LeafNodeSourceTag -> LeafNodeSourceTag -> Ordering)
-> (LeafNodeSourceTag -> LeafNodeSourceTag -> Bool)
-> (LeafNodeSourceTag -> LeafNodeSourceTag -> Bool)
-> (LeafNodeSourceTag -> LeafNodeSourceTag -> Bool)
-> (LeafNodeSourceTag -> LeafNodeSourceTag -> Bool)
-> (LeafNodeSourceTag -> LeafNodeSourceTag -> LeafNodeSourceTag)
-> (LeafNodeSourceTag -> LeafNodeSourceTag -> LeafNodeSourceTag)
-> Ord LeafNodeSourceTag
LeafNodeSourceTag -> LeafNodeSourceTag -> Bool
LeafNodeSourceTag -> LeafNodeSourceTag -> Ordering
LeafNodeSourceTag -> LeafNodeSourceTag -> LeafNodeSourceTag
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: LeafNodeSourceTag -> LeafNodeSourceTag -> Ordering
compare :: LeafNodeSourceTag -> LeafNodeSourceTag -> Ordering
$c< :: LeafNodeSourceTag -> LeafNodeSourceTag -> Bool
< :: LeafNodeSourceTag -> LeafNodeSourceTag -> Bool
$c<= :: LeafNodeSourceTag -> LeafNodeSourceTag -> Bool
<= :: LeafNodeSourceTag -> LeafNodeSourceTag -> Bool
$c> :: LeafNodeSourceTag -> LeafNodeSourceTag -> Bool
> :: LeafNodeSourceTag -> LeafNodeSourceTag -> Bool
$c>= :: LeafNodeSourceTag -> LeafNodeSourceTag -> Bool
>= :: LeafNodeSourceTag -> LeafNodeSourceTag -> Bool
$cmax :: LeafNodeSourceTag -> LeafNodeSourceTag -> LeafNodeSourceTag
max :: LeafNodeSourceTag -> LeafNodeSourceTag -> LeafNodeSourceTag
$cmin :: LeafNodeSourceTag -> LeafNodeSourceTag -> LeafNodeSourceTag
min :: LeafNodeSourceTag -> LeafNodeSourceTag -> LeafNodeSourceTag
Ord, Int -> LeafNodeSourceTag
LeafNodeSourceTag -> Int
LeafNodeSourceTag -> [LeafNodeSourceTag]
LeafNodeSourceTag -> LeafNodeSourceTag
LeafNodeSourceTag -> LeafNodeSourceTag -> [LeafNodeSourceTag]
LeafNodeSourceTag
-> LeafNodeSourceTag -> LeafNodeSourceTag -> [LeafNodeSourceTag]
(LeafNodeSourceTag -> LeafNodeSourceTag)
-> (LeafNodeSourceTag -> LeafNodeSourceTag)
-> (Int -> LeafNodeSourceTag)
-> (LeafNodeSourceTag -> Int)
-> (LeafNodeSourceTag -> [LeafNodeSourceTag])
-> (LeafNodeSourceTag -> LeafNodeSourceTag -> [LeafNodeSourceTag])
-> (LeafNodeSourceTag -> LeafNodeSourceTag -> [LeafNodeSourceTag])
-> (LeafNodeSourceTag
    -> LeafNodeSourceTag -> LeafNodeSourceTag -> [LeafNodeSourceTag])
-> Enum LeafNodeSourceTag
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: LeafNodeSourceTag -> LeafNodeSourceTag
succ :: LeafNodeSourceTag -> LeafNodeSourceTag
$cpred :: LeafNodeSourceTag -> LeafNodeSourceTag
pred :: LeafNodeSourceTag -> LeafNodeSourceTag
$ctoEnum :: Int -> LeafNodeSourceTag
toEnum :: Int -> LeafNodeSourceTag
$cfromEnum :: LeafNodeSourceTag -> Int
fromEnum :: LeafNodeSourceTag -> Int
$cenumFrom :: LeafNodeSourceTag -> [LeafNodeSourceTag]
enumFrom :: LeafNodeSourceTag -> [LeafNodeSourceTag]
$cenumFromThen :: LeafNodeSourceTag -> LeafNodeSourceTag -> [LeafNodeSourceTag]
enumFromThen :: LeafNodeSourceTag -> LeafNodeSourceTag -> [LeafNodeSourceTag]
$cenumFromTo :: LeafNodeSourceTag -> LeafNodeSourceTag -> [LeafNodeSourceTag]
enumFromTo :: LeafNodeSourceTag -> LeafNodeSourceTag -> [LeafNodeSourceTag]
$cenumFromThenTo :: LeafNodeSourceTag
-> LeafNodeSourceTag -> LeafNodeSourceTag -> [LeafNodeSourceTag]
enumFromThenTo :: LeafNodeSourceTag
-> LeafNodeSourceTag -> LeafNodeSourceTag -> [LeafNodeSourceTag]
Enum, LeafNodeSourceTag
LeafNodeSourceTag -> LeafNodeSourceTag -> Bounded LeafNodeSourceTag
forall a. a -> a -> Bounded a
$cminBound :: LeafNodeSourceTag
minBound :: LeafNodeSourceTag
$cmaxBound :: LeafNodeSourceTag
maxBound :: LeafNodeSourceTag
Bounded)

instance ParseMLS LeafNodeSourceTag where
  parseMLS :: Get LeafNodeSourceTag
parseMLS = forall w a.
(Bounded a, Enum a, Integral w, Binary w) =>
String -> Get a
parseMLSEnum @Word8 String
"leaf node source"

instance SerialiseMLS LeafNodeSourceTag where
  serialiseMLS :: LeafNodeSourceTag -> Put
serialiseMLS = forall w a. (Enum a, Integral w, Binary w) => a -> Put
serialiseMLSEnum @Word8

instance HasField "name" LeafNodeSourceTag Text where
  getField :: LeafNodeSourceTag -> Text
getField LeafNodeSourceTag
LeafNodeSourceKeyPackageTag = Text
"key_package"
  getField LeafNodeSourceTag
LeafNodeSourceUpdateTag = Text
"update"
  getField LeafNodeSourceTag
LeafNodeSourceCommitTag = Text
"commit"

leafNodeSourceTag :: LeafNodeSource -> LeafNodeSourceTag
leafNodeSourceTag :: LeafNodeSource -> LeafNodeSourceTag
leafNodeSourceTag (LeafNodeSourceKeyPackage Lifetime
_) = LeafNodeSourceTag
LeafNodeSourceKeyPackageTag
leafNodeSourceTag LeafNodeSource
LeafNodeSourceUpdate = LeafNodeSourceTag
LeafNodeSourceUpdateTag
leafNodeSourceTag (LeafNodeSourceCommit ByteString
_) = LeafNodeSourceTag
LeafNodeSourceCommitTag