{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}

-- | Mock implementation of digital signatures.
module Cardano.Crypto.DSIGN.Mock
  ( MockDSIGN
  , SignKeyDSIGN (..)
  , VerKeyDSIGN (..)
  , SigDSIGN (..)
  , mockSign
  )
where

import Data.Word (Word64)
import GHC.Generics (Generic)
import GHC.TypeLits (type (+))
import Data.Proxy (Proxy (..))
import GHC.Stack
import NoThunks.Class (NoThunks)

import Cardano.Prelude (NFData)
import Cardano.Binary (FromCBOR (..), ToCBOR (..))

import Cardano.Crypto.DSIGN.Class
import Cardano.Crypto.Seed
import Cardano.Crypto.Hash
import Cardano.Crypto.Util


data MockDSIGN

instance DSIGNAlgorithm MockDSIGN where
    type SeedSizeDSIGN MockDSIGN = 8
    type SizeVerKeyDSIGN  MockDSIGN = 8 -- for 64 bit int
    type SizeSignKeyDSIGN MockDSIGN = 8
    type SizeSigDSIGN     MockDSIGN = SizeHash ShortHash + 8

    --
    -- Key and signature types
    --

    newtype VerKeyDSIGN MockDSIGN = VerKeyMockDSIGN Word64
        deriving stock   (Int -> VerKeyDSIGN MockDSIGN -> ShowS
[VerKeyDSIGN MockDSIGN] -> ShowS
VerKeyDSIGN MockDSIGN -> String
(Int -> VerKeyDSIGN MockDSIGN -> ShowS)
-> (VerKeyDSIGN MockDSIGN -> String)
-> ([VerKeyDSIGN MockDSIGN] -> ShowS)
-> Show (VerKeyDSIGN MockDSIGN)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VerKeyDSIGN MockDSIGN] -> ShowS
$cshowList :: [VerKeyDSIGN MockDSIGN] -> ShowS
show :: VerKeyDSIGN MockDSIGN -> String
$cshow :: VerKeyDSIGN MockDSIGN -> String
showsPrec :: Int -> VerKeyDSIGN MockDSIGN -> ShowS
$cshowsPrec :: Int -> VerKeyDSIGN MockDSIGN -> ShowS
Show, VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN -> Bool
(VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN -> Bool)
-> (VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN -> Bool)
-> Eq (VerKeyDSIGN MockDSIGN)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN -> Bool
$c/= :: VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN -> Bool
== :: VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN -> Bool
$c== :: VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN -> Bool
Eq, (forall x. VerKeyDSIGN MockDSIGN -> Rep (VerKeyDSIGN MockDSIGN) x)
-> (forall x.
    Rep (VerKeyDSIGN MockDSIGN) x -> VerKeyDSIGN MockDSIGN)
