diff options
author | Cypher <cypher@server.ky> | 2022-05-03 15:05:40 -0500 |
---|---|---|
committer | Cypher <cypher@server.ky> | 2022-05-03 15:05:40 -0500 |
commit | 1a10c09d6150dbc9e8a1718b710252cb7b38b776 (patch) | |
tree | 34139f56373ad9e93d267543166c0c3da0f434d0 /src/Ssb/Identity.hs | |
parent | 0732fbc8925efb9753b543d721ea845b9b4f338f (diff) | |
download | ssb-haskell-1a10c09d6150dbc9e8a1718b710252cb7b38b776.tar.xz |
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.
Diffstat (limited to 'src/Ssb/Identity.hs')
-rw-r--r-- | src/Ssb/Identity.hs | 9 |
1 files changed, 5 insertions, 4 deletions
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 |