On Wed, Feb 22, 2012 at 04:56:29PM +0100, Guido Trotter wrote: > On Tue, Feb 21, 2012 at 13:21, Iustin Pop <[email protected]> wrote: > > +-- | Computes the HMAC for a given key/test and salt. > > +computeMac :: HashKey -> Maybe String -> String -> String > > +computeMac key salt text = > > + concat . map (printf "%02x") . hmac_sha1 key $ text'' > > + where text' = case salt of > > + Nothing -> text > > + Just salt' -> salt' ++ text > > + text'' = stringToWord8 text' > > + > > I tried simplifying computeMac: would this work: > diff --git a/htools/Ganeti/Hash.hs b/htools/Ganeti/Hash.hs > index e64d7a0..84739ae 100644 > --- a/htools/Ganeti/Hash.hs > +++ b/htools/Ganeti/Hash.hs > @@ -48,11 +48,8 @@ stringToWord8 = B.unpack . encodeUtf8 . T.pack > -- | Computes the HMAC for a given key/test and salt. > computeMac :: HashKey -> Maybe String -> String -> String > computeMac key salt text = > - concat . map (printf "%02x") . hmac_sha1 key $ text'' > - where text' = case salt of > - Nothing -> text > - Just salt' -> salt' ++ text > - text'' = stringToWord8 text' > + concat . map (printf "%02x") . hmac_sha1 key $ > + stringToWord8 $ maybe text (++ text) salt
Yes, very nice! Since stringToWord8 is a function, you can replace the first $ you added with a '.'. thanks! iustin
