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