module Network.Minio.Data.Crypto
( hashSHA256,
hashSHA256FromSource,
hashMD5,
hashMD5ToBase64,
hashMD5FromSource,
hmacSHA256,
hmacSHA256RawBS,
digestToBS,
digestToBase16,
encodeToBase64,
)
where
import Crypto.Hash
( Digest,
MD5 (..),
SHA256 (..),
hashWith,
)
import Crypto.Hash.Conduit (sinkHash)
import Crypto.MAC.HMAC (HMAC, hmac)
import Data.ByteArray (ByteArrayAccess, convert)
import Data.ByteArray.Encoding (Base (Base16, Base64), convertToBase)
import qualified Data.Conduit as C
hashSHA256 :: ByteString -> ByteString
hashSHA256 :: ByteString -> ByteString
hashSHA256 = forall a. ByteArrayAccess a => a -> ByteString
digestToBase16 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall ba alg.
(ByteArrayAccess ba, HashAlgorithm alg) =>
alg -> ba -> Digest alg
hashWith SHA256
SHA256
hashSHA256FromSource :: (Monad m) => C.ConduitM () ByteString m () -> m ByteString
hashSHA256FromSource :: forall (m :: * -> *).
Monad m =>
ConduitM () ByteString m () -> m ByteString
hashSHA256FromSource ConduitM () ByteString m ()
src = do
Digest SHA256
digest <- forall (m :: * -> *) a r.
Monad m =>
ConduitT () a m () -> ConduitT a Void m r -> m r
C.connect ConduitM () ByteString m ()
src forall (m :: * -> *).
Monad m =>
ConduitM ByteString Void m (Digest SHA256)
sinkSHA256Hash
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. ByteArrayAccess a => a -> ByteString
digestToBase16 Digest SHA256
digest
where
sinkSHA256Hash :: (Monad m) => C.ConduitM ByteString Void m (Digest SHA256)
sinkSHA256Hash :: forall (m :: * -> *).
Monad m =>
ConduitM ByteString Void m (Digest SHA256)
sinkSHA256Hash = forall (m :: * -> *) hash.
(Monad m, HashAlgorithm hash) =>
Consumer ByteString m (Digest hash)
sinkHash
hashMD5 :: ByteString -> ByteString
hashMD5 :: ByteString -> ByteString
hashMD5 = forall a. ByteArrayAccess a => a -> ByteString
digestToBase16 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall ba alg.
(ByteArrayAccess ba, HashAlgorithm alg) =>
alg -> ba -> Digest alg
hashWith MD5
MD5
hashMD5FromSource :: (Monad m) => C.ConduitM () ByteString m () -> m ByteString
hashMD5FromSource :: forall (m :: * -> *).
Monad m =>
ConduitM () ByteString m () -> m ByteString
hashMD5FromSource ConduitM () ByteString m ()
src = do
Digest MD5
digest <- forall (m :: * -> *) a r.
Monad m =>
ConduitT () a m () -> ConduitT a Void m r -> m r
C.connect ConduitM () ByteString m ()
src forall (m :: * -> *).
Monad m =>
ConduitM ByteString Void m (Digest MD5)
sinkMD5Hash
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. ByteArrayAccess a => a -> ByteString
digestToBase16 Digest MD5
digest
where
sinkMD5Hash :: (Monad m) => C.ConduitM ByteString Void m (Digest MD5)
sinkMD5Hash :: forall (m :: * -> *).
Monad m =>
ConduitM ByteString Void m (Digest MD5)
sinkMD5Hash = forall (m :: * -> *) hash.
(Monad m, HashAlgorithm hash) =>
Consumer ByteString m (Digest hash)
sinkHash
hmacSHA256 :: ByteString -> ByteString -> HMAC SHA256
hmacSHA256 :: ByteString -> ByteString -> HMAC SHA256
hmacSHA256 ByteString
message ByteString
key = forall key message a.
(ByteArrayAccess key, ByteArrayAccess message, HashAlgorithm a) =>
key -> message -> HMAC a
hmac ByteString
key ByteString
message
hmacSHA256RawBS :: ByteString -> ByteString -> ByteString
hmacSHA256RawBS :: ByteString -> ByteString -> ByteString
hmacSHA256RawBS ByteString
message ByteString
key = forall bin bout.
(ByteArrayAccess bin, ByteArray bout) =>
bin -> bout
convert forall a b. (a -> b) -> a -> b
$ ByteString -> ByteString -> HMAC SHA256
hmacSHA256 ByteString
message ByteString
key
digestToBS :: (ByteArrayAccess a) => a -> ByteString
digestToBS :: forall a. ByteArrayAccess a => a -> ByteString
digestToBS = forall bin bout.
(ByteArrayAccess bin, ByteArray bout) =>
bin -> bout
convert
digestToBase16 :: (ByteArrayAccess a) => a -> ByteString
digestToBase16 :: forall a. ByteArrayAccess a => a -> ByteString
digestToBase16 = forall bin bout.
(ByteArrayAccess bin, ByteArray bout) =>
Base -> bin -> bout
convertToBase Base
Base16
hashMD5ToBase64 :: (ByteArrayAccess a) => a -> ByteString
hashMD5ToBase64 :: forall a. ByteArrayAccess a => a -> ByteString
hashMD5ToBase64 = forall bin bout.
(ByteArrayAccess bin, ByteArray bout) =>
Base -> bin -> bout
convertToBase Base
Base64 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall ba alg.
(ByteArrayAccess ba, HashAlgorithm alg) =>
alg -> ba -> Digest alg
hashWith MD5
MD5
encodeToBase64 :: (ByteArrayAccess a) => a -> ByteString
encodeToBase64 :: forall a. ByteArrayAccess a => a -> ByteString
encodeToBase64 = forall bin bout.
(ByteArrayAccess bin, ByteArray bout) =>
Base -> bin -> bout
convertToBase Base
Base64