commit ghc-hopenssl for openSUSE:Factory
Hello community, here is the log from the commit of package ghc-hopenssl for openSUSE:Factory checked in at 2017-08-31 20:47:37 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/ghc-hopenssl (Old) and /work/SRC/openSUSE:Factory/.ghc-hopenssl.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "ghc-hopenssl" Thu Aug 31 20:47:37 2017 rev:2 rq:513385 version:2.2.1 Changes: -------- --- /work/SRC/openSUSE:Factory/ghc-hopenssl/ghc-hopenssl.changes 2017-03-08 00:54:47.265586267 +0100 +++ /work/SRC/openSUSE:Factory/.ghc-hopenssl.new/ghc-hopenssl.changes 2017-08-31 20:47:40.181511032 +0200 @@ -1,0 +2,5 @@ +Thu Jul 27 14:06:59 UTC 2017 - psimons@suse.com + +- Update to version 2.2.1. + +------------------------------------------------------------------- Old: ---- hopenssl-1.7.tar.gz New: ---- hopenssl-2.2.1.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ ghc-hopenssl.spec ++++++ --- /var/tmp/diff_new_pack.g5Ttsr/_old 2017-08-31 20:47:41.045389773 +0200 +++ /var/tmp/diff_new_pack.g5Ttsr/_new 2017-08-31 20:47:41.049389211 +0200 @@ -1,7 +1,7 @@ # # spec file for package ghc-hopenssl # -# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -17,38 +17,39 @@ %global pkg_name hopenssl +%bcond_with tests Name: ghc-%{pkg_name} -Version: 1.7 +Version: 2.2.1 Release: 0 -Summary: FFI bindings to OpenSSL's EVP digest interface +Summary: FFI Bindings to OpenSSL's EVP Digest Interface License: BSD-3-Clause -Group: System/Libraries +Group: Development/Languages/Other Url: https://hackage.haskell.org/package/%{pkg_name} Source0: https://hackage.haskell.org/package/%{pkg_name}-%{version}/%{pkg_name}-%{version}.tar.gz BuildRequires: ghc-Cabal-devel -# Begin cabal-rpm deps: BuildRequires: ghc-bytestring-devel -BuildRequires: ghc-mtl-devel +BuildRequires: ghc-cabal-doctest-devel BuildRequires: ghc-rpm-macros BuildRequires: libopenssl-devel BuildRoot: %{_tmppath}/%{name}-%{version}-build -# End cabal-rpm deps +%if %{with tests} +BuildRequires: ghc-HUnit-devel +BuildRequires: ghc-doctest-devel +%endif %description -Foreign-function bindings to the OpenSSL library <http://www.openssl.org/>. +Foreign-function bindings to the <http://www.openssl.org/ OpenSSL library>. Currently provides access to the messages digests MD5, DSS, DSS1, RIPEMD160, -and several variants of SHA through the EVP digest interface. +and various SHA variants through the EVP digest interface. %package devel Summary: Haskell %{pkg_name} library development files Group: Development/Libraries/Other Requires: %{name} = %{version}-%{release} Requires: ghc-compiler = %{ghc_version} -# Begin cabal-rpm deps: Requires: libopenssl-devel Requires(post): ghc-compiler = %{ghc_version} Requires(postun): ghc-compiler = %{ghc_version} -# End cabal-rpm deps %description devel This package provides the Haskell %{pkg_name} library development files. @@ -56,14 +57,14 @@ %prep %setup -q -n %{pkg_name}-%{version} - %build %ghc_lib_build - %install %ghc_lib_install +%check +%cabal_test %post devel %ghc_pkg_recache ++++++ hopenssl-1.7.tar.gz -> hopenssl-2.2.1.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hopenssl-1.7/OpenSSL/Digest/ByteString/Lazy.hs new/hopenssl-2.2.1/OpenSSL/Digest/ByteString/Lazy.hs --- old/hopenssl-1.7/OpenSSL/Digest/ByteString/Lazy.hs 2014-12-17 18:25:00.000000000 +0100 +++ new/hopenssl-2.2.1/OpenSSL/Digest/ByteString/Lazy.hs 1970-01-01 01:00:00.000000000 +0100 @@ -1,32 +0,0 @@ -{- | - Module : OpenSSL.Digest.ByteString.Lazy - Copyright : (c) 2010 by Peter Simons - License : BSD3 - - Maintainer : simons@cryp.to - Stability : provisional - Portability : portable - - Wrappers for "OpenSSL.Digest" that supports lazy 'ByteString'. - -} - -module OpenSSL.Digest.ByteString.Lazy where - -import OpenSSL.Digest hiding ( update ) -import Data.Word ( Word8 ) -import Control.Monad.State ( evalStateT ) -import qualified OpenSSL.Digest.ByteString as BS ( update ) -import Data.ByteString.Lazy ( ByteString, toChunks ) - --- |A convenience wrapper which computes the given digest type of a --- 'ByteString'. Unlike the monadic interface, this function does not --- allow the computation to be restarted. - -digest :: MessageDigest -> ByteString -> IO [Word8] -digest mdType xs = - mkDigest mdType $ evalStateT (update xs >> final) - --- |Update the internal state with a block of data. - -update :: ByteString -> Digest Int -update = fmap sum . mapM BS.update . toChunks diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hopenssl-1.7/OpenSSL/Digest/ByteString.hs new/hopenssl-2.2.1/OpenSSL/Digest/ByteString.hs --- old/hopenssl-1.7/OpenSSL/Digest/ByteString.hs 2014-12-17 18:25:00.000000000 +0100 +++ new/hopenssl-2.2.1/OpenSSL/Digest/ByteString.hs 1970-01-01 01:00:00.000000000 +0100 @@ -1,38 +0,0 @@ -{- | - Module : OpenSSL.Digest.ByteString - Copyright : (c) 2010 by Peter Simons - License : BSD3 - - Maintainer : simons@cryp.to - Stability : provisional - Portability : portable - - Wrappers for "OpenSSL.Digest" that supports 'ByteString'. - -} - -module OpenSSL.Digest.ByteString where - -import OpenSSL.Digest hiding ( update ) -import Control.Monad.State ( evalStateT, lift, get ) -import Foreign.Ptr ( castPtr ) -import Data.Word ( Word8 ) -import Data.ByteString ( ByteString ) -import Data.ByteString.Unsafe ( unsafeUseAsCStringLen ) - --- |A convenience wrapper which computes the given digest type of a --- 'ByteString'. Unlike the monadic interface, this function does not --- allow the computation to be restarted. - -digest :: MessageDigest -> ByteString -> IO [Word8] -digest mdType xs = - mkDigest mdType $ evalStateT (update xs >> final) - --- |Update the internal state with a block of data. - -update :: ByteString -> Digest Int -update bs = do - DST ctx <- get - l <- lift $ - unsafeUseAsCStringLen bs $ \(ptr, len) -> - digestUpdate ctx (castPtr ptr) (fromIntegral len) - return (fromEnum l) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hopenssl-1.7/OpenSSL/Digest.hs new/hopenssl-2.2.1/OpenSSL/Digest.hs --- old/hopenssl-1.7/OpenSSL/Digest.hs 2014-12-17 18:25:00.000000000 +0100 +++ new/hopenssl-2.2.1/OpenSSL/Digest.hs 1970-01-01 01:00:00.000000000 +0100 @@ -1,237 +0,0 @@ -{-# LANGUAGE ForeignFunctionInterface #-} - -{- | - Module : OpenSSL.Digest - Copyright : (c) 2014 by Peter Simons - License : BSD3 - - Maintainer : simons@cryp.to - Stability : provisional - Portability : portable - - This module proivdes a high-level API to the message - digest algorithms found in OpenSSL's @crypto@ library. - Link with @-lcrypto@ when using this module. - - Here is a short example program which runs all available - digests on a string: - - > example :: (Enum a) => [a] -> IO [String] - > example input = mapM hash [minBound .. maxBound] - > where - > hash f = fmap (fmt f) (digest f (toWord input)) - > fmt f = shows f . (": \t"++) . (>>=toHex) - > toWord = map (toEnum . fromEnum) - - And when called, the function prints: - - > *Digest> example "open sesame" >>= putStr . unlines - > Null: - > MD5: 54ef36ec71201fdf9d1423fd26f97f6b - > SHA: 2ccefef64c76ac0d42ca1657457977675890c42f - > SHA1: 5bcaff7f22ff533ca099b3408ead876c0ebba9a7 - > DSS: 5bcaff7f22ff533ca099b3408ead876c0ebba9a7 - > DSS1: 5bcaff7f22ff533ca099b3408ead876c0ebba9a7 - > RIPEMD160: bdb2bba6ec93bd566dc1181cadbc92176aa78382 - > MDC2: 112db2200ce1e9db3c2d132aea4ef7d0 - > SHA224: 1ee0f9d93a873a67fe781852d716cb3e5904e015aafaa4d1ff1a81bc - > SHA256: 41ef4bb0b23661e66301aac36066912dac037827b4ae63a7b1165a5aa93ed4eb - > SHA384: ae2a5d6649035c00efe2bc1b5c97f4d5ff97fa2df06f273afa0231c425e8aff30e4cc1db5e5756e8d2245a1514ad1a2d - > SHA512: 8470cdd3bf1ef85d5f092bce5ae5af97ce50820481bf43b2413807fec37e2785b533a65d4c7d71695b141d81ebcd4b6c4def4284e6067f0b400000001b230205 --} - -module OpenSSL.Digest where - -import Control.Exception ( bracket ) -import Foreign -import Foreign.C -import Control.Monad.State -import Numeric ( showHex ) - --- * High-level API - --- |The message digest algorithms we support. - -data MessageDigest - = Null -- ^ 0 bit - | MD5 -- ^ 128 bit - | SHA -- ^ 160 bit - | SHA1 -- ^ 160 bit - | DSS -- ^ other name for SHA1 - | DSS1 -- ^ other name for SHA1 - | RIPEMD160 -- ^ 160 bit - | MDC2 -- ^ 128 bit - | SHA224 -- ^ 224 bit - | SHA256 -- ^ 256 bit - | SHA384 -- ^ 384 bit - | SHA512 -- ^ 512 bit - deriving (Show, Eq, Enum, Bounded) - --- |A convenience wrapper which computes the given digest --- over a list of 'Word8'. Unlike the monadic interface, --- this function does not allow the computation to be --- restarted. - -digest :: MessageDigest -> [Word8] -> IO [Word8] -digest mdType xs = - mkDigest mdType $ evalStateT (update xs >> final) - --- |A monadic interface to the digest computation. - -type Digest a = StateT DigestState IO a - --- |The internal EVP context. - -newtype DigestState = DST (Ptr OpaqueContext) - --- |Run an 'IO' computation with an initialized --- 'DigestState'. All resources will be freed when the --- computation returns. - -mkDigest :: MessageDigest -> (DigestState -> IO a) -> IO a -mkDigest mdType f = - bracket ctxCreate ctxDestroy $ \ctx -> do - when (ctx == nullPtr) (fail "Digest.mkDigest: ctxCreate failed") - md <- toMDEngine mdType - when (md == nullPtr) (fail ("Digest.mkDigest: can't access "++show mdType)) - rc <- digestInit ctx md - when (rc == 0) (fail ("Digest.mkDigest: can't initialize "++show mdType)) - f (DST ctx) - --- |Update the internal state with a block of data. This --- function is just a wrapper for 'update'', which creates --- an array in memory using 'withArray'. - -update :: [Word8] -> Digest () -update xs = do - st <- get - liftIO $ - withArray xs $ \p -> - evalStateT (update' (p, length xs)) st - --- |Update the internal state with a block of data from --- memory. This is the /faster/ version of 'update'. - -update' :: (Ptr Word8, Int) -> Digest () -update' (p,n) = do - DST ctx <- get - rc <- liftIO $ digestUpdate ctx p (toEnum (fromEnum n)) - when (rc == 0) (fail "Digest.update failed") - --- |Wrap up the computation, add padding, do whatever has to --- be done, and return the final hash. The length of the --- result depends on the chosen 'MessageDigest'. Do not call --- more than once! - -final :: Digest [Word8] -final = do - DST ctx <- get - liftIO $ - allocaArray maxMDSize $ \p -> - allocaArray (sizeOf (undefined :: CUInt)) $ \i -> do - rc <- digestFinal ctx p i - when (rc == 0) (fail "Digest.Final failed") - i' <- peek i - peekArray (fromEnum i') p - --- * Low-level API - --- |The EVP context used by OpenSSL is opaque for us; we --- only access it through a 'Ptr'. - -data OpaqueContext = OpaqueContext -type Context = Ptr OpaqueContext - --- |The message digest engines are opaque for us as well. - -data OpaqueMDEngine = OpaqueMDEngine -type MDEngine = Ptr OpaqueMDEngine - --- |Maximum size of all message digests supported by --- OpenSSL. Allocate a buffer of this size for 'digestFinal' --- if you want to stay generic. - -maxMDSize :: Int -maxMDSize = 36 - --- |Create an EVP context. May be 'nullPtr'. - -foreign import ccall unsafe "EVP_MD_CTX_create" ctxCreate :: - IO Context - --- |Initialize an EVP context. - -foreign import ccall unsafe "EVP_MD_CTX_init" ctxInit :: - Context -> IO () - --- |Destroy an EVP context and free the allocated resources. - -foreign import ccall unsafe "EVP_MD_CTX_destroy" ctxDestroy :: - Context -> IO () - --- |Set the message digest engine for 'digestUpdate' calls. --- Returns @\/=0@ in case of an error. - -foreign import ccall unsafe "EVP_DigestInit" digestInit :: - Context -> MDEngine -> IO CInt - --- |Update the internal context with a block of input. --- Returns @\/=0@ in case of an error. - -foreign import ccall unsafe "EVP_DigestUpdate" digestUpdate :: - Context -> Ptr Word8 -> CUInt -> IO CInt - --- |Wrap up the digest computation and return the final --- digest. Do not call repeatedly on the same context! --- Returns @\/=0@ in case of an error. The pointer to the --- unsigned integer may be 'nullPtr'. If it is not, --- 'digestFinal' will store the length of the computed --- digest there. - -foreign import ccall unsafe "EVP_DigestFinal" digestFinal :: - Context -> Ptr Word8 -> Ptr CUInt -> IO CInt - --- ** Message Digest Engines - -foreign import ccall unsafe "EVP_dss" mdDSS :: IO MDEngine -foreign import ccall unsafe "EVP_dss1" mdDSS1 :: IO MDEngine -foreign import ccall unsafe "EVP_md5" mdMD5 :: IO MDEngine -foreign import ccall unsafe "EVP_md_null" mdNull :: IO MDEngine -foreign import ccall unsafe "EVP_mdc2" mdMDC2 :: IO MDEngine -foreign import ccall unsafe "EVP_ripemd160" mdRIPEMD160 :: IO MDEngine -foreign import ccall unsafe "EVP_sha" mdSHA :: IO MDEngine -foreign import ccall unsafe "EVP_sha1" mdSHA1 :: IO MDEngine -foreign import ccall unsafe "EVP_sha224" mdSHA224 :: IO MDEngine -foreign import ccall unsafe "EVP_sha256" mdSHA256 :: IO MDEngine -foreign import ccall unsafe "EVP_sha384" mdSHA384 :: IO MDEngine -foreign import ccall unsafe "EVP_sha512" mdSHA512 :: IO MDEngine - --- |Map a 'MessageDigest' type into the the corresponding --- 'MDEngine'. - -toMDEngine :: MessageDigest -> IO MDEngine -toMDEngine Null = mdNull -toMDEngine MD5 = mdMD5 -toMDEngine SHA = mdSHA -toMDEngine SHA1 = mdSHA1 -toMDEngine DSS = mdDSS -toMDEngine DSS1 = mdDSS1 -toMDEngine RIPEMD160 = mdRIPEMD160 -toMDEngine MDC2 = mdMDC2 -toMDEngine SHA224 = mdSHA224 -toMDEngine SHA256 = mdSHA256 -toMDEngine SHA384 = mdSHA384 -toMDEngine SHA512 = mdSHA512 - --- * Helper Functions - --- |Neat helper to print digests with: --- @ --- \\ws :: [Word8] -> ws >>= toHex --- @ - -toHex :: Word8 -> String -toHex w = case showHex w "" of - w1:w2:[] -> w1:w2:[] - w2:[] -> '0':w2:[] - _ -> error "showHex returned []" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hopenssl-1.7/Setup.hs new/hopenssl-2.2.1/Setup.hs --- old/hopenssl-1.7/Setup.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/hopenssl-2.2.1/Setup.hs 2017-07-07 13:30:48.000000000 +0200 @@ -0,0 +1,34 @@ +{-# LANGUAGE CPP #-} +{-# OPTIONS_GHC -Wall #-} + +module Main ( main ) where + +#ifndef MIN_VERSION_cabal_doctest +#define MIN_VERSION_cabal_doctest(x,y,z) 0 +#endif + +#if MIN_VERSION_cabal_doctest(1,0,0) + +import Distribution.Extra.Doctest ( defaultMainWithDoctests ) +main :: IO () +main = defaultMainWithDoctests "doctests" + +#else + +#ifdef MIN_VERSION_Cabal +-- If the macro is defined, we have new cabal-install, +-- but for some reason we don't have cabal-doctest in package-db +-- +-- Probably we are running cabal sdist, when otherwise using new-build +-- workflow +#warning You are configuring this package without cabal-doctest installed. \ + The doctests test-suite will not work as a result. \ + To fix this, install cabal-doctest before configuring. +#endif + +import Distribution.Simple + +main :: IO () +main = defaultMain + +#endif diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hopenssl-1.7/Setup.lhs new/hopenssl-2.2.1/Setup.lhs --- old/hopenssl-1.7/Setup.lhs 2014-12-17 18:25:00.000000000 +0100 +++ new/hopenssl-2.2.1/Setup.lhs 1970-01-01 01:00:00.000000000 +0100 @@ -1,8 +0,0 @@ -#!/usr/bin/env runhaskell - -> module Main (main) where -> -> import Distribution.Simple -> -> main :: IO () -> main = defaultMain diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hopenssl-1.7/hopenssl.cabal new/hopenssl-2.2.1/hopenssl.cabal --- old/hopenssl-1.7/hopenssl.cabal 2014-12-17 18:25:00.000000000 +0100 +++ new/hopenssl-2.2.1/hopenssl.cabal 2017-07-07 13:30:48.000000000 +0200 @@ -1,31 +1,68 @@ -Name: hopenssl -Version: 1.7 -Copyright: (c) 2004-2013 Peter Simons -License: BSD3 -License-File: LICENSE -Author: Peter Simons <simons@cryp.to>, - Jesper Louis Andersen <jesper.louis.andersen@gmail.com>, - Markus Rothe <markus@unixforces.net> -Maintainer: Peter Simons <simons@cryp.to> -Homepage: http://github.com/peti/hopenssl -Category: Foreign, Cryptography -Synopsis: FFI bindings to OpenSSL's EVP digest interface -Description: Foreign-function bindings to the OpenSSL library - <http://www.openssl.org/>. Currently provides - access to the messages digests MD5, DSS, DSS1, - RIPEMD160, and several variants of SHA through - the EVP digest interface. -Cabal-Version: >= 1.6 -Build-Type: Simple -Tested-With: GHC >= 6.10.4 && <= 7.8.3 - -Source-Repository head - Type: git - Location: git://github.com/peti/hopenssl.git - -Library - Build-Depends: base >= 3 && < 5, mtl, bytestring - Extensions: ForeignFunctionInterface - Extra-Libraries: crypto - Includes: "openssl/evp.h" - Exposed-Modules: OpenSSL.Digest, OpenSSL.Digest.ByteString, OpenSSL.Digest.ByteString.Lazy +name: hopenssl +version: 2.2.1 +copyright: (c) 2004-2017 Peter Simons +license: BSD3 +license-file: LICENSE +author: Peter Simons, Markus Rothe +maintainer: Peter Simons <simons@cryp.to> +homepage: http://github.com/peti/hopenssl +category: Foreign, Cryptography +synopsis: FFI Bindings to OpenSSL's EVP Digest Interface +description: Foreign-function bindings to the + <http://www.openssl.org/ OpenSSL library>. Currently + provides access to the messages digests MD5, DSS, DSS1, + RIPEMD160, and various SHA variants through the EVP + digest interface. +cabal-version: >= 1.8 +build-type: Custom +tested-with: GHC > 7.6 && < 8.1 + +custom-setup + setup-depends: + base >= 4 && <5, + Cabal, + cabal-doctest >= 1 && <1.1 + +source-repository head + type: git + location: git://github.com/peti/hopenssl.git + +library + build-depends: base >= 4.6 && < 5, bytestring + hs-source-dirs: src + other-extensions: CPP, DeriveDataTypeable, EmptyDataDecls, FlexibleInstances, + ForeignFunctionInterface, TypeSynonymInstances + extra-libraries: crypto + includes: "openssl/evp.h" + exposed-modules: OpenSSL.Digest + OpenSSL.Util + OpenSSL.EVP.Digest + OpenSSL.EVP.Digest.Algorithm + OpenSSL.EVP.Digest.Digest + OpenSSL.EVP.Digest.Context + OpenSSL.EVP.Digest.Error + OpenSSL.EVP.Digest.Initialization + build-tools: hsc2hs + +test-suite check-low-level-digest-api + type: exitcode-stdio-1.0 + main-is: CheckLowLevelDigestAPI.hs + other-modules: OpenSesame + hs-source-dirs: test + build-depends: base >= 3 && < 5, hopenssl, HUnit + ghc-options: -threaded + +test-suite check-high-level-digest-api + type: exitcode-stdio-1.0 + main-is: CheckHighLevelDigestAPI.hs + other-modules: OpenSesame + hs-source-dirs: test + build-depends: base >= 3 && < 5, hopenssl, HUnit + ghc-options: -threaded + +test-suite doctests + type: exitcode-stdio-1.0 + main-is: doctests.hs + hs-source-dirs: test + build-depends: base, hopenssl, doctest + ghc-options: -threaded diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hopenssl-1.7/src/OpenSSL/Digest.hs new/hopenssl-2.2.1/src/OpenSSL/Digest.hs --- old/hopenssl-1.7/src/OpenSSL/Digest.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/hopenssl-2.2.1/src/OpenSSL/Digest.hs 2017-07-07 13:30:48.000000000 +0200 @@ -0,0 +1,196 @@ +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE TypeSynonymInstances #-} + +{- | + Maintainer: simons@cryp.to + Stability: provisional + Portability: portable + + This module provides a generic high-level API to the message digest + algorithms found in OpenSSL's @crypto@ library. There are two functions of + particular interest: 'digestByName' and 'digest'. The former can be used to + retrieve an 'Algorithm', i.e. an OpenSSL object that implements a particular + algorithm. That type can then be used to compute actual message digests with + the latter function: + + >>> import Data.ByteString.Char8 ( pack ) + >>> digest (digestByName "md5") (pack "Hello, world.") + "\b\n\239\131\155\149\250\207s\236Y\147u\233-G" + + Neat pretty-printing can be achieved with 'toHex', which converts the binary + representation of a message digest into the common hexadecimal one: + + >>> toHex $ digest (digestByName "md5") (pack "Hello, world.") + "080aef839b95facf73ec599375e92d47" + >>> toHex $ digest (digestByName "sha1") (pack "Hello, world.") + "2ae01472317d1935a84797ec1983ae243fc6aa28" + + The precise set of available digest algorithms provided by OpenSSL depends + on the version of the library installed into the system, obviously, but it's + reasonable to expect the following algorithms to be present: MD5, RIPEMD160, + SHA1, SHA224, SHA256, SHA384, and SHA512. If an algorithm is not available, + 'digestByName' will throw an 'DigestAlgorithmNotAvailableInOpenSSL' + exception. If you don't like exceptions, use the tamer 'digestByName'' + variant: + + >>> digestByName' "i bet this algorithm won't exist" + Nothing + + 'Algorithm' is an instance of 'IsString', so with the proper GHC extensions + enabled it's possible to simplify the call to 'digest' even further: + + >>> :set -XOverloadedStrings + >>> toHex $ digest "sha256" (pack "The 'Through the Universe' podcast rules.") + "73624694a9435095c8fdaad711273a23c02226196c452f817cfd86f965895614" + + Last but not least, 'digest' is actually a class method of 'Digestable', + which collects things we can compute digests of. The defaults are + conservative, i.e. we support all things that correspond roughly to C's + construct of "void pointer plus a length". @digest@ can use with any of the + following signatures: + + >>> let shape1 = digest :: Algorithm -> (Ptr (), CSize) -> MessageDigest + >>> let shape2 = digest :: Algorithm -> (Ptr Word8, CSize) -> MessageDigest + >>> let shape3 = digest :: Algorithm -> (Ptr Word8, CUInt) -> MessageDigest + >>> let shape4 = digest :: Algorithm -> (Ptr (), Int) -> MessageDigest + >>> let shape5 = digest :: Algorithm -> StrictByteString -> MessageDigest + >>> let shape6 = digest :: Algorithm -> LazyByteString -> MessageDigest + + 'StrictByteString' and 'LazyByteString' are also instances of 'IsString' and + therefore subject to implicit construction from string literals: + + >>> shape5 "sha256" "hello" == shape6 "sha256" "hello" + True + + Note that this code offers no overloaded 'digest' version for 'String', + because that function would produce non-deterministic results for Unicode + characters. There is an instance for @[Word8]@, though, so strings can be + hashed after a proper encoding has been applied. For those who don't care + about determinism, there is the following specialized function: + + >>> toHex $ digestString "md5" "no Digestable instance for this sucker" + "a74827f849005794565f83fbd68ad189" + + If you don't mind orphaned instances, however, feel free to shoot yourself + in the foot: + + >>> :set -XFlexibleInstances + >>> instance Digestable String where updateChunk ctx str = withCStringLen str (updateChunk ctx) + >>> toHex $ digest "sha256" ("now we can hash strings" :: String) + "7f2989f173125810aa917c4ffe0e26ae1b5f7fb852274829c210297a43dfc7f9" +-} + +module OpenSSL.Digest + ( -- * Generic digest API + MessageDigest, digest, Digestable(..), digestByName, digestByName', Algorithm + , -- * Special instances + digestString + , -- * Helper Types and Functions + toHex, StrictByteString, LazyByteString + ) + where + +import OpenSSL.EVP.Digest +import qualified OpenSSL.Util as Util + +import Control.Exception +import qualified Data.ByteString as Strict ( ByteString, packCStringLen, concatMap ) +import Data.ByteString.Char8 as Strict8 ( pack ) +import qualified Data.ByteString.Lazy as Lazy ( ByteString, toChunks ) +import Data.ByteString.Unsafe ( unsafeUseAsCStringLen ) +import Foreign +import Foreign.C +import System.IO.Unsafe as IO + +-- Generic Class API ---------------------------------------------------------- + +-- | A message digest is essentially an array of 'Word8' octets. + +type MessageDigest = StrictByteString + +-- | Compute the given message digest of any 'Digestable' thing, i.e. any type +-- that can be converted /efficiently/ and /unambiguously/ into a continuous +-- memory buffer or a sequence of continuous memory buffers. Note that 'String' +-- does /not/ have that property, because the binary representation chosen for +-- Unicode characters during the marshaling process is determined by the +-- system's locale and is therefore non-deterministic. + +digest :: Digestable a => Algorithm -> a -> MessageDigest +digest algo input = + IO.unsafePerformIO $ + bracket newContext freeContext $ \ctx -> do + initDigest algo ctx + updateChunk ctx input + let mdSize = fromIntegral (digestSize algo) + allocaArray mdSize $ \md -> do + finalizeDigest ctx md + Strict.packCStringLen (castPtr md, mdSize) + +-- | A class of things that can be part of a digest computations. By default, +-- we define instances only for various representations of plain memory +-- buffers, but in theory that class can be extended to contain all kinds of +-- complex data types. + +class Digestable a where + updateChunk :: Context -> a -> IO () + +instance Digestable (Ptr a, CSize) where + {-# INLINE updateChunk #-} + updateChunk ctx = uncurry (updateDigest ctx) + +instance Digestable (Ptr a, CUInt) where + {-# INLINE updateChunk #-} + updateChunk ctx = updateChunk ctx . fmap (fromIntegral :: CUInt -> CSize) + +instance Digestable (Ptr a, CInt) where + {-# INLINE updateChunk #-} + updateChunk ctx = updateChunk ctx . fmap (fromIntegral :: CInt -> CSize) + +instance Digestable (Ptr a, Int) where + {-# INLINE updateChunk #-} + updateChunk ctx = updateChunk ctx . fmap (fromIntegral :: Int -> CSize) + +instance Digestable [Word8] where + {-# INLINE updateChunk #-} + updateChunk ctx buf = withArrayLen buf $ \len ptr -> updateChunk ctx (ptr,len) + +instance Digestable StrictByteString where + {-# INLINE updateChunk #-} + updateChunk ctx str = unsafeUseAsCStringLen str (updateChunk ctx) + +instance Digestable LazyByteString where + {-# INLINE updateChunk #-} + updateChunk ctx = mapM_ (updateChunk ctx) . Lazy.toChunks + +-- |We do /not/ define a 'Digestable' instance for 'String', because there is +-- no one obviously correct way to encode Unicode characters for purposes of +-- calculating a digest. We have, however, this specialized function which +-- computes a digest over a @String@ by means of 'withCStrinLen'. This means +-- that the representation of Unicode characters depends on the process locale +-- a.k.a. it's non-deterministc! +-- +-- >>> toHex $ digestString (digestByName "sha1") "Hello, world." +-- "2ae01472317d1935a84797ec1983ae243fc6aa28" + +digestString :: Algorithm -> String -> MessageDigest +digestString algo str = IO.unsafePerformIO $ + withCStringLen str (return . digest algo) + +-- Helper functions ----------------------------------------------------------- + +-- | Synonym for the strict 'Strict.ByteString' variant to improve readability. + +type StrictByteString = Strict.ByteString + +-- | Synonym for the lazy 'Lazy.ByteString' variant to improve readability. + +type LazyByteString = Lazy.ByteString + +-- | Pretty-print a given message digest from binary into hexadecimal +-- representation. +-- +-- >>> toHex (Data.ByteString.pack [0..15]) +-- "000102030405060708090a0b0c0d0e0f" + +toHex :: MessageDigest -> StrictByteString +toHex = Strict.concatMap (pack . Util.toHex) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hopenssl-1.7/src/OpenSSL/EVP/Digest/Algorithm.hsc new/hopenssl-2.2.1/src/OpenSSL/EVP/Digest/Algorithm.hsc --- old/hopenssl-1.7/src/OpenSSL/EVP/Digest/Algorithm.hsc 1970-01-01 01:00:00.000000000 +0100 +++ new/hopenssl-2.2.1/src/OpenSSL/EVP/Digest/Algorithm.hsc 2017-07-07 13:30:48.000000000 +0200 @@ -0,0 +1,100 @@ +{-# LANGUAGE ForeignFunctionInterface #-} + +{- | + Maintainer: simons@cryp.to + Stability: provisional + Portability: portable + + Low-level bindings to OpenSSL's EVP interface. Most users do not need this + code. Check out "OpenSSL.Digest" for a more comfortable interface. +-} + +module OpenSSL.EVP.Digest.Algorithm where + +import OpenSSL.EVP.Digest.Initialization +import OpenSSL.EVP.Digest.Error ( UnknownAlgorithm(..) ) + +import Control.Exception +import Data.Maybe +import Data.String ( IsString(..) ) +import Foreign +import Foreign.C +import System.IO.Unsafe as IO + +#include "openssl/opensslv.h" +#include "openssl/evp.h" + +-- | An opaque handle into OpenSSL's collection of message digest algorithms. +-- Use 'digestByName' to look up any of the available algorithms by name. For +-- the sake of convenience, 'Algorithm' is an instance of 'IsString' so +-- that the compiler can transparently map 'String' literals to algorithms via +-- 'fromString' if the @XOverloadedStrings@ extension is enabled. +-- +-- >>> fromString "sha256" == digestByName "sha256" +-- True + +newtype Algorithm = Algorithm (Ptr ()) + deriving (Show, Eq) + +instance IsString Algorithm where + fromString = digestByName + +-- | Look up a digest algorithm engine by name. Algorithms usually offered by +-- OpenSSL are "md2", "md5", "sha1", "mdc2", "ripemd160", "blake2b512", +-- "blake2s256", "sha224", "sha256", "sha384", and "sha512", but the exact set +-- may vary between platforms. Throws 'UnknownAlgorithm' if the requested +-- algorithm is not known. + +digestByName :: String -> Algorithm +digestByName algo = + fromMaybe (throw (UnknownAlgorithm algo)) (digestByName' algo) + +-- | Variant of 'digestByName' that signals failure by evaluating to 'Nothing' +-- rather than failing. +-- +-- >>> digestByName' "sha256" == Just (digestByName "sha256") +-- True +-- >>> digestByName' "Guess what?" :: Maybe Algorithm +-- Nothing + +digestByName' :: String -> Maybe Algorithm +digestByName' algo = do + let Algorithm p = IO.unsafePerformIO $ do + initializeEVPDigests + withCString algo (return . _digestByName) + if p == nullPtr then Nothing else Just (Algorithm p) + +-- | Return the size of the digest in bytes that the given algorithm will produce. +-- +-- >>> digestSize (digestByName "sha256") +-- 32 + +digestSize :: Algorithm -> Int +digestSize = fromIntegral . _digestSize + +-- | The largest possible digest size of any of the algorithms supported by +-- this library will generate. So if you want to store a digest without +-- bothering to retrieve the appropriate size with 'digestSize' first, allocate +-- a buffer of that size. + +maxDigestSize :: Int +maxDigestSize = #{const EVP_MAX_MD_SIZE} + +-- | Return the block size the the given algorithm operates with. +-- +-- >>> digestBlockSize (digestByName "sha256") +-- 64 + +digestBlockSize :: Algorithm -> Int +digestBlockSize = fromIntegral . _digestBlockSize + +------------------------------------------------------------------------------- + +foreign import ccall unsafe "openssl/evp.h EVP_get_digestbyname" + _digestByName :: CString -> Algorithm + +foreign import ccall unsafe "openssl/evp.h EVP_MD_size" + _digestSize :: Algorithm -> CInt + +foreign import ccall unsafe "openssl/evp.h EVP_MD_block_size" + _digestBlockSize :: Algorithm -> CInt diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hopenssl-1.7/src/OpenSSL/EVP/Digest/Context.hs new/hopenssl-2.2.1/src/OpenSSL/EVP/Digest/Context.hs --- old/hopenssl-1.7/src/OpenSSL/EVP/Digest/Context.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/hopenssl-2.2.1/src/OpenSSL/EVP/Digest/Context.hs 2017-07-07 13:30:48.000000000 +0200 @@ -0,0 +1,68 @@ +{-# LANGUAGE ForeignFunctionInterface #-} +{-# LANGUAGE CPP #-} + +{- | + Maintainer: simons@cryp.to + Stability: provisional + Portability: portable + + Low-level bindings to OpenSSL's EVP interface. Most users do not need this + code. Check out "OpenSSL.Digest" for a more comfortable interface. +-} + +module OpenSSL.EVP.Digest.Context where + +import OpenSSL.EVP.Digest.Error ( throwIfZero ) + +import Control.Monad +import Foreign +import Foreign.C + +#include "openssl/opensslv.h" + +-- | A context for digest computations. Use 'newContext' and 'freeContext' to +-- allocate/deallocate this type. + +newtype Context = Context (Ptr ()) + deriving (Show, Eq) + +-- | Allocate and initialize an 'Context' for use in a digest computation +-- on the heap. Release its underlying memory after use with 'freeContext'. + +newContext :: IO Context +newContext = do ctx@(Context p) <- _newContext + when (p == nullPtr) (fail "OpenSSL.EVP.Digest.Context.newContext failed") + return ctx + +foreign import ccall unsafe +#if OPENSSL_VERSION_NUMBER < 0x1010000f + "openssl/evp.h EVP_MD_CTX_create" +#else + "openssl/evp.h EVP_MD_CTX_new" +#endif + _newContext :: IO Context + +-- | Release all resources associated with a digest computation. + +foreign import ccall unsafe +#if OPENSSL_VERSION_NUMBER < 0x1010000f + "openssl/evp.h EVP_MD_CTX_destroy" +#else + "openssl/evp.h EVP_MD_CTX_free" +#endif + freeContext :: Context -> IO () + +-- | Free all resources associated with this 'Context', but don't destroy the +-- context itself so that it can be re-used for a new digest computation. + +resetDigest :: Context -> IO () +resetDigest ctx = + throwIfZero "OpenSSL.EVP.Digest.resetDigest" (_resetContext ctx) + +foreign import ccall unsafe +#if OPENSSL_VERSION_NUMBER < 0x1010000f + "openssl/evp.h EVP_MD_CTX_cleanup" +#else + "openssl/evp.h EVP_MD_CTX_reset" +#endif + _resetContext :: Context -> IO CInt diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hopenssl-1.7/src/OpenSSL/EVP/Digest/Digest.hs new/hopenssl-2.2.1/src/OpenSSL/EVP/Digest/Digest.hs --- old/hopenssl-1.7/src/OpenSSL/EVP/Digest/Digest.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/hopenssl-2.2.1/src/OpenSSL/EVP/Digest/Digest.hs 2017-07-07 13:30:48.000000000 +0200 @@ -0,0 +1,67 @@ +{-# LANGUAGE ForeignFunctionInterface #-} +{-# LANGUAGE EmptyDataDecls #-} + +{- | + Maintainer: simons@cryp.to + Stability: provisional + Portability: portable + + Low-level bindings to OpenSSL's EVP interface. Most users do not need this + code. Check out "OpenSSL.Digest" for a more comfortable interface. +-} + +module OpenSSL.EVP.Digest.Digest where + +import OpenSSL.EVP.Digest.Algorithm +import OpenSSL.EVP.Digest.Context +import OpenSSL.EVP.Digest.Error ( throwIfZero ) + +import Foreign +import Foreign.C + +-- | Configure the given digest context to use the given message digest +-- algorithm. Throws an exception to signal failure, i.e. because the system is +-- out of memory. + +initDigest :: Algorithm -> Context -> IO () +initDigest algo ctx = + throwIfZero "OpenSSL.EVP.Digest.initDigest" (_initDigest ctx algo nullPtr) + +-- | Hash the given block of memory and update the digest state accordingly. +-- This function can be called many times. Then use 'finalizeDigest' to +-- retrieve the actual hash value. + +updateDigest :: Context -> Ptr a -> CSize -> IO () +updateDigest ctx ptr len = + throwIfZero "OpenSSL.EVP.Digest.updateDigest" (_updateDigest ctx ptr len) + +-- | Finalize the digest calculation and return the result in the 'Word8' array +-- passed as an argument. Naturally, that array is expected to be large enough +-- to contain the digest. 'digestSize' or 'maxDigestSize' are your friends. +-- This function does /not/ clean up the digest context; this has to be done +-- with an explicit call to 'freeContext' (or 'resetContext', if you want to +-- re-use it). However, it does invalidate the digest state so that no further +-- calls of 'digestUpdate' can be made without re-initializing the context +-- first. + +finalizeDigest :: Context -> Ptr Word8 -> IO () +finalizeDigest ctx ptr = + throwIfZero "OpenSSL.EVP.Digest.finalizeDigest" (_finalizeDigest ctx ptr nullPtr) + +------------------------------------------------------------------------------- + +-- | We don't support choosing a custom engine to implement the given +-- algorithm. This type is just a place holder, and we always pass 'nullPtr' +-- whereever it is required to let OpenSSL choose whatever engine it thinks is +-- best. + +data OpaqueEngine + +foreign import ccall unsafe "openssl/evp.h EVP_DigestInit_ex" + _initDigest :: Context -> Algorithm -> Ptr OpaqueEngine -> IO CInt + +foreign import ccall unsafe "openssl/evp.h EVP_DigestUpdate" + _updateDigest :: Context -> Ptr a -> CSize -> IO CInt + +foreign import ccall unsafe "openssl/evp.h EVP_DigestFinal_ex" + _finalizeDigest :: Context -> Ptr Word8 -> Ptr CUInt -> IO CInt diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hopenssl-1.7/src/OpenSSL/EVP/Digest/Error.hs new/hopenssl-2.2.1/src/OpenSSL/EVP/Digest/Error.hs --- old/hopenssl-1.7/src/OpenSSL/EVP/Digest/Error.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/hopenssl-2.2.1/src/OpenSSL/EVP/Digest/Error.hs 2017-07-07 13:30:48.000000000 +0200 @@ -0,0 +1,33 @@ +{-# LANGUAGE DeriveDataTypeable #-} + +{- | + Maintainer: simons@cryp.to + Stability: provisional + Portability: portable + + Low-level bindings to OpenSSL's EVP interface. Most users do not need this + code. Check out "OpenSSL.Digest" for a more comfortable interface. +-} + +module OpenSSL.EVP.Digest.Error where + +import Control.Exception +import Data.Typeable ( Typeable ) +import Foreign +import Foreign.C + +-- | Most OpenSSL functions return an approximation of @Bool@ to signify +-- failure. This wrapper makes it easier to move the error handling to the +-- exception layer where appropriate. + +throwIfZero :: String -> IO CInt -> IO () +throwIfZero fname = + throwIf_ (==0) (const (showString fname " failed with error code 0")) + +-- | A custom exception type which is thrown by 'digestByName' in case the +-- requested digest algorithm is not available in the OpenSSL system library. + +newtype UnknownAlgorithm = UnknownAlgorithm String + deriving (Show, Typeable) + +instance Exception UnknownAlgorithm diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hopenssl-1.7/src/OpenSSL/EVP/Digest/Initialization.hs new/hopenssl-2.2.1/src/OpenSSL/EVP/Digest/Initialization.hs --- old/hopenssl-1.7/src/OpenSSL/EVP/Digest/Initialization.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/hopenssl-2.2.1/src/OpenSSL/EVP/Digest/Initialization.hs 2017-07-07 13:30:48.000000000 +0200 @@ -0,0 +1,41 @@ +{-# LANGUAGE CPP #-} +{-# LANGUAGE ForeignFunctionInterface #-} + +{- | + Maintainer: simons@cryp.to + Stability: provisional + Portability: portable + + Low-level bindings to OpenSSL's EVP interface. Most users do not need this + code. Check out "OpenSSL.Digest" for a more comfortable interface. +-} + +module OpenSSL.EVP.Digest.Initialization ( initializeEVPDigests ) where + +import Control.Concurrent.MVar +import Control.Monad +import System.IO.Unsafe as IO + +#include "openssl/opensslv.h" + +-- | Initialize the OpenSSL EVP engine and register all known digest types in +-- the internal data structures. This function must be called before any of the +-- message digest functions can succeed. This is generally handled +-- transparently by the Haskell implementation and users do not need to worry +-- about this. + +initializeEVPDigests :: IO () +initializeEVPDigests = +#if OPENSSL_VERSION_NUMBER >= 0x1010000f + return () +#else + modifyMVar_ isDigestEngineInitialized $ \isInitialized -> + unless isInitialized _addAllDigests >> return True + +{-# NOINLINE isDigestEngineInitialized #-} +isDigestEngineInitialized :: MVar Bool +isDigestEngineInitialized = IO.unsafePerformIO $ newMVar False + +foreign import ccall unsafe "openssl/evp.h OpenSSL_add_all_digests" _addAllDigests :: IO () + +#endif diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hopenssl-1.7/src/OpenSSL/EVP/Digest.hs new/hopenssl-2.2.1/src/OpenSSL/EVP/Digest.hs --- old/hopenssl-1.7/src/OpenSSL/EVP/Digest.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/hopenssl-2.2.1/src/OpenSSL/EVP/Digest.hs 2017-07-07 13:30:48.000000000 +0200 @@ -0,0 +1,26 @@ +{- | + Maintainer: simons@cryp.to + Stability: provisional + Portability: portable + + Low-level bindings to OpenSSL's EVP interface. Most users do not need this + code. Check out "OpenSSL.Digest" for a more comfortable interface. +-} + +module OpenSSL.EVP.Digest + ( + -- * Digest Algorithms + Algorithm + , digestByName, digestByName', digestSize, maxDigestSize, digestBlockSize + , UnknownAlgorithm + , -- * Digest Contexts + Context, newContext, freeContext, resetDigest + , -- * Digest Computations + initDigest, updateDigest, finalizeDigest + ) + where + +import OpenSSL.EVP.Digest.Algorithm +import OpenSSL.EVP.Digest.Context +import OpenSSL.EVP.Digest.Digest +import OpenSSL.EVP.Digest.Error diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hopenssl-1.7/src/OpenSSL/Util.hs new/hopenssl-2.2.1/src/OpenSSL/Util.hs --- old/hopenssl-1.7/src/OpenSSL/Util.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/hopenssl-2.2.1/src/OpenSSL/Util.hs 2017-07-07 13:30:48.000000000 +0200 @@ -0,0 +1,24 @@ +{- | + Maintainer: simons@cryp.to + Stability: provisional + Portability: portable + + Random collection of utility functions that may be useful, but which aren't + useful enough to be included in the main API modules. +-} + +module OpenSSL.Util where + +import Data.Word +import Numeric + +-- |Neat helper to pretty-print digests into the common hexadecimal notation: +-- +-- >>> [0..15] >>= toHex +-- "000102030405060708090a0b0c0d0e0f" + +toHex :: Word8 -> String +toHex w = case showHex w "" of + [w1,w2] -> [w1, w2] + [w2] -> ['0', w2] + _ -> "showHex returned []" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hopenssl-1.7/test/CheckHighLevelDigestAPI.hs new/hopenssl-2.2.1/test/CheckHighLevelDigestAPI.hs --- old/hopenssl-1.7/test/CheckHighLevelDigestAPI.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/hopenssl-2.2.1/test/CheckHighLevelDigestAPI.hs 2017-07-07 13:30:48.000000000 +0200 @@ -0,0 +1,18 @@ +module Main ( main ) where + +import OpenSSL.Digest +import OpenSesame + +import Test.HUnit + +main :: IO () +main = runTestTT (TestList tests) >> return () + +tests :: [Test] +tests = map (uncurry (mkTest "open sesame")) opensesame + +mkTest :: String -> String -> String -> Test +mkTest input algoName expect = TestCase $ + case digestByName' algoName of + Nothing -> return () + Just algo -> assertEqual algoName expect (show (toHex (digestString algo input))) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hopenssl-1.7/test/CheckLowLevelDigestAPI.hs new/hopenssl-2.2.1/test/CheckLowLevelDigestAPI.hs --- old/hopenssl-1.7/test/CheckLowLevelDigestAPI.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/hopenssl-2.2.1/test/CheckLowLevelDigestAPI.hs 2017-07-07 13:30:48.000000000 +0200 @@ -0,0 +1,34 @@ +module Main ( main ) where + +import OpenSesame + +import OpenSSL.EVP.Digest +import OpenSSL.Util + +import Control.Exception +import Foreign +import Foreign.C.String +import Test.HUnit + +main :: IO () +main = runTestTT (TestList tests) >> return () + +tests :: [Test] +tests = map (uncurry (mkTest "open sesame")) opensesame + +mkTest :: String -> String -> String -> Test +mkTest input algoName expect = TestCase $ + case digestByName' algoName of + Nothing -> return () + Just algo -> digest algo input >>= assertEqual algoName expect + +digest :: Algorithm -> String -> IO String +digest algo input = do + let mdSize = digestSize algo + md <- bracket newContext freeContext $ \ctx -> do + initDigest algo ctx + withCStringLen input $ \(ptr,len) -> updateDigest ctx ptr (fromIntegral len) + allocaArray mdSize $ \md -> do + finalizeDigest ctx md + peekArray mdSize md + return (md >>= toHex) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hopenssl-1.7/test/OpenSesame.hs new/hopenssl-2.2.1/test/OpenSesame.hs --- old/hopenssl-1.7/test/OpenSesame.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/hopenssl-2.2.1/test/OpenSesame.hs 2017-07-07 13:30:48.000000000 +0200 @@ -0,0 +1,15 @@ +module OpenSesame where + +opensesame :: [(String, String)] +opensesame = [ ("MD5", "54ef36ec71201fdf9d1423fd26f97f6b") + , ("SHA", "2ccefef64c76ac0d42ca1657457977675890c42f") + , ("SHA1", "5bcaff7f22ff533ca099b3408ead876c0ebba9a7") + , ("DSS", "5bcaff7f22ff533ca099b3408ead876c0ebba9a7") + , ("DSS1", "5bcaff7f22ff533ca099b3408ead876c0ebba9a7") + , ("RIPEMD160", "bdb2bba6ec93bd566dc1181cadbc92176aa78382") + , ("MDC2", "112db2200ce1e9db3c2d132aea4ef7d0") + , ("SHA224", "1ee0f9d93a873a67fe781852d716cb3e5904e015aafaa4d1ff1a81bc") + , ("SHA256", "41ef4bb0b23661e66301aac36066912dac037827b4ae63a7b1165a5aa93ed4eb") + , ("SHA384", "ae2a5d6649035c00efe2bc1b5c97f4d5ff97fa2df06f273afa0231c425e8aff30e4cc1db5e5756e8d2245a1514ad1a2d") + , ("SHA512", "8470cdd3bf1ef85d5f092bce5ae5af97ce50820481bf43b2413807fec37e2785b533a65d4c7d71695b141d81ebcd4b6c4def4284e6067f0b9ddc318b1b230205") + ] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hopenssl-1.7/test/doctests.hs new/hopenssl-2.2.1/test/doctests.hs --- old/hopenssl-1.7/test/doctests.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/hopenssl-2.2.1/test/doctests.hs 2017-07-07 13:30:48.000000000 +0200 @@ -0,0 +1,10 @@ +module Main where + +import Build_doctests (flags, pkgs, module_sources) +import Data.Foldable (traverse_) +import Test.DocTest (doctest) + +main :: IO () +main = do let args = flags ++ pkgs ++ module_sources + traverse_ putStrLn args -- optionally print arguments + doctest args
participants (1)
-
root@hilbert.suse.de