{-# LANGUAGE Trustworthy #-}
module Data.ByteString.Short.Base32.Hex
(
encodeBase32
, encodeBase32'
, encodeBase32Unpadded
, encodeBase32Unpadded'
, decodeBase32
, decodeBase32Unpadded
, decodeBase32Padded
, isBase32Hex
, isValidBase32Hex
) where
import qualified Data.ByteString.Base32.Hex as B32H
import Data.ByteString.Short (ShortByteString, fromShort, toShort)
import Data.Text (Text)
import Data.Text.Short (ShortText)
import Data.Text.Short.Unsafe (fromShortByteStringUnsafe)
encodeBase32 :: ShortByteString -> ShortText
encodeBase32 :: ShortByteString -> ShortText
encodeBase32 = ShortByteString -> ShortText
fromShortByteStringUnsafe (ShortByteString -> ShortText)
-> (ShortByteString -> ShortByteString)
-> ShortByteString
-> ShortText
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ShortByteString
encodeBase32'
{-# INLINE encodeBase32 #-}
encodeBase32' :: ShortByteString -> ShortByteString
encodeBase32' :: ShortByteString -> ShortByteString
encodeBase32' = ByteString -> ShortByteString
toShort (ByteString -> ShortByteString)
-> (ShortByteString -> ByteString)
-> ShortByteString
-> ShortByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
B32H.encodeBase32' (ByteString -> ByteString)
-> (ShortByteString -> ByteString) -> ShortByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
fromShort
decodeBase32 :: ShortByteString -> Either Text ShortByteString
decodeBase32 :: ShortByteString -> Either Text ShortByteString
decodeBase32 = (ByteString -> ShortByteString)
-> Either Text ByteString -> Either Text ShortByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> ShortByteString
toShort (Either Text ByteString -> Either Text ShortByteString)
-> (ShortByteString -> Either Text ByteString)
-> ShortByteString
-> Either Text ShortByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either Text ByteString
B32H.decodeBase32 (ByteString -> Either Text ByteString)
-> (ShortByteString -> ByteString)
-> ShortByteString
-> Either Text ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
fromShort
{-# INLINE decodeBase32 #-}
encodeBase32Unpadded :: ShortByteString -> ShortText
encodeBase32Unpadded :: ShortByteString -> ShortText
encodeBase32Unpadded = ShortByteString -> ShortText
fromShortByteStringUnsafe (ShortByteString -> ShortText)
-> (ShortByteString -> ShortByteString)
-> ShortByteString
-> ShortText
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ShortByteString
encodeBase32Unpadded'
{-# INLINE encodeBase32Unpadded #-}
encodeBase32Unpadded' :: ShortByteString -> ShortByteString
encodeBase32Unpadded' :: ShortByteString -> ShortByteString
encodeBase32Unpadded' = ByteString -> ShortByteString
toShort (ByteString -> ShortByteString)
-> (ShortByteString -> ByteString)
-> ShortByteString
-> ShortByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
B32H.encodeBase32Unpadded' (ByteString -> ByteString)
-> (ShortByteString -> ByteString) -> ShortByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
fromShort
decodeBase32Unpadded :: ShortByteString -> Either Text ShortByteString
decodeBase32Unpadded :: ShortByteString -> Either Text ShortByteString
decodeBase32Unpadded = (ByteString -> ShortByteString)
-> Either Text ByteString -> Either Text ShortByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> ShortByteString
toShort (Either Text ByteString -> Either Text ShortByteString)
-> (ShortByteString -> Either Text ByteString)
-> ShortByteString
-> Either Text ShortByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either Text ByteString
B32H.decodeBase32Unpadded (ByteString -> Either Text ByteString)
-> (ShortByteString -> ByteString)
-> ShortByteString
-> Either Text ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
fromShort
{-# INLINE decodeBase32Unpadded #-}
decodeBase32Padded :: ShortByteString -> Either Text ShortByteString
decodeBase32Padded :: ShortByteString -> Either Text ShortByteString
decodeBase32Padded = (ByteString -> ShortByteString)
-> Either Text ByteString -> Either Text ShortByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> ShortByteString
toShort (Either Text ByteString -> Either Text ShortByteString)
-> (ShortByteString -> Either Text ByteString)
-> ShortByteString
-> Either Text ShortByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either Text ByteString
B32H.decodeBase32Padded (ByteString -> Either Text ByteString)
-> (ShortByteString -> ByteString)
-> ShortByteString
-> Either Text ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
fromShort
{-# INLINE decodeBase32Padded #-}
isBase32Hex :: ShortByteString -> Bool
isBase32Hex :: ShortByteString -> Bool
isBase32Hex = ByteString -> Bool
B32H.isBase32Hex (ByteString -> Bool)
-> (ShortByteString -> ByteString) -> ShortByteString -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
fromShort
{-# INLINE isBase32Hex #-}
isValidBase32Hex :: ShortByteString -> Bool
isValidBase32Hex :: ShortByteString -> Bool
isValidBase32Hex = ByteString -> Bool
B32H.isValidBase32Hex (ByteString -> Bool)
-> (ShortByteString -> ByteString) -> ShortByteString -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
fromShort
{-# INLINE isValidBase32Hex #-}