{-# LANGUAGE Safe #-} ----------------------------------------------------------------------------- -- | -- Module : Passman.Core.Internal.BFEncoding -- Copyright : Matthew Harm Bekkema 2016 -- License : GPL-2 -- Maintainer : mbekkema97@gmail.com -- Stability : experimental -- Portability : POSIX ----------------------------------------------------------------------------- module Passman.Core.Internal.BFEncoding ( decode , encode , toB64 , fromB64 ) where import qualified Data.ByteString as BS import qualified Data.ByteString.Base64 as B64 import Data.Word toB64 :: Word8 -> Word8 toB64 46 = 65 toB64 47 = 66 toB64 89 = 97 toB64 90 = 98 toB64 121 = 48 toB64 122 = 49 toB64 56 = 43 toB64 57 = 47 toB64 c = c + 2 fromB64 :: Word8 -> Word8 fromB64 65 = 46 fromB64 66 = 47 fromB64 97 = 89 fromB64 98 = 90 fromB64 48 = 121 fromB64 49 = 122 fromB64 43 = 56 fromB64 47 = 57 fromB64 c = c - 2 decode :: BS.ByteString -> BS.ByteString decode = B64.decodeLenient . BS.map toB64 encode :: BS.ByteString -> BS.ByteString encode = BS.map fromB64 . BS.takeWhile (61 /=) . B64.encode