packages feed

mldsa-0.1.0.0: tests/SigExt.hs

-- |
-- Module      : SigExt
-- License     : BSD-3-Clause
-- Copyright   : (c) 2026 Olivier Chéron
--
-- Types that are common to signature-generation and verification test vectors
--
{-# LANGUAGE OverloadedStrings #-}
module SigExt
    ( TestExt(..) , PureExt(..), PreHashExt(..), ExternalMuExt(..)
    , InternalExt(..)
    ) where

import Data.Aeson
import Data.Aeson.Types
import Data.ByteString (ByteString)

import Util

class TestExt ext where
    parseExt :: Object -> Parser ext

data PureExt = PureExt
    { msgEncP :: ByteString
    , ctxEncP :: ByteString
    } deriving Show

instance TestExt PureExt where
    parseExt o = PureExt
        <$> o .:: "message"
        <*> o .:: "context"

data PreHashExt = PreHashExt
    { msgEncPH :: ByteString
    , ctxEncPH :: ByteString
    , hashPH :: String
    } deriving Show

instance TestExt PreHashExt where
    parseExt o = PreHashExt
        <$> o .:: "message"
        <*> o .:: "context"
        <*> o .:  "hashAlg"

newtype ExternalMuExt = ExternalMuExt
    { muEncEM :: ByteString
    } deriving Show

instance TestExt ExternalMuExt where
    parseExt o = ExternalMuExt <$> o .:: "mu"

newtype InternalExt = InternalExt
    { msgEncIM :: ByteString
    } deriving Show

instance TestExt InternalExt where
    parseExt o = InternalExt <$> o .:: "message"