-> Generic (VerKeyDSIGN MockDSIGN)
forall x. Rep (VerKeyDSIGN MockDSIGN) x -> VerKeyDSIGN MockDSIGN
forall x. VerKeyDSIGN MockDSIGN -> Rep (VerKeyDSIGN MockDSIGN) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep (VerKeyDSIGN MockDSIGN) x -> VerKeyDSIGN MockDSIGN
$cfrom :: forall x. VerKeyDSIGN MockDSIGN -> Rep (VerKeyDSIGN MockDSIGN) x
Generic)
        deriving newtype (Integer -> VerKeyDSIGN MockDSIGN
VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
VerKeyDSIGN MockDSIGN
-> VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
(VerKeyDSIGN MockDSIGN
 -> VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN)
-> (VerKeyDSIGN MockDSIGN
    -> VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN)
-> (VerKeyDSIGN MockDSIGN
    -> VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN)
-> (VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN)
-> (VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN)
-> (VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN)
-> (Integer -> VerKeyDSIGN MockDSIGN)
-> Num (VerKeyDSIGN MockDSIGN)
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
fromInteger :: Integer -> VerKeyDSIGN MockDSIGN
$cfromInteger :: Integer -> VerKeyDSIGN MockDSIGN
signum :: VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
$csignum :: VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
abs :: VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
$cabs :: VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
negate :: VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
$cnegate :: VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
* :: VerKeyDSIGN MockDSIGN
-> VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
$c* :: VerKeyDSIGN MockDSIGN
-> VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
- :: VerKeyDSIGN MockDSIGN
-> VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
$c- :: VerKeyDSIGN MockDSIGN
-> VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
+ :: VerKeyDSIGN MockDSIGN
-> VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
$c+ :: VerKeyDSIGN MockDSIGN
-> VerKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
Num, Context -> VerKeyDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
Proxy (VerKeyDSIGN MockDSIGN) -> String
(Context -> VerKeyDSIGN MockDSIGN -> IO (Maybe ThunkInfo))
-> (Context -> VerKeyDSIGN MockDSIGN -> IO (Maybe ThunkInfo))
-> (Proxy (VerKeyDSIGN MockDSIGN) -> String)
-> NoThunks (VerKeyDSIGN MockDSIGN)
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy (VerKeyDSIGN MockDSIGN) -> String
$cshowTypeOf :: Proxy (VerKeyDSIGN MockDSIGN) -> String
wNoThunks :: Context -> VerKeyDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> VerKeyDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
noThunks :: Context -> VerKeyDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> VerKeyDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
NoThunks, VerKeyDSIGN MockDSIGN -> ()
(VerKeyDSIGN MockDSIGN -> ()) -> NFData (VerKeyDSIGN MockDSIGN)
forall a. (a -> ()) -> NFData a
rnf :: VerKeyDSIGN MockDSIGN -> ()
$crnf :: VerKeyDSIGN MockDSIGN -> ()
NFData)

    newtype SignKeyDSIGN MockDSIGN = SignKeyMockDSIGN Word64
        deriving stock   (Int -> SignKeyDSIGN MockDSIGN -> ShowS
[SignKeyDSIGN MockDSIGN] -> ShowS
SignKeyDSIGN MockDSIGN -> String
(Int -> SignKeyDSIGN MockDSIGN -> ShowS)
-> (SignKeyDSIGN MockDSIGN -> String)
-> ([SignKeyDSIGN MockDSIGN] -> ShowS)
-> Show (SignKeyDSIGN MockDSIGN)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SignKeyDSIGN MockDSIGN] -> ShowS
$cshowList :: [SignKeyDSIGN MockDSIGN] -> ShowS
show :: SignKeyDSIGN MockDSIGN -> String
$cshow :: SignKeyDSIGN MockDSIGN -> String
showsPrec :: Int -> SignKeyDSIGN MockDSIGN -> ShowS
$cshowsPrec :: Int -> SignKeyDSIGN MockDSIGN -> ShowS
Show, SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN -> Bool
(SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN -> Bool)
-> (SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN -> Bool)
-> Eq (SignKeyDSIGN MockDSIGN)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN -> Bool
$c/= :: SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN -> Bool
== :: SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN -> Bool
$c== :: SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN -> Bool
Eq, (forall x.
 SignKeyDSIGN MockDSIGN -> Rep (SignKeyDSIGN MockDSIGN) x)
-> (forall x.
    Rep (SignKeyDSIGN MockDSIGN) x -> SignKeyDSIGN MockDSIGN)
