From 1a10c09d6150dbc9e8a1718b710252cb7b38b776 Mon Sep 17 00:00:00 2001 From: Cypher Date: Tue, 3 May 2022 15:05:40 -0500 Subject: use stack lts-18.8 Update text handling to keep uptodate with changes with string conversion, using 'encodeUtf' and 'decodeUtf' where necessary. One update uses an odd encoding to and from JSON, which must be looked at later. --- src/Ssb/Identity.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/Ssb/Identity.hs') diff --git a/src/Ssb/Identity.hs b/src/Ssb/Identity.hs index e3fa4dc..f599669 100644 --- a/src/Ssb/Identity.hs +++ b/src/Ssb/Identity.hs @@ -9,6 +9,7 @@ import qualified Crypto.Saltine.Class as Nacl import Data.Serialize ( Serialize ) import Data.Either.Combinators ( mapLeft ) +import qualified Data.ByteString as S import qualified Data.Text as T newtype PrivateKey = PrivateKey ByteString @@ -21,13 +22,13 @@ instance Serialize PrivateKey formatPrivateKey :: PrivateKey -> Text formatPrivateKey (PrivateKey buf) = "@" <> pubKey <> ".ed25519" - where pubKey = toS $ Base64.encode buf + where pubKey = decodeUtf8 $ Base64.encode buf parsePrivateKey :: Text -> Either Text PrivateKey parsePrivateKey arg = decode $ T.dropEnd constLen $ T.drop 1 arg where constLen = T.length ".ed25519" - decode = fmap PrivateKey . mapLeft toS . Base64.decode . toS + decode = fmap PrivateKey . mapLeft toS . Base64.decode . encodeUtf8 instance FromJSON PrivateKey where parseJSON = withText "PrivateKey" $ \v -> case parsePrivateKey v of @@ -47,13 +48,13 @@ instance Serialize PublicKey formatPublicKey :: PublicKey -> Text formatPublicKey (PublicKey buf) = "@" <> pubKey <> ".ed25519" - where pubKey = toS $ Base64.encode buf + where pubKey = decodeUtf8 $ Base64.encode buf parsePublicKey :: Text -> Either Text PublicKey parsePublicKey arg = decode $ T.dropEnd constLen $ T.drop 1 arg where constLen = T.length ".ed25519" - decode = fmap PublicKey . mapLeft toS . Base64.decode . toS + decode = fmap PublicKey . mapLeft toS . Base64.decode . encodeUtf8 instance FromJSON PublicKey where parseJSON = withText "PublicKey" $ \v -> case parsePublicKey v of -- cgit v1.2.3