-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/

-- | Conduit interface for cryptographic operations (from crypto-api).
--   
--   This package contains everything that you need to use a cryptographic
--   package that supports the crypto-api package using conduits
--   from the conduit package.
@package crypto-conduit
@version 0.5.2.1

-- | This module contains wrappers for cryptographic functions using the
--   conduit package. Currently there is support for hashes, HMACs
--   and many modes of block ciphers (but not everything
--   crypto-api supports has a counterpart here). All functions on
--   this package work in constant memory.
module Crypto.Conduit

-- | A Sink that hashes a stream of ByteStrings and
--   creates a digest d.
sinkHash :: (Monad m, Hash ctx d) => Consumer ByteString m d

-- | Hashes the whole contents of the given file in constant memory. This
--   function is just a convenient wrapper around sinkHash defined
--   as:
--   
--   
--   hashFile fp = liftIO $ runResourceT (sourceFile fp $$ sinkHash)
--   
hashFile :: (MonadIO m, Hash ctx d) => FilePath -> m d

-- | A Sink that computes the HMAC of a stream of
--   ByteStrings and creates a digest d.
sinkHmac :: (Monad m, Hash ctx d) => MacKey ctx d -> Consumer ByteString m d

-- | A Conduit that encrypts a stream of ByteStrings
--   using ECB mode. Expects the input length to be a multiple of the block
--   size of the cipher and fails otherwise. (Note that ECB has many
--   undesirable cryptographic properties, please avoid it if you don't
--   know what you're doing.)
conduitEncryptEcb :: (Monad m, BlockCipher k) => k -> Conduit ByteString m ByteString

-- | A Conduit that decrypts a stream of ByteStrings
--   using ECB mode. Expects the input length to be a multiple of the block
--   size of the cipher and fails otherwise.
conduitDecryptEcb :: (Monad m, BlockCipher k) => k -> Conduit ByteString m ByteString

-- | A Conduit that encrypts a stream of ByteStrings
--   using CBC mode. Expects the input length to be a multiple of the block
--   size of the cipher and fails otherwise.
conduitEncryptCbc :: (Monad m, BlockCipher k) => k -> IV k -> Conduit ByteString m ByteString

-- | A Conduit that decrypts a stream of ByteStrings
--   using CBC mode. Expects the input length to be a multiple of the block
--   size of the cipher and fails otherwise.
conduitDecryptCbc :: (Monad m, BlockCipher k) => k -> IV k -> Conduit ByteString m ByteString

-- | A Conduit that encrypts a stream of ByteStrings
--   using CFB mode. Expects the input length to be a multiple of the block
--   size of the cipher and fails otherwise.
conduitEncryptCfb :: (Monad m, BlockCipher k) => k -> IV k -> Conduit ByteString m ByteString

-- | A Conduit that decrypts a stream of ByteStrings
--   using CFB mode. Expects the input length to be a multiple of the block
--   size of the cipher and fails otherwise.
conduitDecryptCfb :: (Monad m, BlockCipher k) => k -> IV k -> Conduit ByteString m ByteString

-- | A Conduit that encrypts a stream of ByteStrings
--   using OFB mode. Expects the input length to be a multiple of the block
--   size of the cipher and fails otherwise.
conduitEncryptOfb :: (Monad m, BlockCipher k) => k -> IV k -> Conduit ByteString m ByteString

-- | Synonym for conduitEncryptOfb, since for OFB mode both
--   encryption and decryption are the same.
conduitDecryptOfb :: (Monad m, BlockCipher k) => k -> IV k -> Conduit ByteString m ByteString

-- | A Conduit that encrypts a stream of ByteStrings
--   using CTR mode. The input may have any length, even non-multiples of
--   the block size.
conduitEncryptCtr :: (Monad m, BlockCipher k) => k -> IV k -> (IV k -> IV k) -> Conduit ByteString m ByteString

-- | Synonym for conduitEncryptCtr, since for CTR mode both
--   encryption and decryption are the same.
conduitDecryptCtr :: (Monad m, BlockCipher k) => k -> IV k -> (IV k -> IV k) -> Conduit ByteString m ByteString

-- | An infinite stream of bytes generated by a block cipher on CTR mode.
sourceCtr :: (Monad m, BlockCipher k) => k -> IV k -> Producer m ByteString

-- | A Sink that computes the CBC-MAC of a stream of
--   ByteStrings and creates a digest (already encoded in a
--   ByteString, since we're using a block cipher). Expects the
--   input length to be a multiple of the block size of the cipher and
--   fails otherwise. (Note that CBC-MAC is not secure for variable-length
--   messages.)
sinkCbcMac :: (Monad m, BlockCipher k) => k -> Consumer ByteString m ByteString

-- | A Conduit that takes arbitrary ByteStrings and
--   outputs Blocks. Each Full block will have a
--   length that is multiple of the given block size (either exactly the
--   block size or a multiple of at least 1x the block size, depending on
--   the BlockMode). All Blocks beside the last one
--   will be Full. The last block will always be LastOne with
--   less bytes than the block size, possibly zero.
blocked :: Monad m => BlockMode -> ByteLength -> Conduit ByteString m Block

-- | How Blocks should be returned, either with strictly the block
--   size or with a multiple of at least 1x the block size.
data BlockMode
StrictBlockSize :: BlockMode
AnyMultiple :: BlockMode

-- | A block returned by blocked.
data Block
Full :: ByteString -> Block
LastOne :: ByteString -> Block
instance Eq BlockMode
instance Ord BlockMode
instance Show BlockMode
instance Enum BlockMode
instance Eq Block
instance Ord Block
instance Show Block