-> Generic (SignKeyDSIGN MockDSIGN)
forall x. Rep (SignKeyDSIGN MockDSIGN) x -> SignKeyDSIGN MockDSIGN
forall x. SignKeyDSIGN MockDSIGN -> Rep (SignKeyDSIGN MockDSIGN) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep (SignKeyDSIGN MockDSIGN) x -> SignKeyDSIGN MockDSIGN
$cfrom :: forall x. SignKeyDSIGN MockDSIGN -> Rep (SignKeyDSIGN MockDSIGN) x
Generic)
        deriving newtype (Integer -> SignKeyDSIGN MockDSIGN
SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN
SignKeyDSIGN MockDSIGN
-> SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN
(SignKeyDSIGN MockDSIGN
 -> SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN)
-> (SignKeyDSIGN MockDSIGN
    -> SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN)
-> (SignKeyDSIGN MockDSIGN
    -> SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN)
-> (SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN)
-> (SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN)
-> (SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN)
-> (Integer -> SignKeyDSIGN MockDSIGN)
-> Num (SignKeyDSIGN MockDSIGN)
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
fromInteger :: Integer -> SignKeyDSIGN MockDSIGN
$cfromInteger :: Integer -> SignKeyDSIGN MockDSIGN
signum :: SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN
$csignum :: SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN
abs :: SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN
$cabs :: SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN
negate :: SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN
$cnegate :: SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN
* :: SignKeyDSIGN MockDSIGN
-> SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN
$c* :: SignKeyDSIGN MockDSIGN
-> SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN
- :: SignKeyDSIGN MockDSIGN
-> SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN
$c- :: SignKeyDSIGN MockDSIGN
-> SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN
+ :: SignKeyDSIGN MockDSIGN
-> SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN
$c+ :: SignKeyDSIGN MockDSIGN
-> SignKeyDSIGN MockDSIGN -> SignKeyDSIGN MockDSIGN
Num, Context -> SignKeyDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
Proxy (SignKeyDSIGN MockDSIGN) -> String
(Context -> SignKeyDSIGN MockDSIGN -> IO (Maybe ThunkInfo))
-> (Context -> SignKeyDSIGN MockDSIGN -> IO (Maybe ThunkInfo))
-> (Proxy (SignKeyDSIGN MockDSIGN) -> String)
-> NoThunks (SignKeyDSIGN MockDSIGN)
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy (SignKeyDSIGN MockDSIGN) -> String
$cshowTypeOf :: Proxy (SignKeyDSIGN MockDSIGN) -> String
wNoThunks :: Context -> SignKeyDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> SignKeyDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
noThunks :: Context -> SignKeyDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> SignKeyDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
NoThunks, SignKeyDSIGN MockDSIGN -> ()
(SignKeyDSIGN MockDSIGN -> ()) -> NFData (SignKeyDSIGN MockDSIGN)
forall a. (a -> ()) -> NFData a
rnf :: SignKeyDSIGN MockDSIGN -> ()
$crnf :: SignKeyDSIGN MockDSIGN -> ()
NFData)

    data SigDSIGN MockDSIGN = SigMockDSIGN !(Hash ShortHash ()) !Word64
        deriving stock    (Int -> SigDSIGN MockDSIGN -> ShowS
[SigDSIGN MockDSIGN] -> ShowS
SigDSIGN MockDSIGN -> String
(Int -> SigDSIGN MockDSIGN -> ShowS)
-> (SigDSIGN MockDSIGN -> String)
-> ([SigDSIGN MockDSIGN] -> ShowS)
-> Show (SigDSIGN MockDSIGN)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SigDSIGN MockDSIGN] -> ShowS
$cshowList :: [SigDSIGN MockDSIGN] -> ShowS
show :: SigDSIGN MockDSIGN -> String
$cshow :: SigDSIGN MockDSIGN -> String
showsPrec :: Int -> SigDSIGN MockDSIGN -> ShowS
$cshowsPrec :: Int -> SigDSIGN MockDSIGN -> ShowS
Show, SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
(SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool)
-> (SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool)
-> Eq (SigDSIGN MockDSIGN)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
$c/= :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
== :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
$c== :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
Eq, Eq (SigDSIGN MockDSIGN)
Eq (SigDSIGN MockDSIGN)
-> (SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Ordering)
-> (SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool)
-> (SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool)
-> (SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool)
-> (SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool)
-> (SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN)
-> (SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN)
-> Ord (SigDSIGN MockDSIGN)
SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Ordering
SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN
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
min :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN
$cmin :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN
max :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN
$cmax :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN
>= :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
$c>= :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
> :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
$c> :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
<= :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
$c<= :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
< :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
$c< :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
compare :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Ordering
$ccompare :: SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Ordering
$cp1Ord :: Eq (SigDSIGN MockDSIGN)
Ord, (forall x. SigDSIGN MockDSIGN -> Rep (SigDSIGN MockDSIGN) x)
-> (forall x. Rep (SigDSIGN MockDSIGN) x -> SigDSIGN MockDSIGN)
-> Generic (SigDSIGN MockDSIGN)
forall x. Rep (SigDSIGN MockDSIGN) x -> SigDSIGN MockDSIGN
forall x. SigDSIGN MockDSIGN -> Rep (SigDSIGN MockDSIGN) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep (SigDSIGN MockDSIGN) x -> SigDSIGN MockDSIGN
$cfrom :: forall x. SigDSIGN MockDSIGN -> Rep (SigDSIGN MockDSIGN) x
Generic)
        deriving anyclass (Context -> SigDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
Proxy (SigDSIGN MockDSIGN) -> String
(Context -> SigDSIGN MockDSIGN -> IO (Maybe ThunkInfo))
-> (Context -> SigDSIGN MockDSIGN -> IO (Maybe ThunkInfo))
-> (Proxy (SigDSIGN MockDSIGN) -> String)
-> NoThunks (SigDSIGN MockDSIGN)
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy (SigDSIGN MockDSIGN) -> String
$cshowTypeOf :: Proxy (SigDSIGN MockDSIGN) -> String
wNoThunks :: Context -> SigDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> SigDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
noThunks :: Context -> SigDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> SigDSIGN MockDSIGN -> IO (Maybe ThunkInfo)
NoThunks, SigDSIGN MockDSIGN -> ()
(SigDSIGN MockDSIGN -> ()) -> NFData (SigDSIGN MockDSIGN)
forall a. (a -> ()) -> NFData a
rnf :: SigDSIGN MockDSIGN -> ()
$crnf :: SigDSIGN MockDSIGN -> ()
NFData)


    --
    -- Metadata and basic key operations
    --

    algorithmNameDSIGN :: proxy MockDSIGN -> String
