{-# LANGUAGE Trustworthy #-}
module Data.ByteString.Short.Base64.URL
(
encodeBase64
, encodeBase64'
, encodeBase64Unpadded
, encodeBase64Unpadded'
, decodeBase64
, decodeBase64Unpadded
, decodeBase64Padded
, decodeBase64Lenient
, isBase64Url
, isValidBase64Url
) where
import qualified Data.ByteString.Base64.URL as B64U
import Data.ByteString.Short (ShortByteString, fromShort, toShort)
import Data.Text (Text)
import Data.Text.Short (ShortText)
import Data.Text.Short.Unsafe (fromShortByteStringUnsafe)
encodeBase64 :: ShortByteString -> ShortText
encodeBase64 :: ShortByteString -> ShortText
encodeBase64 = ShortByteString -> ShortText
fromShortByteStringUnsafe (ShortByteString -> ShortText)
-> (ShortByteString -> ShortByteString)
-> ShortByteString
-> ShortText
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ShortByteString
encodeBase64'
{-# INLINE encodeBase64 #-}
encodeBase64' :: ShortByteString -> ShortByteString
encodeBase64' :: ShortByteString -> ShortByteString
encodeBase64' = ByteString -> ShortByteString
toShort (ByteString -> ShortByteString)
-> (ShortByteString -> ByteString)
-> ShortByteString
-> ShortByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
B64U.encodeBase64' (ByteString -> ByteString)
-> (ShortByteString -> ByteString) -> ShortByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
fromShort
decodeBase64 :: ShortByteString -> Either Text ShortByteString
decodeBase64 :: ShortByteString -> Either Text ShortByteString
decodeBase64 = (ByteString -> ShortByteString)
-> Either Text ByteString -> Either Text ShortByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> ShortByteString
toShort (Either Text ByteString -> Either Text ShortByteString)
-> (ShortByteString -> Either Text ByteString)
-> ShortByteString
-> Either Text ShortByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either Text ByteString
B64U.decodeBase64 (ByteString -> Either Text ByteString)
-> (ShortByteString -> ByteString)
-> ShortByteString
-> Either Text ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
fromShort
{-# INLINE decodeBase64 #-}
encodeBase64Unpadded :: ShortByteString -> ShortText
encodeBase64Unpadded :: ShortByteString -> ShortText
encodeBase64Unpadded = ShortByteString -> ShortText
fromShortByteStringUnsafe (ShortByteString -> ShortText)
-> (ShortByteString -> ShortByteString)
-> ShortByteString
-> ShortText
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ShortByteString
encodeBase64Unpadded'
{-# INLINE encodeBase64Unpadded #-}
encodeBase64Unpadded' :: ShortByteString -> ShortByteString
encodeBase64Unpadded' :: ShortByteString -> ShortByteString
encodeBase64Unpadded' = ByteString -> ShortByteString
toShort (ByteString -> ShortByteString)
-> (ShortByteString -> ByteString)
-> ShortByteString
-> ShortByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
B64U.encodeBase64Unpadded' (ByteString -> ByteString)
-> (ShortByteString -> ByteString) -> ShortByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
fromShort
decodeBase64Unpadded :: ShortByteString -> Either Text ShortByteString
decodeBase64Unpadded :: ShortByteString -> Either Text ShortByteString
decodeBase64Unpadded = (ByteString -> ShortByteString)
-> Either Text ByteString -> Either Text ShortByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> ShortByteString
toShort (Either Text ByteString -> Either Text ShortByteString)
-> (ShortByteString -> Either Text ByteString)
-> ShortByteString
-> Either Text ShortByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either Text ByteString
B64U.decodeBase64Unpadded (ByteString -> Either Text ByteString)
-> (ShortByteString -> ByteString)
-> ShortByteString
-> Either Text ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
fromShort
{-# INLINE decodeBase64Unpadded #-}
decodeBase64Padded :: ShortByteString -> Either Text ShortByteString
decodeBase64Padded :: ShortByteString -> Either Text ShortByteString
decodeBase64Padded = (ByteString -> ShortByteString)
-> Either Text ByteString -> Either Text ShortByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> ShortByteString
toShort (Either Text ByteString -> Either Text ShortByteString)
-> (ShortByteString -> Either Text ByteString)
-> ShortByteString
-> Either Text ShortByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either Text ByteString
B64U.decodeBase64Padded (ByteString -> Either Text ByteString)
-> (ShortByteString -> ByteString)
-> ShortByteString
-> Either Text ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
fromShort
{-# INLINE decodeBase64Padded #-}
decodeBase64Lenient :: ShortByteString -> ShortByteString
decodeBase64Lenient :: ShortByteString -> ShortByteString
decodeBase64Lenient = ByteString -> ShortByteString
toShort (ByteString -> ShortByteString)
-> (ShortByteString -> ByteString)
-> ShortByteString
-> ShortByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
B64U.decodeBase64Lenient (ByteString -> ByteString)
-> (ShortByteString -> ByteString) -> ShortByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
fromShort
{-# INLINE decodeBase64Lenient #-}
isBase64Url :: ShortByteString -> Bool
isBase64Url :: ShortByteString -> Bool
isBase64Url = ByteString -> Bool
B64U.isBase64Url (ByteString -> Bool)
-> (ShortByteString -> ByteString) -> ShortByteString -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
fromShort
{-# INLINE isBase64Url #-}
isValidBase64Url :: ShortByteString -> Bool
isValidBase64Url :: ShortByteString -> Bool
isValidBase64Url = ByteString -> Bool
B64U.isValidBase64Url (ByteString -> Bool)
-> (ShortByteString -> ByteString) -> ShortByteString -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
fromShort
{-# INLINE isValidBase64Url #-}