factor out base64 code

This commit is contained in:
Joey Hess 2011-05-01 14:27:40 -04:00
parent 3095e16311
commit 2ddade8132
3 changed files with 22 additions and 13 deletions

20
Base64.hs Normal file
View file

@ -0,0 +1,20 @@
{- Simple Base64 access
-
- Copyright 2011 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Base64 (toB64, fromB64) where
import Codec.Binary.Base64
import Data.Bits.Utils
toB64 :: String -> String
toB64 = encode . s2w8
fromB64 :: String -> String
fromB64 s =
case decode s of
Nothing -> error "bad base64 encoded data"
Just ws -> w82s ws

View file

@ -22,21 +22,17 @@ module Crypto (
withDecryptedHandle,
withEncryptedContent,
withDecryptedContent,
toB64,
fromB64,
prop_hmacWithCipher_sane
) where
import qualified Data.ByteString.Lazy.Char8 as L
import qualified Data.Map as M
import qualified Codec.Binary.Base64 as B64
import Data.ByteString.Lazy.UTF8 (fromString)
import Data.Digest.Pure.SHA
import System.Cmd.Utils
import Data.String.Utils
import Data.List
import Data.Bits.Utils
import System.IO
import System.Posix.IO
import System.Posix.Types
@ -50,6 +46,7 @@ import Types
import Key
import RemoteClass
import Utility
import Base64
import CryptoTypes
{- The first half of a Cipher is used for HMAC; the remainder
@ -246,15 +243,6 @@ configGet c key =
Just v -> v
Nothing -> error $ "missing " ++ key ++ " in remote config"
toB64 :: String -> String
toB64 = B64.encode . s2w8
fromB64 :: String -> String
fromB64 s =
case B64.decode s of
Nothing -> error "bad base64 encoded data"
Just ws -> w82s ws
hmacWithCipher :: Cipher -> String -> String
hmacWithCipher c = hmacWithCipher' (cipherHmac c)
hmacWithCipher' :: String -> String -> String

View file

@ -33,6 +33,7 @@ import Remote.Encryptable
import Crypto
import Key
import Content
import Base64
remote :: RemoteType Annex
remote = RemoteType {