{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE TypeFamilies #-}
module Data.Text.Encoding.Base64.Lens
( AsBase64(..)
, AsBase64Unpadded(..)
) where
import Control.Lens
import Data.Text (Text)
import Data.ByteString.Base64.Lens
import qualified Data.Text.Encoding.Base64 as B64T
import qualified Data.Text.Encoding.Base64.URL as B64TU
instance AsBase64 Text where
type Base64 Text = Text
_Base64 = prism' B64T.encodeBase64 $ \s -> case B64T.decodeBase64 s of
Left _ -> Nothing
Right a -> Just a
{-# INLINE _Base64 #-}
_Base64Url = prism' B64TU.encodeBase64 $ \s -> case B64TU.decodeBase64 s of
Left _ -> Nothing
Right a -> Just a
{-# INLINE _Base64Url #-}
instance AsBase64Unpadded Text where
type Base64Unpadded Text = Text
_Base64Unpadded = prism' B64T.encodeBase64 $ \s -> case B64T.decodeBase64 s of
Left _ -> Nothing
Right a -> Just a
{-# INLINE _Base64Unpadded #-}
_Base64UrlUnpadded = prism' B64TU.encodeBase64 $ \s -> case B64TU.decodeBase64Unpadded s of
Left _ -> Nothing
Right a -> Just a
{-# INLINE _Base64UrlUnpadded #-}