algorithmNameDSIGN proxy MockDSIGN
_ = String
"mock"

    deriveVerKeyDSIGN :: SignKeyDSIGN MockDSIGN -> VerKeyDSIGN MockDSIGN
deriveVerKeyDSIGN (SignKeyMockDSIGN n) = Word64 -> VerKeyDSIGN MockDSIGN
VerKeyMockDSIGN Word64
n

    --
    -- Core algorithm operations
    --

    type Signable MockDSIGN = SignableRepresentation

    signDSIGN :: ContextDSIGN MockDSIGN
-> a -> SignKeyDSIGN MockDSIGN -> SigDSIGN MockDSIGN
signDSIGN () a
a SignKeyDSIGN MockDSIGN
sk = a -> SignKeyDSIGN MockDSIGN -> SigDSIGN MockDSIGN
forall a.
SignableRepresentation a =>
a -> SignKeyDSIGN MockDSIGN -> SigDSIGN MockDSIGN
mockSign a
a SignKeyDSIGN MockDSIGN
sk

    verifyDSIGN :: ContextDSIGN MockDSIGN
-> VerKeyDSIGN MockDSIGN
-> a
-> SigDSIGN MockDSIGN
-> Either String ()
verifyDSIGN () (VerKeyMockDSIGN n) a
a SigDSIGN MockDSIGN
s =
      if SigDSIGN MockDSIGN
s SigDSIGN MockDSIGN -> SigDSIGN MockDSIGN -> Bool
forall a. Eq a => a -> a -> Bool
== a -> SignKeyDSIGN MockDSIGN -> SigDSIGN MockDSIGN
forall a.
SignableRepresentation a =>
a -> SignKeyDSIGN MockDSIGN -> SigDSIGN MockDSIGN
mockSign a
a (Word64 -> SignKeyDSIGN MockDSIGN
SignKeyMockDSIGN Word64
n)
        then () -> Either String ()
