{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}

{- FOURMOLU_DISABLE -}
module Test.Crypto.Regressions (
  tests
  ) where

import Test.Tasty.HUnit (testCase, assertEqual)
import Test.Tasty (TestTree, testGroup)
import Cardano.Crypto.DSIGN (rawDeserialiseVerKeyDSIGN)
import Cardano.Crypto.DSIGN.Ed25519 (Ed25519DSIGN)
import qualified Data.ByteString as BS
#ifdef SECP256K1_ENABLED
import Cardano.Crypto.DSIGN.SchnorrSecp256k1 (SchnorrSecp256k1DSIGN)
#endif

tests :: TestTree
tests :: TestTree
tests = TestName -> [TestTree] -> TestTree
testGroup TestName
"Regressions" [
  TestName -> [TestTree] -> TestTree
testGroup TestName
"DSIGN" [
#ifdef SECP256K1_ENABLED
    TestName -> [TestTree] -> TestTree
testGroup TestName
"Schnorr serialization" [
        TestName -> Assertion -> TestTree
testCase TestName
"Schnorr verkey deserialization fails on \"m\" literal" forall a b. (a -> b) -> a -> b
$ do
          let actual :: Maybe (VerKeyDSIGN SchnorrSecp256k1DSIGN)
actual = forall v. DSIGNAlgorithm v => ByteString -> Maybe (VerKeyDSIGN v)
rawDeserialiseVerKeyDSIGN @SchnorrSecp256k1DSIGN ByteString
"m"
          forall a.
(Eq a, Show a, HasCallStack) =>
TestName -> a -> a -> Assertion
assertEqual TestName
"" forall a. Maybe a
Nothing Maybe (VerKeyDSIGN SchnorrSecp256k1DSIGN)
actual
      ],
#endif
    TestName -> [TestTree] -> TestTree
testGroup TestName
"Ed25519 serialization" [
      TestName -> Assertion -> TestTree
testCase TestName
"Ed25519 sign key deserialization fails on 33 NUL bytes" forall a b. (a -> b) -> a -> b
$ do
        let actual :: Maybe (VerKeyDSIGN Ed25519DSIGN)
actual = forall v. DSIGNAlgorithm v => ByteString -> Maybe (VerKeyDSIGN v)
rawDeserialiseVerKeyDSIGN @Ed25519DSIGN forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Word8 -> ByteString
BS.replicate Int
33 forall a b. (a -> b) -> a -> b
$ Word8
0
        forall a.
(Eq a, Show a, HasCallStack) =>
TestName -> a -> a -> Assertion
assertEqual TestName
"" forall a. Maybe a
Nothing Maybe (VerKeyDSIGN Ed25519DSIGN)
actual
      ]
    ]
  ]