Use Base64 to correctly handle binary ByteStrings

This commit is contained in:
Tissevert 2019-10-17 18:53:11 +02:00
parent 0c2974b055
commit 818c343e89
2 changed files with 5 additions and 3 deletions

View File

@ -23,6 +23,7 @@ library
-- other-extensions:
build-depends: aeson
, base >=4.9 && <4.13
, base64-bytestring
, bytestring
, containers
, hanafuda >= 0.3.3

View File

@ -22,6 +22,7 @@ import Data.Aeson (
)
import Data.Aeson.Types (toJSONKeyText)
import Data.ByteString (ByteString)
import qualified Data.ByteString.Base64 as B64 (decode, encode)
import Data.Map (Map)
import Data.Monoid ((<>))
import Data.Text (Text)
@ -182,10 +183,10 @@ instance ToJSON PublicState where
toEncoding = genericToEncoding defaultOptions
instance FromJSON ByteString where
parseJSON = withText "ByteString" (return . encodeUtf8)
parseJSON = withText "ByteString" (either fail return . B64.decode . encodeUtf8)
instance ToJSON ByteString where
toJSON = String . decodeUtf8
toEncoding = toEncoding . decodeUtf8
toJSON = String . decodeUtf8 . B64.encode
toEncoding = toEncoding . decodeUtf8 . B64.encode
data PublicGame = PublicGame {
nonce :: ByteString