forall a b. b -> Either a b
Right ()
        else String -> Either String ()
forall a b. a -> Either a b
Left (String -> Either String ()) -> String -> Either String ()
forall a b. (a -> b) -> a -> b
$ VerificationFailure -> String
forall a. Show a => a -> String
show (VerificationFailure -> String) -> VerificationFailure -> String
forall a b. (a -> b) -> a -> b
$ MockVerificationFailure :: VerKeyDSIGN MockDSIGN
-> SigDSIGN MockDSIGN -> String -> VerificationFailure
MockVerificationFailure {
                 vErrVerKey :: VerKeyDSIGN MockDSIGN
vErrVerKey    = Word64 -> VerKeyDSIGN MockDSIGN
VerKeyMockDSIGN Word64
n
               , vErrSignature :: SigDSIGN MockDSIGN
vErrSignature = SigDSIGN MockDSIGN
s
               , vErrCallStack :: String
vErrCallStack = CallStack -> String
prettyCallStack CallStack
HasCallStack => CallStack
callStack
               }

    --
    -- Key generation
    --

    genKeyDSIGN :: Seed -> SignKeyDSIGN MockDSIGN
genKeyDSIGN Seed
seed   =
      Word64 -> SignKeyDSIGN MockDSIGN
SignKeyMockDSIGN (Seed -> (forall (m :: * -> *). MonadRandom m => m Word64) -> Word64
forall a. Seed -> (forall (m :: * -> *). MonadRandom m => m a) -> a
runMonadRandomWithSeed Seed
seed forall (m :: * -> *). MonadRandom m => m Word64
getRandomWord64)


    --
    -- raw serialise/deserialise
    --


    rawSerialiseVerKeyDSIGN :: VerKeyDSIGN MockDSIGN -> ByteString
rawSerialiseVerKeyDSIGN  (VerKeyMockDSIGN  k) = Word64 -> ByteString
writeBinaryWord64 Word64
k
    rawSerialiseSignKeyDSIGN :: SignKeyDSIGN MockDSIGN -> ByteString
rawSerialiseSignKeyDSIGN (SignKeyMockDSIGN k) = Word64 -> ByteString
writeBinaryWord64 Word64
k
    rawSerialiseSigDSIGN :: SigDSIGN MockDSIGN -> ByteString
rawSerialiseSigDSIGN     (SigMockDSIGN   h k) = Hash ShortHash () -> ByteString
forall h a. Hash h a -> ByteString
hashToBytes Hash ShortHash ()
h
                                                 ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> Word64 -> ByteString
writeBinaryWord64 Word64
k

    rawDeserialiseVerKeyDSIGN :: ByteString -> Maybe (VerKeyDSIGN MockDSIGN)
rawDeserialiseVerKeyDSIGN ByteString
bs
      | [ByteString
kb] <- [Int] -> ByteString -> [ByteString]
splitsAt [Int
8] ByteString
bs
      , let k :: Word64
k = ByteString -> Word64
readBinaryWord64 ByteString
kb
      = VerKeyDSIGN MockDSIGN -> Maybe (VerKeyDSIGN MockDSIGN)
forall a. a -> Maybe a
Just (VerKeyDSIGN MockDSIGN -> Maybe (VerKeyDSIGN MockDSIGN))
-> VerKeyDSIGN MockDSIGN -> Maybe (VerKeyDSIGN MockDSIGN)
forall a b. (a -> b) -> a -> b
$! Word64 -> VerKeyDSIGN MockDSIGN
VerKeyMockDSIGN Word64
k

      | Bool
otherwise
      = Maybe (VerKeyDSIGN MockDSIGN)
