diff options
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 |