File: Internal.hs

package info (click to toggle)
haskell-cryptohash 0.11.9-11
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 336 kB
  • sloc: haskell: 1,325; ansic: 991; makefile: 4
file content (38 lines) | stat: -rw-r--r-- 1,072 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{-# LANGUAGE CPP #-}
{-# LANGUAGE PackageImports #-}

-- |
-- Module      : Crypto.Hash.Internal
-- License     : BSD-style
-- Maintainer  : Vincent Hanquez <vincent@snarc.org>
-- Stability   : experimental
-- Portability : unknown
module Crypto.Hash.Internal
    ( unsafeDoIO
    , digestToByteString
    , digestToByteStringWitness
    ) where

import System.IO.Unsafe
import Data.ByteArray (convert)
import "cryptonite" Crypto.Hash
import Data.ByteString (ByteString)

-- | perform io for hashes that do allocation and ffi.
-- unsafeDupablePerformIO is used when possible as the
-- computation is pure and the output is directly linked
-- to the input. we also do not modify anything after it has
-- been returned to the user.
unsafeDoIO :: IO a -> a
#if __GLASGOW_HASKELL__ > 704
unsafeDoIO = unsafeDupablePerformIO
#else
unsafeDoIO = unsafePerformIO
#endif

digestToByteString :: HashAlgorithm h => Digest h -> ByteString
digestToByteString = convert

digestToByteStringWitness :: HashAlgorithm h => h -> Digest h -> ByteString
digestToByteStringWitness _ = convert