{-# LANGUAGE OverloadedStrings, FlexibleContexts, CPP #-}
{-# OPTIONS_HADDOCK hide #-}
module Jose.Internal.Base64 where
#if MIN_VERSION_mtl(2,2,1)
import Control.Monad.Except
#else
import Control.Monad.Error
#endif
import Data.ByteArray
import Data.ByteArray.Encoding
import Jose.Types
encode :: (ByteArrayAccess input, ByteArray output) => input -> output
encode :: forall input output.
(ByteArrayAccess input, ByteArray output) =>
input -> output
encode = Base -> input -> output
forall bin bout.
(ByteArrayAccess bin, ByteArray bout) =>
Base -> bin -> bout
convertToBase Base
Base64URLUnpadded
decode :: (ByteArrayAccess input, ByteArray output, MonadError JwtError m) => input -> m output
decode :: forall input output (m :: * -> *).
(ByteArrayAccess input, ByteArray output, MonadError JwtError m) =>
input -> m output
decode input
bs = (String -> m output)
-> (output -> m output) -> Either String output -> m output
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (JwtError -> m output
forall a. JwtError -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (JwtError -> m output)
-> (String -> JwtError) -> String -> m output
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> JwtError
Base64Error) output -> m output
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Either String output -> m output)
-> Either String output -> m output
forall a b. (a -> b) -> a -> b
$ Base -> input -> Either String output
forall bin bout.
(ByteArrayAccess bin, ByteArray bout) =>
Base -> bin -> Either String bout
convertFromBase Base
Base64URLUnpadded input
bs