forall a. Maybe a
Nothing

    rawDeserialiseSignKeyDSIGN :: ByteString -> Maybe (SignKeyDSIGN MockDSIGN)
rawDeserialiseSignKeyDSIGN ByteString
bs
      | [ByteString
kb] <- [Int] -> ByteString -> [ByteString]
splitsAt [Int
8] ByteString
bs
      , let k :: Word64
k = ByteString -> Word64
readBinaryWord64 ByteString
kb
      = SignKeyDSIGN MockDSIGN -> Maybe (SignKeyDSIGN MockDSIGN)
forall a. a -> Maybe a
Just (SignKeyDSIGN MockDSIGN -> Maybe (SignKeyDSIGN MockDSIGN))
-> SignKeyDSIGN MockDSIGN -> Maybe (SignKeyDSIGN MockDSIGN)
forall a b. (a -> b) -> a -> b
$! Word64 -> SignKeyDSIGN MockDSIGN
SignKeyMockDSIGN Word64
k

      | Bool
otherwise
      = Maybe (SignKeyDSIGN MockDSIGN)
forall a. Maybe a
Nothing

    rawDeserialiseSigDSIGN :: ByteString -> Maybe (SigDSIGN MockDSIGN)
rawDeserialiseSigDSIGN ByteString
bs
      | [ByteString
hb, ByteString
kb] <- [Int] -> ByteString -> [ByteString]
splitsAt [Word -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word -> Int) -> Word -> Int
forall a b. (a -> b) -> a -> b
$ Proxy ShortHash -> Word
forall h (proxy :: * -> *). HashAlgorithm h => proxy h -> Word
sizeHash (Proxy ShortHash
forall k (t :: k). Proxy t
Proxy :: Proxy ShortHash), Int
8] ByteString
bs
      , Just Hash ShortHash ()
h   <- ByteString -> Maybe (Hash ShortHash ())
forall h a. HashAlgorithm h => ByteString -> Maybe (Hash h a)
hashFromBytes ByteString
hb
      , let k :: Word64
k = ByteString -> Word64
readBinaryWord64 ByteString
kb
      = SigDSIGN MockDSIGN -> Maybe (SigDSIGN MockDSIGN)
forall a. a -> Maybe a
Just (SigDSIGN MockDSIGN -> Maybe (SigDSIGN MockDSIGN))
-> SigDSIGN MockDSIGN -> Maybe (SigDSIGN MockDSIGN)
forall a b. (a -> b) -> a -> b
$! Hash ShortHash () -> Word64 -> SigDSIGN MockDSIGN
SigMockDSIGN Hash ShortHash ()
h Word64
k

      | Bool
otherwise
      = Maybe (SigDSIGN MockDSIGN)
forall a. Maybe a
Nothing


instance ToCBOR (VerKeyDSIGN MockDSIGN) where
  toCBOR :: VerKeyDSIGN MockDSIGN -> Encoding
toCBOR = VerKeyDSIGN MockDSIGN -> Encoding
forall v. DSIGNAlgorithm v => VerKeyDSIGN v -> Encoding
encodeVerKeyDSIGN
  encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (VerKeyDSIGN MockDSIGN) -> Size
encodedSizeExpr forall t. ToCBOR t => Proxy t -> Size
_ = Proxy (VerKeyDSIGN MockDSIGN) -> Size
forall v. DSIGNAlgorithm v => Proxy (VerKeyDSIGN v) -> Size
encodedVerKeyDSIGNSizeExpr

instance FromCBOR (VerKeyDSIGN MockDSIGN) where
  fromCBOR :: Decoder s (VerKeyDSIGN MockDSIGN)
fromCBOR = Decoder s (VerKeyDSIGN MockDSIGN)
forall v s. DSIGNAlgorithm v => Decoder s (VerKeyDSIGN v)
decodeVerKeyDSIGN

instance ToCBOR (SignKeyDSIGN MockDSIGN) where
  toCBOR :: SignKeyDSIGN MockDSIGN -> Encoding
