diff options
Diffstat (limited to 'Utility/Base64.hs')
-rw-r--r-- | Utility/Base64.hs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Utility/Base64.hs b/Utility/Base64.hs index 6ab3c984f..0e3087276 100644 --- a/Utility/Base64.hs +++ b/Utility/Base64.hs @@ -1,5 +1,8 @@ {- Simple Base64 encoding of Strings - + - Note that this uses the FileSystemEncoding, so it can be used on Strings + - that repesent filepaths containing arbitrarily encoded characters. + - - Copyright 2011, 2015 Joey Hess <id@joeyh.name> - - License: BSD-2-clause @@ -9,13 +12,15 @@ module Utility.Base64 (toB64, fromB64Maybe, fromB64, prop_b64_roundtrips) where import qualified "sandi" Codec.Binary.Base64 as B64 import Data.Maybe +import qualified Data.ByteString.Lazy as L import Data.ByteString.UTF8 (fromString, toString) +import Utility.FileSystemEncoding toB64 :: String -> String -toB64 = toString . B64.encode . fromString +toB64 = toString . B64.encode . L.toStrict . encodeBS fromB64Maybe :: String -> Maybe String -fromB64Maybe s = either (const Nothing) (Just . toString) +fromB64Maybe s = either (const Nothing) (Just . decodeBS . L.fromStrict) (B64.decode $ fromString s) fromB64 :: String -> String |