module Botan.Hash.MD4
( MD4(..)
, MD4Digest(..)
, md4
, md4Lazy
) where

import qualified Data.ByteString as ByteString
import qualified Data.ByteString.Lazy as Lazy
import qualified Data.Text as Text

import qualified Botan.Hash as Botan
import qualified Botan.Utility as Botan

import Botan.Hash.Class
import Botan.Prelude

-- MD4 type

data MD4

newtype instance Digest MD4 = MD4Digest
    { Digest MD4 -> ByteString
getMD4ByteString :: ByteString {- ByteVector n -} }
    deriving newtype (Digest MD4 -> Digest MD4 -> Bool
(Digest MD4 -> Digest MD4 -> Bool)
-> (Digest MD4 -> Digest MD4 -> Bool) -> Eq (Digest MD4)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Digest MD4 -> Digest MD4 -> Bool
== :: Digest MD4 -> Digest MD4 -> Bool
$c/= :: Digest MD4 -> Digest MD4 -> Bool
/= :: Digest MD4 -> Digest MD4 -> Bool
Eq, Eq (Digest MD4)
Eq (Digest MD4) =>
(Digest MD4 -> Digest MD4 -> Ordering)
-> (Digest MD4 -> Digest MD4 -> Bool)
-> (Digest MD4 -> Digest MD4 -> Bool)
-> (Digest MD4 -> Digest MD4 -> Bool)
-> (Digest MD4 -> Digest MD4 -> Bool)
-> (Digest MD4 -> Digest MD4 -> Digest MD4)
-> (Digest MD4 -> Digest MD4 -> Digest MD4)
-> Ord (Digest MD4)
Digest MD4 -> Digest MD4 -> Bool
Digest MD4 -> Digest MD4 -> Ordering
Digest MD4 -> Digest MD4 -> Digest MD4
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Digest MD4 -> Digest MD4 -> Ordering
compare :: Digest MD4 -> Digest MD4 -> Ordering
$c< :: Digest MD4 -> Digest MD4 -> Bool
< :: Digest MD4 -> Digest MD4 -> Bool
$c<= :: Digest MD4 -> Digest MD4 -> Bool
<= :: Digest MD4 -> Digest MD4 -> Bool
$c> :: Digest MD4 -> Digest MD4 -> Bool
> :: Digest MD4 -> Digest MD4 -> Bool
$c>= :: Digest MD4 -> Digest MD4 -> Bool
>= :: Digest MD4 -> Digest MD4 -> Bool
$cmax :: Digest MD4 -> Digest MD4 -> Digest MD4
max :: Digest MD4 -> Digest MD4 -> Digest MD4
$cmin :: Digest MD4 -> Digest MD4 -> Digest MD4
min :: Digest MD4 -> Digest MD4 -> Digest MD4
Ord)

type MD4Digest = Digest MD4

instance Show (Digest MD4) where
    show :: Digest MD4 -> String
    show :: Digest MD4 -> String
show (MD4Digest ByteString
bytes) = Text -> String
Text.unpack (Text -> String) -> Text -> String
forall a b. (a -> b) -> a -> b
$ ByteString -> HexCase -> Text
Botan.hexEncode ByteString
bytes HexCase
Botan.Lower

instance Hash MD4 where
    hash :: ByteString -> Digest MD4
    hash :: ByteString -> Digest MD4
hash = ByteString -> Digest MD4
MD4Digest (ByteString -> Digest MD4)
-> (ByteString -> ByteString) -> ByteString -> Digest MD4
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hash -> ByteString -> ByteString
Botan.hash Hash
Botan.md4

instance IncrementalHash MD4 where
    hashLazy :: Lazy.ByteString -> Digest MD4
    hashLazy :: ByteString -> Digest MD4
hashLazy = ByteString -> Digest MD4
MD4Digest (ByteString -> Digest MD4)
-> (ByteString -> ByteString) -> ByteString -> Digest MD4
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hash -> ByteString -> ByteString
Botan.hashLazy Hash
Botan.md4

-- MD4 hash

md4 :: ByteString -> MD4Digest
md4 :: ByteString -> Digest MD4
md4 = ByteString -> Digest MD4
forall hash. Hash hash => ByteString -> Digest hash
hash

md4Lazy :: Lazy.ByteString -> MD4Digest
md4Lazy :: ByteString -> Digest MD4
md4Lazy = ByteString -> Digest MD4
forall hash. IncrementalHash hash => ByteString -> Digest hash
hashLazy