toCBOR = SignKeyDSIGN MockDSIGN -> Encoding
forall v. DSIGNAlgorithm v => SignKeyDSIGN v -> Encoding
encodeSignKeyDSIGN
  encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (SignKeyDSIGN MockDSIGN) -> Size
encodedSizeExpr forall t. ToCBOR t => Proxy t -> Size
_ = Proxy (SignKeyDSIGN MockDSIGN) -> Size
forall v. DSIGNAlgorithm v => Proxy (SignKeyDSIGN v) -> Size
encodedSignKeyDESIGNSizeExpr

instance FromCBOR (SignKeyDSIGN MockDSIGN) where
  fromCBOR :: Decoder s (SignKeyDSIGN MockDSIGN)
fromCBOR = Decoder s (SignKeyDSIGN MockDSIGN)
forall v s. DSIGNAlgorithm v => Decoder s (SignKeyDSIGN v)
decodeSignKeyDSIGN

instance ToCBOR (SigDSIGN MockDSIGN) where
  toCBOR :: SigDSIGN MockDSIGN -> Encoding
toCBOR = SigDSIGN MockDSIGN -> Encoding
forall v. DSIGNAlgorithm v => SigDSIGN v -> Encoding
encodeSigDSIGN
  encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size)
-> Proxy (SigDSIGN MockDSIGN) -> Size
encodedSizeExpr forall t. ToCBOR t => Proxy t -> Size
_ = Proxy (SigDSIGN MockDSIGN) -> Size
forall v. DSIGNAlgorithm v => Proxy (SigDSIGN v) -> Size
encodedSigDSIGNSizeExpr

instance FromCBOR (SigDSIGN MockDSIGN) where
  fromCBOR :: Decoder s (SigDSIGN MockDSIGN)
fromCBOR = Decoder s (SigDSIGN MockDSIGN)
forall v s. DSIGNAlgorithm v => Decoder s (SigDSIGN v)
decodeSigDSIGN


-- | Debugging: provide information about the verification failure
--
-- We don't include the actual value here as that would require propagating a
-- 'Show' constraint.
data VerificationFailure
  = MockVerificationFailure
      { VerificationFailure -> VerKeyDSIGN MockDSIGN
vErrVerKey :: VerKeyDSIGN MockDSIGN
      , VerificationFailure -> SigDSIGN MockDSIGN
vErrSignature :: SigDSIGN MockDSIGN
      , VerificationFailure -> String
vErrCallStack :: String
      }
  deriving Int -> VerificationFailure -> ShowS
[VerificationFailure] -> ShowS
VerificationFailure -> String
(Int -> VerificationFailure -> ShowS)
-> (VerificationFailure -> String)
-> ([VerificationFailure] -> ShowS)
-> Show VerificationFailure
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VerificationFailure] -> ShowS
$cshowList :: [VerificationFailure] -> ShowS
show :: VerificationFailure -> String
$cshow :: VerificationFailure -> String
showsPrec :: Int -> VerificationFailure -> ShowS
$cshowsPrec :: Int -> VerificationFailure -> ShowS
Show

mockSign :: SignableRepresentation a
         => a -> SignKeyDSIGN MockDSIGN -> SigDSIGN MockDSIGN
mockSign :: a -> SignKeyDSIGN MockDSIGN -> SigDSIGN MockDSIGN
mockSign a
a (SignKeyMockDSIGN n) =
  Hash ShortHash () -> Word64 -> SigDSIGN MockDSIGN
SigMockDSIGN (Hash ShortHash a -> Hash ShortHash ()
forall h a b. Hash h a -> Hash h b
castHash ((a -> ByteString) -> a -> Hash ShortHash a
forall h a. HashAlgorithm h => (a -> ByteString) -> a -> Hash h a
hashWith a -> ByteString
forall a. SignableRepresentation a => a -> ByteString
getSignableRepresentation a
a)) Word64
n