Wycheproof.hs (1287B)
1 {-# LANGUAGE OverloadedStrings #-} 2 3 module Wycheproof ( 4 Wycheproof(..) 5 , MacTestGroup(..) 6 , MacTest(..) 7 ) where 8 9 import Data.Aeson ((.:)) 10 import qualified Data.Aeson as A 11 import qualified Data.Text as T 12 13 data Wycheproof = Wycheproof { 14 wp_numberOfTests :: !Int 15 , wp_testGroups :: ![MacTestGroup] 16 } deriving Show 17 18 instance A.FromJSON Wycheproof where 19 parseJSON = A.withObject "Wycheproof" $ \m -> Wycheproof 20 <$> m .: "numberOfTests" 21 <*> m .: "testGroups" 22 23 data MacTestGroup = MacTestGroup { 24 mtg_keySize :: !Int 25 , mtg_tagSize :: !Int 26 , mtg_type :: !T.Text 27 , mtg_tests :: ![MacTest] 28 } deriving Show 29 30 instance A.FromJSON MacTestGroup where 31 parseJSON = A.withObject "MacTestGroup" $ \m -> MacTestGroup 32 <$> m .: "keySize" 33 <*> m .: "tagSize" 34 <*> m .: "type" 35 <*> m .: "tests" 36 37 data MacTest = MacTest { 38 mt_tcId :: !Int 39 , mt_comment :: !T.Text 40 , mt_key :: !T.Text 41 , mt_msg :: !T.Text 42 , mt_tag :: !T.Text 43 , mt_result :: !T.Text 44 , mt_flags :: ![T.Text] 45 } deriving Show 46 47 instance A.FromJSON MacTest where 48 parseJSON = A.withObject "MacTest" $ \m -> MacTest 49 <$> m .: "tcId" 50 <*> m .: "comment" 51 <*> m .: "key" 52 <*> m .: "msg" 53 <*> m .: "tag" 54 <*> m .: "result" 55 <*> m .: "flags" 56