{-# LANGUAGE CPP #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}
#if MIN_VERSION_lens(5,0,0)
{-# LANGUAGE Safe #-}
#else
{-# LANGUAGE Trustworthy #-}
#endif
module Data.ByteString.Short.Base64.Lens
(
_Base64
, _Base64Url
, _Base64UrlUnpadded
, _Base64Lenient
, _Base64UrlLenient
, pattern Base64
, pattern Base64Url
, pattern Base64UrlUnpadded
, pattern Base64Lenient
, pattern Base64UrlLenient
) where
import Control.Lens
import Data.ByteString.Short (ShortByteString)
import qualified Data.ByteString.Short.Base64 as BS64
import qualified Data.ByteString.Short.Base64.URL as BS64U
_Base64 :: Prism' ShortByteString ShortByteString
_Base64 :: p ShortByteString (f ShortByteString)
-> p ShortByteString (f ShortByteString)
_Base64 = (ShortByteString -> ShortByteString)
-> (ShortByteString -> Maybe ShortByteString)
-> Prism
ShortByteString ShortByteString ShortByteString ShortByteString
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ShortByteString -> ShortByteString
BS64.encodeBase64' ((ShortByteString -> Maybe ShortByteString)
-> Prism
ShortByteString ShortByteString ShortByteString ShortByteString)
-> (ShortByteString -> Maybe ShortByteString)
-> Prism
ShortByteString ShortByteString ShortByteString ShortByteString
forall a b. (a -> b) -> a -> b
$ \ShortByteString
s -> case ShortByteString -> Either Text ShortByteString
BS64.decodeBase64 ShortByteString
s of
Left Text
_ -> Maybe ShortByteString
forall a. Maybe a
Nothing
Right ShortByteString
a -> ShortByteString -> Maybe ShortByteString
forall a. a -> Maybe a
Just ShortByteString
a
{-# INLINE _Base64 #-}
_Base64Url :: Prism' ShortByteString ShortByteString
_Base64Url :: p ShortByteString (f ShortByteString)
-> p ShortByteString (f ShortByteString)
_Base64Url = (ShortByteString -> ShortByteString)
-> (ShortByteString -> Maybe ShortByteString)
-> Prism
ShortByteString ShortByteString ShortByteString ShortByteString
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ShortByteString -> ShortByteString
BS64U.encodeBase64' ((ShortByteString -> Maybe ShortByteString)
-> Prism
ShortByteString ShortByteString ShortByteString ShortByteString)
-> (ShortByteString -> Maybe ShortByteString)
-> Prism
ShortByteString ShortByteString ShortByteString ShortByteString
forall a b. (a -> b) -> a -> b
$ \ShortByteString
s -> case ShortByteString -> Either Text ShortByteString
BS64U.decodeBase64 ShortByteString
s of
Left Text
_ -> Maybe ShortByteString
forall a. Maybe a
Nothing
Right ShortByteString
a -> ShortByteString -> Maybe ShortByteString
forall a. a -> Maybe a
Just ShortByteString
a
{-# INLINE _Base64Url #-}
_Base64UrlUnpadded :: Prism' ShortByteString ShortByteString
_Base64UrlUnpadded :: p ShortByteString (f ShortByteString)
-> p ShortByteString (f ShortByteString)
_Base64UrlUnpadded = (ShortByteString -> ShortByteString)
-> (ShortByteString -> Maybe ShortByteString)
-> Prism
ShortByteString ShortByteString ShortByteString ShortByteString
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ShortByteString -> ShortByteString
BS64U.encodeBase64Unpadded' ((ShortByteString -> Maybe ShortByteString)
-> Prism
ShortByteString ShortByteString ShortByteString ShortByteString)
-> (ShortByteString -> Maybe ShortByteString)
-> Prism
ShortByteString ShortByteString ShortByteString ShortByteString
forall a b. (a -> b) -> a -> b
$ \ShortByteString
s -> case ShortByteString -> Either Text ShortByteString
BS64U.decodeBase64Unpadded ShortByteString
s of
Left Text
_ -> Maybe ShortByteString
forall a. Maybe a
Nothing
Right ShortByteString
a -> ShortByteString -> Maybe ShortByteString
forall a. a -> Maybe a
Just ShortByteString
a
{-# INLINE _Base64UrlUnpadded #-}
_Base64Lenient :: Iso' ShortByteString ShortByteString
_Base64Lenient :: p ShortByteString (f ShortByteString)
-> p ShortByteString (f ShortByteString)
_Base64Lenient = (ShortByteString -> ShortByteString)
-> (ShortByteString -> ShortByteString)
-> Iso
ShortByteString ShortByteString ShortByteString ShortByteString
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso ShortByteString -> ShortByteString
BS64.decodeBase64Lenient ShortByteString -> ShortByteString
BS64.encodeBase64'
_Base64UrlLenient :: Iso' ShortByteString ShortByteString
_Base64UrlLenient :: p ShortByteString (f ShortByteString)
-> p ShortByteString (f ShortByteString)
_Base64UrlLenient = (ShortByteString -> ShortByteString)
-> (ShortByteString -> ShortByteString)
-> Iso
ShortByteString ShortByteString ShortByteString ShortByteString
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso ShortByteString -> ShortByteString
BS64U.decodeBase64Lenient ShortByteString -> ShortByteString
BS64U.encodeBase64'
pattern Base64 :: ShortByteString -> ShortByteString
pattern $bBase64 :: ShortByteString -> ShortByteString
$mBase64 :: forall r.
ShortByteString -> (ShortByteString -> r) -> (Void# -> r) -> r
Base64 a <- (preview _Base64 -> Just a) where
Base64 ShortByteString
a = Tagged ShortByteString (Identity ShortByteString)
-> Tagged ShortByteString (Identity ShortByteString)
Prism
ShortByteString ShortByteString ShortByteString ShortByteString
_Base64 (Tagged ShortByteString (Identity ShortByteString)
-> Tagged ShortByteString (Identity ShortByteString))
-> ShortByteString -> ShortByteString
forall t b. AReview t b -> b -> t
# ShortByteString
a
pattern Base64Url :: ShortByteString -> ShortByteString
pattern $bBase64Url :: ShortByteString -> ShortByteString
$mBase64Url :: forall r.
ShortByteString -> (ShortByteString -> r) -> (Void# -> r) -> r
Base64Url a <- (preview _Base64Url -> Just a) where
Base64Url ShortByteString
a = Tagged ShortByteString (Identity ShortByteString)
-> Tagged ShortByteString (Identity ShortByteString)
Prism
ShortByteString ShortByteString ShortByteString ShortByteString
_Base64Url (Tagged ShortByteString (Identity ShortByteString)
-> Tagged ShortByteString (Identity ShortByteString))
-> ShortByteString -> ShortByteString
forall t b. AReview t b -> b -> t
# ShortByteString
a
pattern Base64UrlUnpadded :: ShortByteString -> ShortByteString
pattern $bBase64UrlUnpadded :: ShortByteString -> ShortByteString
$mBase64UrlUnpadded :: forall r.
ShortByteString -> (ShortByteString -> r) -> (Void# -> r) -> r
Base64UrlUnpadded a <- (preview _Base64UrlUnpadded -> Just a) where
Base64UrlUnpadded ShortByteString
a = Tagged ShortByteString (Identity ShortByteString)
-> Tagged ShortByteString (Identity ShortByteString)
Prism
ShortByteString ShortByteString ShortByteString ShortByteString
_Base64UrlUnpadded (Tagged ShortByteString (Identity ShortByteString)
-> Tagged ShortByteString (Identity ShortByteString))
-> ShortByteString -> ShortByteString
forall t b. AReview t b -> b -> t
# ShortByteString
a
pattern Base64Lenient :: ShortByteString -> ShortByteString
pattern $bBase64Lenient :: ShortByteString -> ShortByteString
$mBase64Lenient :: forall r.
ShortByteString -> (ShortByteString -> r) -> (Void# -> r) -> r
Base64Lenient a <- (view (from _Base64Lenient) -> a) where
Base64Lenient ShortByteString
a = Getting ShortByteString ShortByteString ShortByteString
-> ShortByteString -> ShortByteString
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting ShortByteString ShortByteString ShortByteString
Iso ShortByteString ShortByteString ShortByteString ShortByteString
_Base64Lenient ShortByteString
a
{-# COMPLETE Base64Lenient #-}
pattern Base64UrlLenient :: ShortByteString -> ShortByteString
pattern $bBase64UrlLenient :: ShortByteString -> ShortByteString
$mBase64UrlLenient :: forall r.
ShortByteString -> (ShortByteString -> r) -> (Void# -> r) -> r
Base64UrlLenient a <- (view (from _Base64UrlLenient) -> a) where
Base64UrlLenient ShortByteString
a = Getting ShortByteString ShortByteString ShortByteString
-> ShortByteString -> ShortByteString
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting ShortByteString ShortByteString ShortByteString
Iso ShortByteString ShortByteString ShortByteString ShortByteString
_Base64UrlLenient ShortByteString
a
{-# COMPLETE Base64UrlLenient #-}