git-annex/Utility/Base64.hs

26 lines
552 B
Haskell
Raw Normal View History

{- Simple Base64 encoding
-
- Copyright 2011-2023 Joey Hess <id@joeyh.name>
2011-05-01 18:27:40 +00:00
-
- License: BSD-2-clause
2011-05-01 18:27:40 +00:00
-}
module Utility.Base64 where
2011-05-01 18:27:40 +00:00
import Utility.Exception
import Codec.Binary.Base64 as B64
import Data.Maybe
import qualified Data.ByteString as B
2011-05-01 18:27:40 +00:00
toB64 :: B.ByteString -> B.ByteString
toB64 = B64.encode
fromB64Maybe :: B.ByteString -> Maybe (B.ByteString)
fromB64Maybe = either (const Nothing) Just . B64.decode
fromB64 :: B.ByteString -> B.ByteString
fromB64 = fromMaybe bad . fromB64Maybe
where
bad = giveup "bad base64 encoded data"