<commit_before>-- |
-- Module      : Crypto.Cipher.Types.AEAD
-- License     : BSD-style
-- Maintainer  : <NAME> <<EMAIL>>
-- Stability   : Stable
-- Portability : Excellent
--
-- AEAD cipher basic types
--
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE Rank2Types #-}
module Crypto.Cipher.Types.AEAD where

import           Crypto.Cipher.Types.Base
import           Crypto.Internal.ByteArray (ByteArrayAccess, ByteArray)
import qualified Crypto.Internal.ByteArray as B
import           Crypto.Internal.Imports

-- | AEAD Implementation
data AEADModeImpl st = AEADModeImpl
    { aeadImplAppendHeader :: forall ba . ByteArrayAccess ba => st -> ba -> st
    , aeadImplEncrypt      :: forall ba . ByteArray ba => st -> ba -> (ba, st)
    , aeadImplDecrypt      :: forall ba . ByteArray ba => st -> ba -> (ba, st)
    , aeadImplFinalize     :: st -> Int -> AuthTag
    }

-- | Authenticated Encryption with Associated Data algorithms
data AEAD cipher = forall st . AEAD
    { aeadModeImpl :: AEADModeImpl st
    , aeadState    :: st
    }

-- | Append some header information to an AEAD context
aeadAppendHeader :: ByteArrayAccess aad => AEAD cipher -> aad -> AEAD cipher
aeadAppendHeader (AEAD impl st) aad = AEAD impl $ (aeadImplAppendHeader impl) st aad
<commit_msg>Avoid thunk leak with AEAD state<commit_after>-- |
-- Module      : Crypto.Cipher.Types.AEAD
-- License     : BSD-style
-- Maintainer  : <NAME> <<EMAIL>>
-- Stability   : Stable
-- Portability : Excellent
--
-- AEAD cipher basic types
--
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE Rank2Types #-}
module Crypto.Cipher.Types.AEAD where

import           Crypto.Cipher.Types.Base
import           Crypto.Internal.ByteArray (ByteArrayAccess, ByteArray)
import qualified Crypto.Internal.ByteArray as B
import           Crypto.Internal.Imports

-- | AEAD Implementation
data AEADModeImpl st = AEADModeImpl
    { aeadImplAppendHeader :: forall ba . ByteArrayAccess ba => st -> ba -> st
    , aeadImplEncrypt      :: forall ba . ByteArray ba => st -> ba -> (ba, st)
    , aeadImplDecrypt      :: forall ba . ByteArray ba => st -> ba -> (ba, st)
    , aeadImplFinalize     :: st -> Int -> AuthTag
    }

-- | Authenticated Encryption with Associated Data algorithms
data AEAD cipher = forall st . AEAD
    { aeadModeImpl :: AEADModeImpl st
    , aeadState    :: !st
    }

-- | Append some header information to an AEAD context
aeadAppendHeader :: ByteArrayAccess aad => AEAD cipher -> aad -> AEAD cipher
aeadAppendHeader (AEAD impl st) aad = AEAD impl $ (aeadImplAppendHeader impl) st aad

{'fraction_non_alphanumeric': 0.110202492211838, 'fraction_numerical': 0.000778816199376947, 'mean_word_length': 2.8573573573573574, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3190854', 'n_tokens_mistral': 839, 'n_tokens_neox': 803, 'n_words': 237}