{-# LANGUAGE DataKinds #-}
module Data.ByteString.Short.Base64.URL
(
encodeBase64
, encodeBase64'
, encodeBase64Unpadded
, encodeBase64Unpadded'
, decodeBase64
, decodeBase64Untyped
, decodeBase64Unpadded
, decodeBase64UnpaddedUntyped
, decodeBase64Padded
, decodeBase64PaddedUntyped
, decodeBase64Lenient
, isBase64Url
, isValidBase64Url
) where
import Data.Base64.Types
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 -> Base64 'UrlPadded ShortText
encodeBase64 :: ShortByteString -> Base64 'UrlPadded ShortText
encodeBase64 = (ShortByteString -> ShortText)
-> Base64 'UrlPadded ShortByteString -> Base64 'UrlPadded ShortText
forall a b. (a -> b) -> Base64 'UrlPadded a -> Base64 'UrlPadded b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ShortByteString -> ShortText
fromShortByteStringUnsafe (Base64 'UrlPadded ShortByteString -> Base64 'UrlPadded ShortText)
-> (ShortByteString -> Base64 'UrlPadded ShortByteString)
-> ShortByteString
-> Base64 'UrlPadded ShortText
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> Base64 'UrlPadded ShortByteString
encodeBase64'
{-# INLINE encodeBase64 #-}
encodeBase64' :: ShortByteString -> Base64 'UrlPadded ShortByteString
encodeBase64' :: ShortByteString -> Base64 'UrlPadded ShortByteString
encodeBase64' = (ByteString -> ShortByteString)
-> Base64 'UrlPadded ByteString
-> Base64 'UrlPadded ShortByteString
forall a b. (a -> b) -> Base64 'UrlPadded a -> Base64 'UrlPadded b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> ShortByteString
toShort (Base64 'UrlPadded ByteString -> Base64 'UrlPadded ShortByteString)
-> (ShortByteString -> Base64 'UrlPadded ByteString)
-> ShortByteString
-> Base64 'UrlPadded ShortByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Base64 'UrlPadded ByteString
B64U.encodeBase64' (ByteString -> Base64 'UrlPadded ByteString)
-> (ShortByteString -> ByteString)
-> ShortByteString
-> Base64 'UrlPadded ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
fromShort
decodeBase64
:: UrlAlphabet k
=> Base64 k ShortByteString
-> ShortByteString
decodeBase64 :: forall (k :: Alphabet).
UrlAlphabet k =>
Base64 k ShortByteString -> ShortByteString
decodeBase64 = ByteString -> ShortByteString
toShort (ByteString -> ShortByteString)
-> (Base64 k ShortByteString -> ByteString)
-> Base64 k ShortByteString
-> ShortByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Base64 k ByteString -> ByteString
forall (k :: Alphabet).
UrlAlphabet k =>
Base64 k ByteString -> ByteString
B64U.decodeBase64 (Base64 k ByteString -> ByteString)
-> (Base64 k ShortByteString -> Base64 k ByteString)
-> Base64 k ShortByteString
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ShortByteString -> ByteString)
-> Base64 k ShortByteString -> Base64 k ByteString
forall a b. (a -> b) -> Base64 k a -> Base64 k b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ShortByteString -> ByteString
fromShort
decodeBase64Untyped :: ShortByteString -> Either Text ShortByteString
decodeBase64Untyped :: ShortByteString -> Either Text ShortByteString
decodeBase64Untyped = (ByteString -> ShortByteString)
-> Either Text ByteString -> Either Text ShortByteString
forall a b. (a -> b) -> Either Text a -> Either Text b
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.decodeBase64Untyped (ByteString -> Either Text ByteString)
-> (ShortByteString -> ByteString)
-> ShortByteString
-> Either Text ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
fromShort
{-# inline decodeBase64Untyped #-}
encodeBase64Unpadded :: ShortByteString -> Base64 'UrlUnpadded ShortText
encodeBase64Unpadded :: ShortByteString -> Base64 'UrlUnpadded ShortText
encodeBase64Unpadded = (ShortByteString -> ShortText)
-> Base64 'UrlUnpadded ShortByteString
-> Base64 'UrlUnpadded ShortText
forall a b.
(a -> b) -> Base64 'UrlUnpadded a -> Base64 'UrlUnpadded b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ShortByteString -> ShortText
fromShortByteStringUnsafe (Base64 'UrlUnpadded ShortByteString
-> Base64 'UrlUnpadded ShortText)
-> (ShortByteString -> Base64 'UrlUnpadded ShortByteString)
-> ShortByteString
-> Base64 'UrlUnpadded ShortText
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> Base64 'UrlUnpadded ShortByteString
encodeBase64Unpadded'
{-# INLINE encodeBase64Unpadded #-}
encodeBase64Unpadded' :: ShortByteString -> Base64 'UrlUnpadded ShortByteString
encodeBase64Unpadded' :: ShortByteString -> Base64 'UrlUnpadded ShortByteString
encodeBase64Unpadded' = (ByteString -> ShortByteString)
-> Base64 'UrlUnpadded ByteString
-> Base64 'UrlUnpadded ShortByteString
forall a b.
(a -> b) -> Base64 'UrlUnpadded a -> Base64 'UrlUnpadded b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> ShortByteString
toShort (Base64 'UrlUnpadded ByteString
-> Base64 'UrlUnpadded ShortByteString)
-> (ShortByteString -> Base64 'UrlUnpadded ByteString)
-> ShortByteString
-> Base64 'UrlUnpadded ShortByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Base64 'UrlUnpadded ByteString
B64U.encodeBase64Unpadded' (ByteString -> Base64 'UrlUnpadded ByteString)
-> (ShortByteString -> ByteString)
-> ShortByteString
-> Base64 'UrlUnpadded ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
fromShort
decodeBase64Unpadded :: Base64 'UrlUnpadded ShortByteString -> ShortByteString
decodeBase64Unpadded :: Base64 'UrlUnpadded ShortByteString -> ShortByteString
decodeBase64Unpadded = ByteString -> ShortByteString
toShort (ByteString -> ShortByteString)
-> (Base64 'UrlUnpadded ShortByteString -> ByteString)
-> Base64 'UrlUnpadded ShortByteString
-> ShortByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Base64 'UrlUnpadded ByteString -> ByteString
B64U.decodeBase64Unpadded (Base64 'UrlUnpadded ByteString -> ByteString)
-> (Base64 'UrlUnpadded ShortByteString
-> Base64 'UrlUnpadded ByteString)
-> Base64 'UrlUnpadded ShortByteString
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ShortByteString -> ByteString)
-> Base64 'UrlUnpadded ShortByteString
-> Base64 'UrlUnpadded ByteString
forall a b.
(a -> b) -> Base64 'UrlUnpadded a -> Base64 'UrlUnpadded b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ShortByteString -> ByteString
fromShort
{-# INLINE decodeBase64Unpadded #-}
decodeBase64UnpaddedUntyped :: ShortByteString -> Either Text ShortByteString
decodeBase64UnpaddedUntyped :: ShortByteString -> Either Text ShortByteString
decodeBase64UnpaddedUntyped = (ByteString -> ShortByteString)
-> Either Text ByteString -> Either Text ShortByteString
forall a b. (a -> b) -> Either Text a -> Either Text b
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.decodeBase64UnpaddedUntyped
(ByteString -> Either Text ByteString)
-> (ShortByteString -> ByteString)
-> ShortByteString
-> Either Text ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
fromShort
{-# inline decodeBase64UnpaddedUntyped #-}
decodeBase64Padded :: Base64 'UrlPadded ShortByteString -> ShortByteString
decodeBase64Padded :: Base64 'UrlPadded ShortByteString -> ShortByteString
decodeBase64Padded = ByteString -> ShortByteString
toShort (ByteString -> ShortByteString)
-> (Base64 'UrlPadded ShortByteString -> ByteString)
-> Base64 'UrlPadded ShortByteString
-> ShortByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Base64 'UrlPadded ByteString -> ByteString
B64U.decodeBase64Padded (Base64 'UrlPadded ByteString -> ByteString)
-> (Base64 'UrlPadded ShortByteString
-> Base64 'UrlPadded ByteString)
-> Base64 'UrlPadded ShortByteString
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ShortByteString -> ByteString)
-> Base64 'UrlPadded ShortByteString
-> Base64 'UrlPadded ByteString
forall a b. (a -> b) -> Base64 'UrlPadded a -> Base64 'UrlPadded b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ShortByteString -> ByteString
fromShort
{-# INLINE decodeBase64Padded #-}
decodeBase64PaddedUntyped :: ShortByteString -> Either Text ShortByteString
decodeBase64PaddedUntyped :: ShortByteString -> Either Text ShortByteString
decodeBase64PaddedUntyped = (ByteString -> ShortByteString)
-> Either Text ByteString -> Either Text ShortByteString
forall a b. (a -> b) -> Either Text a -> Either Text b
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.decodeBase64PaddedUntyped
(ByteString -> Either Text ByteString)
-> (ShortByteString -> ByteString)
-> ShortByteString
-> Either Text ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
fromShort
{-# inline decodeBase64PaddedUntyped #-}
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 #-}