summaryrefslogtreecommitdiff
path: root/Crypto.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-04-21 16:37:14 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-04-21 16:37:14 -0400
commit892593c5efacbc084d19af4b5d7164ededaea7ff (patch)
tree20c1763ad5ca69b89c4a8977d6a45c98dc64b217 /Crypto.hs
parent66d951c3fd1a2aa19543d4148be8de734f54fd5c (diff)
Use haskell Crypto library instead of haskell SHA library.a
Since hS3 needs Crypto anyway, this actually reduces dependencies.
Diffstat (limited to 'Crypto.hs')
-rw-r--r--Crypto.hs24
1 files changed, 16 insertions, 8 deletions
diff --git a/Crypto.hs b/Crypto.hs
index 478d83761..ef7b49d8f 100644
--- a/Crypto.hs
+++ b/Crypto.hs
@@ -27,20 +27,21 @@ module Crypto (
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 Data.HMAC
+import Data.Array
+import Codec.Utils
+import System.Cmd.Utils
import System.IO
import System.Posix.IO
import System.Posix.Types
import System.Posix.Process
-import Control.Concurrent
-import Control.Exception (finally)
import System.Exit
import System.Environment
+import Control.Concurrent
+import Control.Exception (finally)
import Types
import Key
@@ -143,9 +144,9 @@ decryptCipher _ (EncryptedCipher encipher _) =
encryptKey :: Cipher -> Key -> IO Key
encryptKey c k =
return Key {
- keyName = showDigest $ hmacSha1
- (fromString $ cipherHmac c)
- (fromString $ show k),
+ keyName = showOctets $ hmac_sha1
+ (s2w8 $ cipherHmac c)
+ (s2w8 $ show k),
keyBackendName = "GPGHMACSHA1",
keySize = Nothing, -- size and mtime omitted
keyMtime = Nothing -- to avoid leaking data
@@ -252,3 +253,10 @@ fromB64 s =
case B64.decode s of
Nothing -> error "bad base64 encoded data"
Just ws -> w82s ws
+
+showOctets :: [Octet] -> String
+showOctets = concat . map hexChars
+ where
+ hexChars c = [arr ! (c `div` 16), arr ! (c `mod` 16)]
+ arr = listArray (0, 15) "0123456789abcdef"
+