[clean up SHA1 code some, export raw SHA1 type to avoid unneeded string conversions
John Meacham <john@repetae.net>**20070519020911] move ./Util/SHA1.lhs ./Util/SHA1.hs
hunk ./Util/SHA1.hs 1
+{-
hunk ./Util/SHA1.hs 7
+Modified by John Meacham for code cleanups.
+
+
hunk ./Util/SHA1.hs 24
-\begin{code}
-{-# OPTIONS -fglasgow-exts -fno-warn-name-shadowing -O2 #-}
--- -fglasgow-exts needed for nasty hack below
--- name shadowing disabled because a,b,c,d,e are shadowed loads in step 4
-module Util.SHA1 (sha1file) where
+-}
+
+{-# OPTIONS -funbox-strict-fields -fglasgow-exts -fno-warn-name-shadowing -O2 #-}
+
+module Util.SHA1 (sha1file,ABCDE(..),Hash) where
hunk ./Util/SHA1.hs 30
--- import Autoconf (big_endian)
---import PackedString (PackedString, unsafeWithInternals,
---                     concatLenPS, packWords, lengthPS)
hunk ./Util/SHA1.hs 40
+type Hash = ABCDE
hunk ./Util/SHA1.hs 42
+    deriving(Eq,Ord)
+
hunk ./Util/SHA1.hs 46
-sha1file :: FilePath -> IO String
+{-# NOINLINE sha1file #-}
+sha1file :: FilePath -> IO Hash
hunk ./Util/SHA1.hs 62
-    return $ sha1_step_5_display res
+    return res
hunk ./Util/SHA1.hs 73
-{-
-sha1PS :: PackedString -> String
-sha1PS s = s5
- where s1_2 = sha1_step_1_2_pad_length s
-       abcde = sha1_step_3_init
-       abcde' = unsafePerformIO
-              $ unsafeWithInternals s1_2 (\ptr len ->
-                    do let ptr' = castPtr ptr
-                       unless big_endian $ fiddle_endianness ptr' len
-                       sha1_step_4_main abcde ptr' len)
-       s5 = sha1_step_5_display abcde'
--}
hunk ./Util/SHA1.hs 82
-\end{code}
hunk ./Util/SHA1.hs 83
-sha1_step_1_2_pad_length assumes the length is at most 2^61.
-This seems reasonable as the Int used to represent it is normally 32bit,
-but obviously could go wrong with large inputs on 64bit machines.
-The PackedString library should probably move to Word64s if this is an
-issue, though.
+-- sha1_step_1_2_pad_length assumes the length is at most 2^61.
+-- This seems reasonable as the Int used to represent it is normally 32bit,
+-- but obviously could go wrong with large inputs on 64bit machines.
+-- The PackedString library should probably move to Word64s if this is an
+-- issue, though.
+--
+-- sha1_step_1_2_pad_length :: PackedString -> PackedString
+-- sha1_step_1_2_pad_length s
+--  = let len = lengthPS s
+--        num_nuls = (55 - len) `mod` 64
+--        padding = 128:replicate num_nuls 0
+--        len_w8s = reverse $ size_split 8 (fromIntegral len*8)
+--    in concatLenPS (len + 1 + num_nuls + 8)
+--                   [s, packWords padding, packWords len_w8s]
hunk ./Util/SHA1.hs 98
-sha1_step_1_2_pad_length :: PackedString -> PackedString
-sha1_step_1_2_pad_length s
- = let len = lengthPS s
-       num_nuls = (55 - len) `mod` 64
-       padding = 128:replicate num_nuls 0
-       len_w8s = reverse $ size_split 8 (fromIntegral len*8)
-   in concatLenPS (len + 1 + num_nuls + 8)
-                  [s, packWords padding, packWords len_w8s]
-\begin{code}
hunk ./Util/SHA1.hs 109
-\end{code}
hunk ./Util/SHA1.hs 110
-\begin{code}
hunk ./Util/SHA1.hs 219
-sha1_step_5_display :: ABCDE -> String
-sha1_step_5_display (ABCDE a b c d e)
- = concatMap showAsHex [a, b, c, d, e]
+instance Show ABCDE where
+    showsPrec _ (ABCDE a b c d e) = showAsHex a . showAsHex b . showAsHex c . showAsHex d . showAsHex e
hunk ./Util/SHA1.hs 222
-showAsHex :: Word32 -> String
-showAsHex n = showIt 8 n ""
+showAsHex :: Word32 -> ShowS
+showAsHex n = showIt 8 n
hunk ./Util/SHA1.hs 230
-\end{code}