{-# LANGUAGE DataKinds #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
module Data.TypedEncoding.Instances.Enc.Base64 where
import Data.TypedEncoding
import Data.TypedEncoding.Instances.Support
import Data.TypedEncoding.Instances.Support.Unsafe
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
import qualified Data.ByteString.Base64 as B64
import qualified Data.ByteString.Base64.Lazy as BL64
import Data.TypedEncoding.Instances.Restriction.Base64 ()
acceptLenientS :: Enc ("enc-B64-len" ': ys) c B.ByteString -> Enc ("enc-B64" ': ys) c B.ByteString
acceptLenientS :: Enc @[Symbol] ((':) @Symbol "enc-B64-len" ys) c ByteString
-> Enc @[Symbol] ((':) @Symbol "enc-B64" ys) c ByteString
acceptLenientS = (ByteString -> ByteString)
-> Enc @[Symbol] ((':) @Symbol "enc-B64-len" ys) c ByteString
-> Enc @[Symbol] ((':) @Symbol "enc-B64" ys) c ByteString
forall k1 k2 s1 s2 (e1 :: k1) c (e2 :: k2).
(s1 -> s2) -> Enc @k1 e1 c s1 -> Enc @k2 e2 c s2
withUnsafeCoerce (ByteString -> ByteString
B64.encode (ByteString -> ByteString)
-> (ByteString -> ByteString) -> ByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
B64.decodeLenient)
acceptLenientL :: Enc ("enc-B64-len" ': ys) c BL.ByteString -> Enc ("enc-B64" ': ys) c BL.ByteString
acceptLenientL :: Enc @[Symbol] ((':) @Symbol "enc-B64-len" ys) c ByteString
-> Enc @[Symbol] ((':) @Symbol "enc-B64" ys) c ByteString
acceptLenientL = (ByteString -> ByteString)
-> Enc @[Symbol] ((':) @Symbol "enc-B64-len" ys) c ByteString
-> Enc @[Symbol] ((':) @Symbol "enc-B64" ys) c ByteString
forall k1 k2 s1 s2 (e1 :: k1) c (e2 :: k2).
(s1 -> s2) -> Enc @k1 e1 c s1 -> Enc @k2 e2 c s2
withUnsafeCoerce (ByteString -> ByteString
BL64.encode (ByteString -> ByteString)
-> (ByteString -> ByteString) -> ByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
BL64.decodeLenient)
asEncodingB :: Enc '["r-B64"] c B.ByteString -> Enc '["enc-B64"] c B.ByteString
asEncodingB :: Enc @[Symbol] ((':) @Symbol "r-B64" ('[] @Symbol)) c ByteString
-> Enc
@[Symbol] ((':) @Symbol "enc-B64" ('[] @Symbol)) c ByteString
asEncodingB = (ByteString -> ByteString)
-> Enc @[Symbol] ((':) @Symbol "r-B64" ('[] @Symbol)) c ByteString
-> Enc
@[Symbol] ((':) @Symbol "enc-B64" ('[] @Symbol)) c ByteString
forall k1 k2 s1 s2 (e1 :: k1) c (e2 :: k2).
(s1 -> s2) -> Enc @k1 e1 c s1 -> Enc @k2 e2 c s2
withUnsafeCoerce ByteString -> ByteString
forall a. a -> a
id
asEncodingBL :: Enc '["r-B64"] c BL.ByteString -> Enc '["enc-B64"] c BL.ByteString
asEncodingBL :: Enc @[Symbol] ((':) @Symbol "r-B64" ('[] @Symbol)) c ByteString
-> Enc
@[Symbol] ((':) @Symbol "enc-B64" ('[] @Symbol)) c ByteString
asEncodingBL = (ByteString -> ByteString)
-> Enc @[Symbol] ((':) @Symbol "r-B64" ('[] @Symbol)) c ByteString
-> Enc
@[Symbol] ((':) @Symbol "enc-B64" ('[] @Symbol)) c ByteString
forall k1 k2 s1 s2 (e1 :: k1) c (e2 :: k2).
(s1 -> s2) -> Enc @k1 e1 c s1 -> Enc @k2 e2 c s2
withUnsafeCoerce ByteString -> ByteString
forall a. a -> a
id
instance FlattenAs "r-ASCII" "enc-B64-nontext" where
instance FlattenAs "r-ASCII" "enc-B64" where
instance FlattenAs "r-B64" "enc-B64" where
instance EncodingSuperset "enc-B64" where
type EncSuperset "enc-B64" = "r-B64"
instance EncodingSuperset "enc-B64-len" where
type EncSuperset "enc-B64-len" = "r-B64"
instance Applicative f => Encode f "enc-B64" "enc-B64" c B.ByteString where
encoding :: Encoding f "enc-B64" "enc-B64" c ByteString
encoding = Encoding f "enc-B64" "enc-B64" c ByteString
forall (f :: * -> *) c.
Applicative f =>
Encoding f "enc-B64" "enc-B64" c ByteString
encB64B
encB64B :: Applicative f => Encoding f "enc-B64" "enc-B64" c B.ByteString
encB64B :: Encoding f "enc-B64" "enc-B64" c ByteString
encB64B = (ByteString -> ByteString)
-> Encoding f "enc-B64" (AlgNm "enc-B64") c ByteString
forall (nm :: Symbol) (f :: * -> *) c str.
Applicative f =>
(str -> str) -> Encoding f nm (AlgNm nm) c str
_implEncodingP ByteString -> ByteString
B64.encode
instance Applicative f => Encode f "enc-B64" "enc-B64" c BL.ByteString where
encoding :: Encoding f "enc-B64" "enc-B64" c ByteString
encoding = Encoding f "enc-B64" "enc-B64" c ByteString
forall (f :: * -> *) c.
Applicative f =>
Encoding f "enc-B64" "enc-B64" c ByteString
encB64BL
encB64BL :: Applicative f => Encoding f "enc-B64" "enc-B64" c BL.ByteString
encB64BL :: Encoding f "enc-B64" "enc-B64" c ByteString
encB64BL = (ByteString -> ByteString)
-> Encoding f "enc-B64" (AlgNm "enc-B64") c ByteString
forall (nm :: Symbol) (f :: * -> *) c str.
Applicative f =>
(str -> str) -> Encoding f nm (AlgNm nm) c str
_implEncodingP ByteString -> ByteString
BL64.encode
instance (UnexpectedDecodeErr f, Applicative f) => Decode f "enc-B64" "enc-B64" c B.ByteString where
decoding :: Decoding f "enc-B64" "enc-B64" c ByteString
decoding = Decoding f "enc-B64" "enc-B64" c ByteString
forall (f :: * -> *) c.
(UnexpectedDecodeErr @* f, Applicative f) =>
Decoding f "enc-B64" "enc-B64" c ByteString
decB64B
decB64B :: (UnexpectedDecodeErr f, Applicative f) => Decoding f "enc-B64" "enc-B64" c B.ByteString
decB64B :: Decoding f "enc-B64" "enc-B64" c ByteString
decB64B = (ByteString -> f ByteString)
-> Decoding f "enc-B64" (AlgNm "enc-B64") c ByteString
forall (nm :: Symbol) (f :: * -> *) c str.
Functor f =>
(str -> f str) -> Decoding f nm (AlgNm nm) c str
_implDecodingF (forall (x :: Symbol) (f :: * -> *) err a.
(KnownSymbol x, UnexpectedDecodeErr @* f, Applicative f,
Show err) =>
Either err a -> f a
forall (f :: * -> *) err a.
(KnownSymbol "enc-B64", UnexpectedDecodeErr @* f, Applicative f,
Show err) =>
Either err a -> f a
asUnexpected @"enc-B64" (Either String ByteString -> f ByteString)
-> (ByteString -> Either String ByteString)
-> ByteString
-> f ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either String ByteString
B64.decode)
instance (UnexpectedDecodeErr f, Applicative f) => Decode f "enc-B64" "enc-B64" c BL.ByteString where
decoding :: Decoding f "enc-B64" "enc-B64" c ByteString
decoding = Decoding f "enc-B64" "enc-B64" c ByteString
forall (f :: * -> *) c.
(UnexpectedDecodeErr @* f, Applicative f) =>
Decoding f "enc-B64" "enc-B64" c ByteString
decB64BL
decB64BL :: (UnexpectedDecodeErr f, Applicative f) => Decoding f "enc-B64" "enc-B64" c BL.ByteString
decB64BL :: Decoding f "enc-B64" "enc-B64" c ByteString
decB64BL = (ByteString -> f ByteString)
-> Decoding f "enc-B64" (AlgNm "enc-B64") c ByteString
forall (nm :: Symbol) (f :: * -> *) c str.
Functor f =>
(str -> f str) -> Decoding f nm (AlgNm nm) c str
_implDecodingF (forall (x :: Symbol) (f :: * -> *) err a.
(KnownSymbol x, UnexpectedDecodeErr @* f, Applicative f,
Show err) =>
Either err a -> f a
forall (f :: * -> *) err a.
(KnownSymbol "enc-B64", UnexpectedDecodeErr @* f, Applicative f,
Show err) =>
Either err a -> f a
asUnexpected @"enc-B64" (Either String ByteString -> f ByteString)
-> (ByteString -> Either String ByteString)
-> ByteString
-> f ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either String ByteString
BL64.decode)
instance (RecreateErr f, Applicative f) => Validate f "enc-B64" "enc-B64" c B.ByteString where
validation :: Validation f "enc-B64" "enc-B64" c ByteString
validation = Decoding
(Either UnexpectedDecodeEx) "enc-B64" "enc-B64" c ByteString
-> Validation f "enc-B64" "enc-B64" c ByteString
forall (nm :: Symbol) (f :: * -> *) c str.
(KnownSymbol nm, RecreateErr @* f, Applicative f) =>
Decoding (Either UnexpectedDecodeEx) nm nm c str
-> Validation f nm nm c str
validFromDec Decoding
(Either UnexpectedDecodeEx) "enc-B64" "enc-B64" c ByteString
forall (f :: * -> *) c.
(UnexpectedDecodeErr @* f, Applicative f) =>
Decoding f "enc-B64" "enc-B64" c ByteString
decB64B
instance (RecreateErr f, Applicative f) => Validate f "enc-B64" "enc-B64" c BL.ByteString where
validation :: Validation f "enc-B64" "enc-B64" c ByteString
validation = Decoding
(Either UnexpectedDecodeEx) "enc-B64" "enc-B64" c ByteString
-> Validation f "enc-B64" "enc-B64" c ByteString
forall (nm :: Symbol) (f :: * -> *) c str.
(KnownSymbol nm, RecreateErr @* f, Applicative f) =>
Decoding (Either UnexpectedDecodeEx) nm nm c str
-> Validation f nm nm c str
validFromDec Decoding
(Either UnexpectedDecodeEx) "enc-B64" "enc-B64" c ByteString
forall (f :: * -> *) c.
(UnexpectedDecodeErr @* f, Applicative f) =>
Decoding f "enc-B64" "enc-B64" c ByteString
decB64BL
instance Applicative f => Validate f "enc-B64-len" "enc-B64-len" c B.ByteString where
validation :: Validation f "enc-B64-len" "enc-B64-len" c ByteString
validation = (forall (xs :: [Symbol]).
Enc @[Symbol] ((':) @Symbol "enc-B64-len" xs) c ByteString
-> f (Enc @[Symbol] xs c ByteString))
-> Validation f "enc-B64-len" (AlgNm "enc-B64-len") c ByteString
forall (f :: * -> *) (nm :: Symbol) conf str.
(forall (xs :: [Symbol]).
Enc @[Symbol] ((':) @Symbol nm xs) conf str
-> f (Enc @[Symbol] xs conf str))
-> Validation f nm (AlgNm nm) conf str
_mkValidation ((forall (xs :: [Symbol]).
Enc @[Symbol] ((':) @Symbol "enc-B64-len" xs) c ByteString
-> f (Enc @[Symbol] xs c ByteString))
-> Validation f "enc-B64-len" (AlgNm "enc-B64-len") c ByteString)
-> (forall (xs :: [Symbol]).
Enc @[Symbol] ((':) @Symbol "enc-B64-len" xs) c ByteString
-> f (Enc @[Symbol] xs c ByteString))
-> Validation f "enc-B64-len" (AlgNm "enc-B64-len") c ByteString
forall a b. (a -> b) -> a -> b
$ (ByteString -> ByteString)
-> Enc @[Symbol] ((':) @Symbol "enc-B64-len" xs) c ByteString
-> f (Enc @[Symbol] xs c ByteString)
forall k1 k2 (f :: * -> *) str (enc1 :: k1) conf (enc2 :: k2).
Applicative f =>
(str -> str) -> Enc @k1 enc1 conf str -> f (Enc @k2 enc2 conf str)
implTranP ByteString -> ByteString
forall a. a -> a
id
instance Applicative f => Validate f "enc-B64-len" "enc-B64-len" c BL.ByteString where
validation :: Validation f "enc-B64-len" "enc-B64-len" c ByteString
validation = (forall (xs :: [Symbol]).
Enc @[Symbol] ((':) @Symbol "enc-B64-len" xs) c ByteString
-> f (Enc @[Symbol] xs c ByteString))
-> Validation f "enc-B64-len" (AlgNm "enc-B64-len") c ByteString
forall (f :: * -> *) (nm :: Symbol) conf str.
(forall (xs :: [Symbol]).
Enc @[Symbol] ((':) @Symbol nm xs) conf str
-> f (Enc @[Symbol] xs conf str))
-> Validation f nm (AlgNm nm) conf str
_mkValidation ((forall (xs :: [Symbol]).
Enc @[Symbol] ((':) @Symbol "enc-B64-len" xs) c ByteString
-> f (Enc @[Symbol] xs c ByteString))
-> Validation f "enc-B64-len" (AlgNm "enc-B64-len") c ByteString)
-> (forall (xs :: [Symbol]).
Enc @[Symbol] ((':) @Symbol "enc-B64-len" xs) c ByteString
-> f (Enc @[Symbol] xs c ByteString))
-> Validation f "enc-B64-len" (AlgNm "enc-B64-len") c ByteString
forall a b. (a -> b) -> a -> b
$ (ByteString -> ByteString)
-> Enc @[Symbol] ((':) @Symbol "enc-B64-len" xs) c ByteString
-> f (Enc @[Symbol] xs c ByteString)
forall k1 k2 (f :: * -> *) str (enc1 :: k1) conf (enc2 :: k2).
Applicative f =>
(str -> str) -> Enc @k1 enc1 conf str -> f (Enc @k2 enc2 conf str)
implTranP ByteString -> ByteString
forall a. a -> a
id