How to work around duplicate symbol error when using Yesod and Darcs library?

回眸只為那壹抹淺笑 提交于 2019-12-05 04:46:02

The darcs hash output is just the base16 encoded version of the cryptohash output. Looks like base16-bytestring is one way to bridge that gap. I tried it and Crypt.SHA256 becomes as simple as:

module Crypt.SHA256 ( sha256sum ) where

import Crypto.Hash.SHA256 ( hash )
import Data.ByteString ( ByteString )
import Data.ByteString.Base16 ( encode )
import Data.ByteString.Char8 ( unpack )

sha256sum :: ByteString -> String
sha256sum = unpack . encode . hash

In fact the hashed-storage package also has a copy of sha2.c and fixed the problem by renaming the symbols. So the simplest quick fix for darcs 2.8 is to copy sha2.h and sha2.c from hashed-storage, replace hashed_storage_ with darcs_ in both files, and change the FFI import in src/Crypt/SHA256.hs in darcs to:

foreign import ccall unsafe "sha2.h darcs_sha256" c_sha256
    :: Ptr CChar -> CSize -> Ptr Word8 -> IO ()

I'd be happy to release darcs 2.8.3 with this change if it would help you. For 2.10 I'll switch to using cryptohash as above as I don't see any reason to keep using the local C version and in general in darcs we are trying to get rid of private implementations of common code.

EDIT: I originally thought hashed-storage would have the same problem, but I was wrong (in retrospect it's obvious that it would have clashed with darcs itself if not for the renaming).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!