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