From 94835c393e81e3fbcfc7a92daa22e2123f03568b Mon Sep 17 00:00:00 2001 From: Vladislav Sabanov Date: Sat, 3 Jan 2026 01:39:31 -0300 Subject: [PATCH 1/4] Simplify record fields --- botan-low/test/Test/Botan/Low/PwdHash.hs | 8 ++--- botan/src/Botan/BlockCipher.hs | 22 ++++++------- botan/src/Botan/Cipher.hs | 40 ++++++++++++------------ botan/src/Botan/HOTP.hs | 12 +++---- botan/src/Botan/Hash.hs | 22 ++++++------- botan/src/Botan/MAC.hs | 20 ++++++------ 6 files changed, 62 insertions(+), 62 deletions(-) diff --git a/botan-low/test/Test/Botan/Low/PwdHash.hs b/botan-low/test/Test/Botan/Low/PwdHash.hs index aed70f9e..e05cc806 100644 --- a/botan-low/test/Test/Botan/Low/PwdHash.hs +++ b/botan-low/test/Test/Botan/Low/PwdHash.hs @@ -36,10 +36,10 @@ tests = do -------------------------------------------------------------------------------} data TestParams = TestParams { - testPbkdfName :: PBKDFName - , testIterationsParam :: Int - , testParallelismParam :: Int - , testMemoryParam :: Int + pbkdfName :: PBKDFName + , iterationsParam :: Int + , parallelismParam :: Int + , memoryParam :: Int } deriving stock (Show, Eq) diff --git a/botan/src/Botan/BlockCipher.hs b/botan/src/Botan/BlockCipher.hs index 3b2b3ce7..c34750ff 100644 --- a/botan/src/Botan/BlockCipher.hs +++ b/botan/src/Botan/BlockCipher.hs @@ -429,14 +429,14 @@ blockCipherDecryptLazy = undefined -- Tagged mutable context data MutableBlockCipher = MkMutableBlockCipher - { mutableBlockCipherType :: BlockCipher - , mutableBlockCipherCtx :: Low.BlockCipher + { algo :: BlockCipher + , ctx :: Low.BlockCipher } -- Destructor destroyBlockCipher :: (MonadIO m) => MutableBlockCipher -> m () -destroyBlockCipher = liftIO . Low.blockCipherDestroy . (.mutableBlockCipherCtx) +destroyBlockCipher = liftIO . Low.blockCipherDestroy . (.ctx) -- Initializers @@ -449,25 +449,25 @@ newBlockCipher c = do -- Accessors --- NOTE: Because of synonyms, `blockCipherName (mutableBlockCipherType mc) == getBlockCipherName` may not be `True`. +-- NOTE: Because of synonyms, `blockCipherName (mc.algo) == getBlockCipherName` may not be `True`. getBlockCipherName :: (MonadIO m) => MutableBlockCipher -- ^ The cipher object -> m (Low.BlockCipherName) -- ^ The cipher name -getBlockCipherName = liftIO . Low.blockCipherName . (.mutableBlockCipherCtx) +getBlockCipherName = liftIO . Low.blockCipherName . (.ctx) getBlockCipherBlockSize :: (MonadIO m) => MutableBlockCipher -- ^ The cipher object -> m Int -getBlockCipherBlockSize = liftIO . Low.blockCipherBlockSize . (.mutableBlockCipherCtx) +getBlockCipherBlockSize = liftIO . Low.blockCipherBlockSize . (.ctx) getBlockCipherKeySpec :: (MonadIO m) => MutableBlockCipher -- ^ The cipher object -> m BlockCipherKeySpec getBlockCipherKeySpec mc = do - (mn,mx,md) <- liftIO $ Low.blockCipherGetKeyspec mc.mutableBlockCipherCtx + (mn,mx,md) <- liftIO $ Low.blockCipherGetKeyspec mc.ctx return $ keySpec mn mx md setBlockCipherKey @@ -479,14 +479,14 @@ setBlockCipherKey k mc = do valid <- keySizeIsValid (ByteString.length k) <$> getBlockCipherKeySpec mc if valid then do - liftIO $ Low.blockCipherSetKey mc.mutableBlockCipherCtx k + liftIO $ Low.blockCipherSetKey mc.ctx k return True else return False -- Accessory functions clearBlockCipher :: (MonadIO m) => MutableBlockCipher -> m () -clearBlockCipher = liftIO . Low.blockCipherClear . (.mutableBlockCipherCtx) +clearBlockCipher = liftIO . Low.blockCipherClear . (.ctx) -- Mutable algorithm @@ -497,7 +497,7 @@ encryptBlockCipherBlocks => MutableBlockCipher -> ByteString -> m BlockCipherText -encryptBlockCipherBlocks mc pt = liftIO $ Low.blockCipherEncryptBlocks mc.mutableBlockCipherCtx pt +encryptBlockCipherBlocks mc pt = liftIO $ Low.blockCipherEncryptBlocks mc.ctx pt -- NOTE: Not maybe because it should never fail in a proper context (ie, having set the key successfully) decryptBlockCipherBlocks @@ -505,7 +505,7 @@ decryptBlockCipherBlocks => MutableBlockCipher -> BlockCipherText -> m ByteString -decryptBlockCipherBlocks mc ct = liftIO $ Low.blockCipherDecryptBlocks mc.mutableBlockCipherCtx ct +decryptBlockCipherBlocks mc ct = liftIO $ Low.blockCipherDecryptBlocks mc.ctx ct autoEncryptBlockCipherBlocks :: (MonadIO m) diff --git a/botan/src/Botan/Cipher.hs b/botan/src/Botan/Cipher.hs index de2a7da1..add39dd3 100644 --- a/botan/src/Botan/Cipher.hs +++ b/botan/src/Botan/Cipher.hs @@ -513,16 +513,16 @@ aeadDecrypt c k n ad ct = unsafePerformIO $ do -- Tagged mutable context data MutableCipher = MkMutableCipher - { mutableCipherType :: Cipher - , mutableCipherDirection :: CipherDirection - , mutableCipherCtx :: Low.Cipher + { algo :: Cipher + , direction :: CipherDirection + , ctx :: Low.Cipher -- , mutableCipherProcessed :: Int } -- Destructor destroyCipher :: (MonadIO m) => MutableCipher -> m () -destroyCipher = liftIO . Low.cipherDestroy . (.mutableCipherCtx) +destroyCipher = liftIO . Low.cipherDestroy . (.ctx) -- Associated types @@ -560,29 +560,29 @@ newCipher c dir = do -- Accessors getCipherName :: (MonadIO m) => MutableCipher -> m ByteString -getCipherName = liftIO . Low.cipherName . (.mutableCipherCtx) +getCipherName = liftIO . Low.cipherName . (.ctx) getCipherKeySpec :: (MonadIO m) => MutableCipher -> m CipherKeySpec getCipherKeySpec c = do - (mn,mx,md) <- liftIO $ Low.cipherGetKeyspec c.mutableCipherCtx + (mn,mx,md) <- liftIO $ Low.cipherGetKeyspec c.ctx return $ keySpec mn mx md getCipherDefaultNonceSize :: (MonadIO m) => MutableCipher -> m Int -getCipherDefaultNonceSize = liftIO . Low.cipherGetDefaultNonceLength . (.mutableCipherCtx) +getCipherDefaultNonceSize = liftIO . Low.cipherGetDefaultNonceLength . (.ctx) getCipherNonceSizeIsValid :: (MonadIO m) => MutableCipher -> Int -> m Bool -getCipherNonceSizeIsValid c n = liftIO $ Low.cipherValidNonceLength c.mutableCipherCtx n +getCipherNonceSizeIsValid c n = liftIO $ Low.cipherValidNonceLength c.ctx n -- TODO: Rename getAEADTagLength? getAETagLength? getCipherTagSize :: (MonadIO m) => MutableCipher -> m Int -getCipherTagSize = liftIO . Low.cipherGetTagLength . (.mutableCipherCtx) +getCipherTagSize = liftIO . Low.cipherGetTagLength . (.ctx) getCipherUpdateGranularity :: (MonadIO m) => MutableCipher -> m Int -getCipherUpdateGranularity = liftIO . Low.cipherGetUpdateGranularity . (.mutableCipherCtx) +getCipherUpdateGranularity = liftIO . Low.cipherGetUpdateGranularity . (.ctx) getCipherIdealUpdateGranularity :: (MonadIO m) => MutableCipher -> m Int -getCipherIdealUpdateGranularity = liftIO . Low.cipherGetIdealUpdateGranularity . (.mutableCipherCtx) +getCipherIdealUpdateGranularity = liftIO . Low.cipherGetIdealUpdateGranularity . (.ctx) -- NOTE: out + ug + tag is safe overestimate for encryption -- NOTE: out + ug - tag may not be a safe overestimate for decryption @@ -591,34 +591,34 @@ getCipherEstimateOutputLength ctx input = do o <- getCipherOutputLength ctx input -- NOTE: Flawed but usable u <- getCipherUpdateGranularity ctx -- TODO: When u == 1, it should be just input + t, right? t <- getCipherTagSize ctx - if ctx.mutableCipherDirection == CipherEncrypt + if ctx.direction == CipherEncrypt then return (o + u + t) else return (o + u - t) -- TODO: Maybe just 'o'... -- NOTE: Supposed to be an upper bound, may not always be valid? - needs checking {-# WARNING getCipherOutputLength "Needs to be confirmed accurate, use getCipherEstimateOutputLength" #-} getCipherOutputLength :: (MonadIO m) => MutableCipher -> Int -> m Int -getCipherOutputLength c n = liftIO $ Low.cipherOutputLength c.mutableCipherCtx n +getCipherOutputLength c n = liftIO $ Low.cipherOutputLength c.ctx n setCipherKey :: (MonadIO m) => MutableCipher -> CipherKey -> m () -setCipherKey c key = liftIO $ Low.cipherSetKey c.mutableCipherCtx key +setCipherKey c key = liftIO $ Low.cipherSetKey c.ctx key -- TODO: Consider flipping setAEADAssociatedData :: (MonadIO m) => MutableCipher -> ByteString -> m () -setAEADAssociatedData c ad = liftIO $ Low.cipherSetAssociatedData c.mutableCipherCtx ad +setAEADAssociatedData c ad = liftIO $ Low.cipherSetAssociatedData c.ctx ad -- Accessory functions clearCipher :: (MonadIO m) => MutableCipher -> m () -clearCipher = liftIO . Low.cipherClear . (.mutableCipherCtx) +clearCipher = liftIO . Low.cipherClear . (.ctx) resetCipher :: (MonadIO m) => MutableCipher -> m () -resetCipher = liftIO . Low.cipherReset . (.mutableCipherCtx) +resetCipher = liftIO . Low.cipherReset . (.ctx) -- Mutable algorithm startCipher :: (MonadIO m) => MutableCipher -> CipherNonce -> m () -startCipher c n = liftIO $ Low.cipherStart c.mutableCipherCtx n +startCipher c n = liftIO $ Low.cipherStart c.ctx n -- NOTE: DOES NOT USE ESTIMATED OUTPUT LENGTH updateCipher @@ -628,7 +628,7 @@ updateCipher -> m (Int, ByteString) updateCipher c msg = do o <- getCipherOutputLength c (ByteString.length msg) - liftIO $ Low.cipherUpdate c.mutableCipherCtx (cipherUpdateFlag CipherUpdate) o msg + liftIO $ Low.cipherUpdate c.ctx (cipherUpdateFlag CipherUpdate) o msg -- updateCipherChunks :: _ -- updateCipherChunks = undefined @@ -643,7 +643,7 @@ finalizeCipher -> m ByteString finalizeCipher c msg = do o <- getCipherOutputLength c (ByteString.length msg) - (_,out) <- liftIO $ Low.cipherUpdate c.mutableCipherCtx (cipherUpdateFlag CipherFinal) o msg + (_,out) <- liftIO $ Low.cipherUpdate c.ctx (cipherUpdateFlag CipherFinal) o msg return out finalizeResetCipher diff --git a/botan/src/Botan/HOTP.hs b/botan/src/Botan/HOTP.hs index f96392e5..d1b2d0bd 100644 --- a/botan/src/Botan/HOTP.hs +++ b/botan/src/Botan/HOTP.hs @@ -45,9 +45,9 @@ type HOTPKey = ByteString -- TODO: Bring in MVar to capture everything data HOTPCtx = HOTPCtx - { hotpCtx :: Low.HOTP - , hotpCounter :: Low.HOTPCounter - , hotpResync :: Int + { ctx :: Low.HOTP + , counter :: Low.HOTPCounter + , resync :: Int } data HOTPLength @@ -62,9 +62,9 @@ newHOTP :: HOTP -> HOTPLength -> Int -> ByteString -> IO HOTPCtx newHOTP hotp len resync key = do ctx <- Low.hotpInit key (hotpAlgo hotp) (hotpLength len) return $ HOTPCtx - { hotpCtx = ctx - , hotpCounter = 0 - , hotpResync = resync + { ctx = ctx + , counter = 0 + , resync = resync } hotpGenerate :: HOTPCtx -> IO Low.HOTPCode diff --git a/botan/src/Botan/Hash.hs b/botan/src/Botan/Hash.hs index 52078206..8d8db100 100644 --- a/botan/src/Botan/Hash.hs +++ b/botan/src/Botan/Hash.hs @@ -474,8 +474,8 @@ hashFileLazy h fp = do -- Tagged mutable context data MutableHash = MkMutableHash - { mutableHashType :: Hash - , mutableHashCtx :: Low.Hash + { algo :: Hash + , ctx :: Low.Hash } -- Destructor @@ -484,7 +484,7 @@ destroyHash :: (MonadIO m) => MutableHash -> m () -destroyHash = liftIO . Low.hashDestroy . (.mutableHashCtx) +destroyHash = liftIO . Low.hashDestroy . (.ctx) -- Initializers @@ -502,19 +502,19 @@ getHashName :: (MonadIO m) => MutableHash -> m Low.HashName -getHashName = liftIO . Low.hashName . (.mutableHashCtx) +getHashName = liftIO . Low.hashName . (.ctx) getHashBlockSize :: (MonadIO m) => MutableHash -> m Int -getHashBlockSize = liftIO . Low.hashBlockSize . (.mutableHashCtx) +getHashBlockSize = liftIO . Low.hashBlockSize . (.ctx) getHashDigestSize :: (MonadIO m) => MutableHash -> m Int -getHashDigestSize = liftIO . Low.hashOutputLength . (.mutableHashCtx) +getHashDigestSize = liftIO . Low.hashOutputLength . (.ctx) -- Accessory functions @@ -523,14 +523,14 @@ copyHashState => MutableHash -> m MutableHash copyHashState mh = do - ctx <- liftIO $ Low.hashCopyState mh.mutableHashCtx - return $ MkMutableHash mh.mutableHashType ctx + ctx <- liftIO $ Low.hashCopyState mh.ctx + return $ MkMutableHash mh.algo ctx clearHash :: (MonadIO m) => MutableHash -> m () -clearHash = liftIO . Low.hashClear . (.mutableHashCtx) +clearHash = liftIO . Low.hashClear . (.ctx) -- Mutable algorithm -- TODO: Flip? @@ -548,13 +548,13 @@ updateHashChunks -> [ByteString] -> m () updateHashChunks mh chunks = - liftIO $ traverse_ (Low.hashUpdate mh.mutableHashCtx) chunks + liftIO $ traverse_ (Low.hashUpdate mh.ctx) chunks finalizeHash :: (MonadIO m) => MutableHash -> m HashDigest -finalizeHash = liftIO . Low.hashFinal . (.mutableHashCtx) +finalizeHash = liftIO . Low.hashFinal . (.ctx) updateFinalizeHash :: (MonadIO m) diff --git a/botan/src/Botan/MAC.hs b/botan/src/Botan/MAC.hs index b83d5a61..acf1b52f 100644 --- a/botan/src/Botan/MAC.hs +++ b/botan/src/Botan/MAC.hs @@ -293,8 +293,8 @@ gmac _ _ _ _ = error "Expected GMAC" -- Tagged mutable context data MutableMAC = MkMutableMAC - { mutableMACType :: MAC - , mutableMACCtx :: Low.MAC + { algo :: MAC + , ctx :: Low.MAC } -- Destructor @@ -303,7 +303,7 @@ destroyMAC :: (MonadIO m) => MutableMAC -> m () -destroyMAC = liftIO . Low.macDestroy . (.mutableMACCtx) +destroyMAC = liftIO . Low.macDestroy . (.ctx) -- Initializers @@ -321,21 +321,21 @@ getMACName :: (MonadIO m) => MutableMAC -> m Low.MACName -getMACName = liftIO . Low.macName . (.mutableMACCtx) +getMACName = liftIO . Low.macName . (.ctx) getMACKeySpec :: (MonadIO m) => MutableMAC -> m MACKeySpec getMACKeySpec mm = do - (mn,mx,md) <- liftIO $ Low.macGetKeyspec mm.mutableMACCtx + (mn,mx,md) <- liftIO $ Low.macGetKeyspec mm.ctx return $ keySpec mn mx md getMACDigestLength :: (MonadIO m) => MutableMAC -> m Int -getMACDigestLength = liftIO . Low.macOutputLength . (.mutableMACCtx) +getMACDigestLength = liftIO . Low.macOutputLength . (.ctx) setMACKey :: (MonadIO m) @@ -346,7 +346,7 @@ setMACKey k mm = do valid <- keySizeIsValid (ByteString.length k) <$> getMACKeySpec mm if valid then do - liftIO $ Low.macSetKey mm.mutableMACCtx k + liftIO $ Low.macSetKey mm.ctx k return True else return False @@ -372,7 +372,7 @@ clearMAC :: (MonadIO m) => MutableMAC -> m () -clearMAC = liftIO . Low.macClear . (.mutableMACCtx) +clearMAC = liftIO . Low.macClear . (.ctx) -- Mutable algorithm @@ -392,13 +392,13 @@ updateMACChunks -> [ByteString] -> m () updateMACChunks mm chunks = - liftIO $ traverse_ (Low.macUpdate mm.mutableMACCtx) chunks + liftIO $ traverse_ (Low.macUpdate mm.ctx) chunks finalizeMAC :: (MonadIO m) => MutableMAC -> m MACDigest -finalizeMAC = liftIO . Low.macFinal . (.mutableMACCtx) +finalizeMAC = liftIO . Low.macFinal . (.ctx) updateFinalizeMAC :: (MonadIO m) From 5b21aef4c96ca4a3df43b41826bace69e856401e Mon Sep 17 00:00:00 2001 From: Vladislav Sabanov Date: Mon, 5 Jan 2026 13:43:10 -0300 Subject: [PATCH 2/4] Simplify newtypes --- .../src/Botan/Bindings/BlockCipher.hs | 2 +- botan-bindings/src/Botan/Bindings/Cipher.hsc | 2 +- botan-bindings/src/Botan/Bindings/ConstPtr.hs | 2 +- botan-bindings/src/Botan/Bindings/FPE.hsc | 2 +- botan-bindings/src/Botan/Bindings/HOTP.hs | 2 +- botan-bindings/src/Botan/Bindings/Hash.hs | 2 +- botan-bindings/src/Botan/Bindings/MAC.hs | 2 +- botan-bindings/src/Botan/Bindings/MPI.hs | 2 +- botan-bindings/src/Botan/Bindings/PubKey.hsc | 4 +-- .../src/Botan/Bindings/PubKey/Decrypt.hsc | 2 +- .../src/Botan/Bindings/PubKey/Encrypt.hsc | 2 +- .../Botan/Bindings/PubKey/KeyAgreement.hsc | 2 +- .../Botan/Bindings/PubKey/KeyEncapsulation.hs | 4 +-- .../src/Botan/Bindings/PubKey/Sign.hsc | 2 +- .../src/Botan/Bindings/PubKey/Verify.hsc | 2 +- botan-bindings/src/Botan/Bindings/RNG.hs | 2 +- botan-bindings/src/Botan/Bindings/SRP6.hs | 2 +- botan-bindings/src/Botan/Bindings/TOTP.hs | 2 +- botan-bindings/src/Botan/Bindings/X509.hsc | 4 +-- botan-low/src/Botan/Low/BlockCipher.hs | 6 ++-- botan-low/src/Botan/Low/Cipher.hs | 6 ++-- botan-low/src/Botan/Low/FPE.hs | 6 ++-- botan-low/src/Botan/Low/HOTP.hs | 6 ++-- botan-low/src/Botan/Low/Hash.hs | 6 ++-- botan-low/src/Botan/Low/MAC.hs | 6 ++-- botan-low/src/Botan/Low/MPI.hs | 6 ++-- botan-low/src/Botan/Low/PubKey.hs | 12 ++++---- botan-low/src/Botan/Low/PubKey/Decrypt.hs | 6 ++-- botan-low/src/Botan/Low/PubKey/Encrypt.hs | 6 ++-- .../src/Botan/Low/PubKey/KeyAgreement.hs | 6 ++-- .../src/Botan/Low/PubKey/KeyEncapsulation.hs | 12 ++++---- botan-low/src/Botan/Low/PubKey/Sign.hs | 6 ++-- botan-low/src/Botan/Low/PubKey/Verify.hs | 6 ++-- botan-low/src/Botan/Low/RNG.hs | 4 +-- botan-low/src/Botan/Low/SRP6.hs | 6 ++-- botan-low/src/Botan/Low/TOTP.hs | 6 ++-- botan-low/src/Botan/Low/X509.hs | 8 +++--- botan/src/Botan/BlockCipher.hs | 8 +++--- botan/src/Botan/Cipher.hs | 14 +++++----- botan/src/Botan/Hash.hs | 8 +++--- botan/src/Botan/MAC.hs | 6 ++-- botan/src/Botan/Types/Class.hs | 28 +++++++++---------- 42 files changed, 114 insertions(+), 114 deletions(-) diff --git a/botan-bindings/src/Botan/Bindings/BlockCipher.hs b/botan-bindings/src/Botan/Bindings/BlockCipher.hs index 6e07a8fa..34df17ff 100644 --- a/botan-bindings/src/Botan/Bindings/BlockCipher.hs +++ b/botan-bindings/src/Botan/Bindings/BlockCipher.hs @@ -75,7 +75,7 @@ data {-# CTYPE "botan/ffi.h" "struct botan_block_cipher_struct" #-} BotanBlockCi -- | Botan BlockCipher object newtype {-# CTYPE "botan/ffi.h" "botan_block_cipher_t" #-} BotanBlockCipher - = MkBotanBlockCipher { runBotanBlockCipher :: Ptr BotanBlockCipherStruct } + = MkBotanBlockCipher { ptr :: Ptr BotanBlockCipherStruct } deriving newtype (Eq, Ord, Storable) -- | Destroy a block cipher object diff --git a/botan-bindings/src/Botan/Bindings/Cipher.hsc b/botan-bindings/src/Botan/Bindings/Cipher.hsc index 6d45d637..c8a43bbc 100644 --- a/botan-bindings/src/Botan/Bindings/Cipher.hsc +++ b/botan-bindings/src/Botan/Bindings/Cipher.hsc @@ -78,7 +78,7 @@ data {-# CTYPE "botan/ffi.h" "struct botan_cipher_struct" #-} BotanCipherStruct -- | Botan Cipher object newtype {-# CTYPE "botan/ffi.h" "botan_cipher_t" #-} BotanCipher - = MkBotanCipher { runBotanCipher :: Ptr BotanCipherStruct } + = MkBotanCipher { ptr :: Ptr BotanCipherStruct } deriving newtype (Eq, Ord, Storable) -- | Destroy the cipher object diff --git a/botan-bindings/src/Botan/Bindings/ConstPtr.hs b/botan-bindings/src/Botan/Bindings/ConstPtr.hs index 06819b98..73710c4a 100644 --- a/botan-bindings/src/Botan/Bindings/ConstPtr.hs +++ b/botan-bindings/src/Botan/Bindings/ConstPtr.hs @@ -27,7 +27,7 @@ import Foreign.Storable -- botan_version_string type ConstPtr :: Type -> Type type role ConstPtr phantom -newtype ConstPtr a = ConstPtr { unConstPtr :: Ptr a } +newtype ConstPtr a = ConstPtr { un :: Ptr a } deriving stock (Data) deriving newtype (Eq, Ord, Storable) diff --git a/botan-bindings/src/Botan/Bindings/FPE.hsc b/botan-bindings/src/Botan/Bindings/FPE.hsc index 668360db..a5b2580d 100644 --- a/botan-bindings/src/Botan/Bindings/FPE.hsc +++ b/botan-bindings/src/Botan/Bindings/FPE.hsc @@ -61,7 +61,7 @@ data {-# CTYPE "botan/ffi.h" "struct botan_fpe_struct" #-} BotanFPEStruct -- | Botan FPE object newtype {-# CTYPE "botan/ffi.h" "botan_fpe_t" #-} BotanFPE - = MkBotanFPE { runBotanFPE :: Ptr BotanFPEStruct } + = MkBotanFPE { ptr :: Ptr BotanFPEStruct } deriving newtype (Eq, Ord, Storable) -- | Destroy the FPE object diff --git a/botan-bindings/src/Botan/Bindings/HOTP.hs b/botan-bindings/src/Botan/Bindings/HOTP.hs index 8654fed2..b790cca4 100644 --- a/botan-bindings/src/Botan/Bindings/HOTP.hs +++ b/botan-bindings/src/Botan/Bindings/HOTP.hs @@ -59,7 +59,7 @@ data {-# CTYPE "botan/ffi.h" "struct botan_hotp_struct" #-} BotanHOTPStruct -- | Botan HOTP object newtype {-# CTYPE "botan/ffi.h" "botan_hotp_t" #-} BotanHOTP - = MkBotanHOTP { runBotanHOTP :: Ptr BotanHOTPStruct } + = MkBotanHOTP { ptr :: Ptr BotanHOTPStruct } deriving newtype (Eq, Ord, Storable) -- | Destroy a HOTP instance diff --git a/botan-bindings/src/Botan/Bindings/Hash.hs b/botan-bindings/src/Botan/Bindings/Hash.hs index 3a7e8065..701fad13 100644 --- a/botan-bindings/src/Botan/Bindings/Hash.hs +++ b/botan-bindings/src/Botan/Bindings/Hash.hs @@ -84,7 +84,7 @@ data {-# CTYPE "botan/ffi.h" "struct botan_hash_struct" #-} BotanHashStruct -- | Botan Hash object newtype {-# CTYPE "botan/ffi.h" "botan_hash_t" #-} BotanHash - = MkBotanHash { runBotanHash :: Ptr BotanHashStruct } + = MkBotanHash { ptr :: Ptr BotanHashStruct } deriving newtype (Eq, Ord, Storable) -- | Frees all resources of the hash object diff --git a/botan-bindings/src/Botan/Bindings/MAC.hs b/botan-bindings/src/Botan/Bindings/MAC.hs index 7daa7f99..b659c807 100644 --- a/botan-bindings/src/Botan/Bindings/MAC.hs +++ b/botan-bindings/src/Botan/Bindings/MAC.hs @@ -74,7 +74,7 @@ data {-# CTYPE "botan/ffi.h" "struct botan_mac_struct" #-} BotanMACStruct -- | Botan MAC object newtype {-# CTYPE "botan/ffi.h" "botan_mac_t" #-} BotanMAC - = MkBotanMAC { runBotanMAC :: Ptr BotanMACStruct } + = MkBotanMAC { ptr :: Ptr BotanMACStruct } deriving newtype (Eq, Ord, Storable) -- | Frees all resources of the MAC object diff --git a/botan-bindings/src/Botan/Bindings/MPI.hs b/botan-bindings/src/Botan/Bindings/MPI.hs index 633524a1..c05c1129 100644 --- a/botan-bindings/src/Botan/Bindings/MPI.hs +++ b/botan-bindings/src/Botan/Bindings/MPI.hs @@ -68,7 +68,7 @@ data {-# CTYPE "botan/ffi.h" "struct botan_mp_struct" #-} BotanMPStruct -- | Botan MP object newtype {-# CTYPE "botan/ffi.h" "botan_mp_t" #-} BotanMP - = MkBotanMP { runBotanMP :: Ptr BotanMPStruct } + = MkBotanMP { ptr :: Ptr BotanMPStruct } deriving newtype (Eq, Ord, Storable) -- | Destroy (deallocate) an MPI diff --git a/botan-bindings/src/Botan/Bindings/PubKey.hsc b/botan-bindings/src/Botan/Bindings/PubKey.hsc index 882a6478..c6738c4b 100644 --- a/botan-bindings/src/Botan/Bindings/PubKey.hsc +++ b/botan-bindings/src/Botan/Bindings/PubKey.hsc @@ -159,7 +159,7 @@ data {-# CTYPE "botan/ffi.h" "struct botan_privkey_struct" #-} BotanPrivKeyStruc -- | Botan PrivKey object newtype {-# CTYPE "botan/ffi.h" "botan_privkey_t" #-} BotanPrivKey - = MkBotanPrivKey { runBotanPrivKey :: Ptr BotanPrivKeyStruct } + = MkBotanPrivKey { ptr :: Ptr BotanPrivKeyStruct } deriving newtype (Eq, Ord, Storable) -- | Frees all resources of the PrivKey object @@ -547,7 +547,7 @@ data {-# CTYPE "botan/ffi.h" "struct botan_pubkey_struct" #-} BotanPubKeyStruct -- | Botan PubKey object newtype {-# CTYPE "botan/ffi.h" "botan_pubkey_t" #-} BotanPubKey - = MkBotanPubKey { runBotanPubKey :: Ptr BotanPubKeyStruct } + = MkBotanPubKey { ptr :: Ptr BotanPubKeyStruct } deriving newtype (Eq, Ord, Storable) -- | Frees all resources of the PubKey object diff --git a/botan-bindings/src/Botan/Bindings/PubKey/Decrypt.hsc b/botan-bindings/src/Botan/Bindings/PubKey/Decrypt.hsc index 0ef1573a..d20ce014 100644 --- a/botan-bindings/src/Botan/Bindings/PubKey/Decrypt.hsc +++ b/botan-bindings/src/Botan/Bindings/PubKey/Decrypt.hsc @@ -36,7 +36,7 @@ data {-# CTYPE "botan/ffi.h" "struct botan_pk_op_decrypt_struct" #-} BotanPKOpDe -- | Botan decrypt object newtype {-# CTYPE "botan/ffi.h" "botan_pk_op_decrypt_t" #-} BotanPKOpDecrypt - = MkBotanPKOpDecrypt { runBotanPKOpDecrypt :: Ptr BotanPKOpDecryptStruct } + = MkBotanPKOpDecrypt { ptr :: Ptr BotanPKOpDecryptStruct } deriving newtype (Eq, Ord, Storable) -- | Destroy a decrypt object diff --git a/botan-bindings/src/Botan/Bindings/PubKey/Encrypt.hsc b/botan-bindings/src/Botan/Bindings/PubKey/Encrypt.hsc index 60087d16..db890fc2 100644 --- a/botan-bindings/src/Botan/Bindings/PubKey/Encrypt.hsc +++ b/botan-bindings/src/Botan/Bindings/PubKey/Encrypt.hsc @@ -37,7 +37,7 @@ data {-# CTYPE "botan/ffi.h" "struct botan_pk_op_encrypt_struct" #-} BotanPKOpEn -- | Botan encrypt object newtype {-# CTYPE "botan/ffi.h" "botan_pk_op_encrypt_t" #-} BotanPKOpEncrypt - = MkBotanPKOpEncrypt { runBotanPKOpEncrypt :: Ptr BotanPKOpEncryptStruct } + = MkBotanPKOpEncrypt { ptr :: Ptr BotanPKOpEncryptStruct } deriving newtype (Eq, Ord, Storable) -- | Destroy a encrypt object diff --git a/botan-bindings/src/Botan/Bindings/PubKey/KeyAgreement.hsc b/botan-bindings/src/Botan/Bindings/PubKey/KeyAgreement.hsc index bac6f88d..c0eac2a4 100644 --- a/botan-bindings/src/Botan/Bindings/PubKey/KeyAgreement.hsc +++ b/botan-bindings/src/Botan/Bindings/PubKey/KeyAgreement.hsc @@ -41,7 +41,7 @@ data {-# CTYPE "botan/ffi.h" "struct botan_pk_op_ka_struct" #-} BotanPKOpKeyAgre -- | Botan key agreement object newtype {-# CTYPE "botan/ffi.h" "botan_pk_op_ka_t" #-} BotanPKOpKeyAgreement - = MkBotanPKOpKeyAgreement { runBotanPKOpKeyAgreement :: Ptr BotanPKOpKeyAgreementStruct } + = MkBotanPKOpKeyAgreement { ptr :: Ptr BotanPKOpKeyAgreementStruct } deriving newtype (Eq, Ord, Storable) -- | Destroy a key agreement object diff --git a/botan-bindings/src/Botan/Bindings/PubKey/KeyEncapsulation.hs b/botan-bindings/src/Botan/Bindings/PubKey/KeyEncapsulation.hs index 92aba325..3cb9374c 100644 --- a/botan-bindings/src/Botan/Bindings/PubKey/KeyEncapsulation.hs +++ b/botan-bindings/src/Botan/Bindings/PubKey/KeyEncapsulation.hs @@ -41,7 +41,7 @@ data {-# CTYPE "botan/ffi.h" "struct botan_pk_op_kem_encrypt_struct" #-} BotanPK -- | Botan KEM encrypt object newtype {-# CTYPE "botan/ffi.h" "botan_pk_op_kem_encrypt_t" #-} BotanPKOpKEMEncrypt - = MkBotanPKOpKEMEncrypt { runBotanPKOpKEMEncrypt :: Ptr BotanPKOpKEMEncryptStruct } + = MkBotanPKOpKEMEncrypt { ptr :: Ptr BotanPKOpKEMEncryptStruct } deriving newtype (Eq, Ord, Storable) -- | Destroy a KEM encrypt object @@ -87,7 +87,7 @@ data {-# CTYPE "botan/ffi.h" "struct botan_pk_op_kem_decrypt_struct" #-} BotanPK -- | Botan KEM decrypt object newtype {-# CTYPE "botan/ffi.h" "botan_pk_op_kem_decrypt_t" #-} BotanPKOpKEMDecrypt - = MkBotanPKOpKEMDecrypt { runBotanPKOpKEMDecrypt :: Ptr BotanPKOpKEMDecryptStruct } + = MkBotanPKOpKEMDecrypt { ptr :: Ptr BotanPKOpKEMDecryptStruct } deriving newtype (Eq, Ord, Storable) -- | Destroy a KEM decrypt object diff --git a/botan-bindings/src/Botan/Bindings/PubKey/Sign.hsc b/botan-bindings/src/Botan/Bindings/PubKey/Sign.hsc index 6a7f0514..2031d960 100644 --- a/botan-bindings/src/Botan/Bindings/PubKey/Sign.hsc +++ b/botan-bindings/src/Botan/Bindings/PubKey/Sign.hsc @@ -39,7 +39,7 @@ data {-# CTYPE "botan/ffi.h" "struct botan_pk_op_sign_struct" #-} BotanPKOpSignS -- | Botan sign object newtype {-# CTYPE "botan/ffi.h" "botan_pk_op_sign_t" #-} BotanPKOpSign - = MkBotanPKOpSign { runBotanPKOpSign :: Ptr BotanPKOpSignStruct } + = MkBotanPKOpSign { ptr :: Ptr BotanPKOpSignStruct } deriving newtype (Eq, Ord, Storable) -- | Destroy a sign object diff --git a/botan-bindings/src/Botan/Bindings/PubKey/Verify.hsc b/botan-bindings/src/Botan/Bindings/PubKey/Verify.hsc index 62c64e82..0ebd7806 100644 --- a/botan-bindings/src/Botan/Bindings/PubKey/Verify.hsc +++ b/botan-bindings/src/Botan/Bindings/PubKey/Verify.hsc @@ -36,7 +36,7 @@ data {-# CTYPE "botan/ffi.h" "struct botan_pk_op_verify_struct" #-} BotanPKOpVer -- | Botan verify object newtype {-# CTYPE "botan/ffi.h" "botan_pk_op_verify_t" #-} BotanPKOpVerify - = MkBotanPKOpVerify { runBotanPKOpVerify :: Ptr BotanPKOpVerifyStruct } + = MkBotanPKOpVerify { ptr :: Ptr BotanPKOpVerifyStruct } deriving newtype (Eq, Ord, Storable) -- | Destroy a verify object diff --git a/botan-bindings/src/Botan/Bindings/RNG.hs b/botan-bindings/src/Botan/Bindings/RNG.hs index 13c57c0b..ba486c30 100644 --- a/botan-bindings/src/Botan/Bindings/RNG.hs +++ b/botan-bindings/src/Botan/Bindings/RNG.hs @@ -48,7 +48,7 @@ data {-# CTYPE "botan/ffi.h" "struct botan_rng_struct" #-} BotanRNGStruct -- | Botan RNG object newtype {-# CTYPE "botan/ffi.h" "botan_rng_t" #-} BotanRNG - = MkBotanRNG { runBotanRNG :: Ptr BotanRNGStruct } + = MkBotanRNG { ptr :: Ptr BotanRNGStruct } deriving newtype (Eq, Ord, Storable) -- | Frees all resources of the random number generator object diff --git a/botan-bindings/src/Botan/Bindings/SRP6.hs b/botan-bindings/src/Botan/Bindings/SRP6.hs index 90ab19d3..43d002d6 100644 --- a/botan-bindings/src/Botan/Bindings/SRP6.hs +++ b/botan-bindings/src/Botan/Bindings/SRP6.hs @@ -40,7 +40,7 @@ data {-# CTYPE "botan/ffi.h" "struct botan_srp6_server_session_struct" #-} Botan -- | SRP-6 server session object newtype {-# CTYPE "botan/ffi.h" "botan_srp6_server_session_t" #-} BotanSRP6ServerSession - = MkBotanSRP6ServerSession { runBotanSRP6ServerSession :: Ptr BotanSRP6ServerSessionStruct } + = MkBotanSRP6ServerSession { ptr :: Ptr BotanSRP6ServerSessionStruct } deriving newtype (Eq, Ord, Storable) -- | Frees all resources of the SRP-6 server session object diff --git a/botan-bindings/src/Botan/Bindings/TOTP.hs b/botan-bindings/src/Botan/Bindings/TOTP.hs index bfb0b477..3f66afc2 100644 --- a/botan-bindings/src/Botan/Bindings/TOTP.hs +++ b/botan-bindings/src/Botan/Bindings/TOTP.hs @@ -64,7 +64,7 @@ data {-# CTYPE "botan/ffi.h" "struct botan_totp_struct" #-} BotanTOTPStruct -- | Botan TOTP object newtype {-# CTYPE "botan/ffi.h" "botan_totp_t" #-} BotanTOTP - = MkBotanTOTP { runBotanTOTP :: Ptr BotanTOTPStruct } + = MkBotanTOTP { ptr :: Ptr BotanTOTPStruct } deriving newtype (Eq, Ord, Storable) -- | Destroy a TOTP instance diff --git a/botan-bindings/src/Botan/Bindings/X509.hsc b/botan-bindings/src/Botan/Bindings/X509.hsc index cd73a657..ec8d7fb6 100644 --- a/botan-bindings/src/Botan/Bindings/X509.hsc +++ b/botan-bindings/src/Botan/Bindings/X509.hsc @@ -82,7 +82,7 @@ data {-# CTYPE "botan/ffi.h" "struct botan_x509_cert_struct" #-} BotanX509CertSt -- | Botan X509Cert object newtype {-# CTYPE "botan/ffi.h" "botan_x509_cert_t" #-} BotanX509Cert - = MkBotanX509Cert { runBotanX509Cert :: Ptr BotanX509CertStruct } + = MkBotanX509Cert { ptr :: Ptr BotanX509CertStruct } deriving newtype (Eq, Ord, Storable) -- | Destroy a X509Cert instance @@ -295,7 +295,7 @@ data {-# CTYPE "botan/ffi.h" "struct botan_x509_crl_struct" #-} BotanX509CRLStru -- | Botan X509CRL object newtype {-# CTYPE "botan/ffi.h" "botan_x509_crl_t" #-} BotanX509CRL - = MkBotanX509CRL { runBotanX509CRL :: Ptr BotanX509CRLStruct } + = MkBotanX509CRL { ptr :: Ptr BotanX509CRLStruct } deriving newtype (Eq, Ord, Storable) -- | Destroy a X509CRL instance diff --git a/botan-low/src/Botan/Low/BlockCipher.hs b/botan-low/src/Botan/Low/BlockCipher.hs index 0c90e2bc..e6cf7e74 100644 --- a/botan-low/src/Botan/Low/BlockCipher.hs +++ b/botan-low/src/Botan/Low/BlockCipher.hs @@ -189,7 +189,7 @@ True -------------------------------------------------------------------------------} -- | A mutable block cipher object -newtype BlockCipher = MkBlockCipher { getBlockCipherForeignPtr :: ForeignPtr BotanBlockCipherStruct } +newtype BlockCipher = MkBlockCipher { foreignPtr :: ForeignPtr BotanBlockCipherStruct } withBlockCipher :: BlockCipher -> (BotanBlockCipher -> IO a) -> IO a -- | Destroy a block cipher object immediately @@ -197,8 +197,8 @@ blockCipherDestroy :: BlockCipher -> IO () createBlockCipher :: (Ptr BotanBlockCipher -> IO CInt) -> IO BlockCipher (withBlockCipher, blockCipherDestroy, createBlockCipher) = mkBindings - MkBotanBlockCipher (.runBotanBlockCipher) - MkBlockCipher (.getBlockCipherForeignPtr) + MkBotanBlockCipher (.ptr) + MkBlockCipher (.foreignPtr) botan_block_cipher_destroy diff --git a/botan-low/src/Botan/Low/Cipher.hs b/botan-low/src/Botan/Low/Cipher.hs index 2bce575a..eecaa2b7 100644 --- a/botan-low/src/Botan/Low/Cipher.hs +++ b/botan-low/src/Botan/Low/Cipher.hs @@ -195,7 +195,7 @@ If you are encrypting or decrypting multiple messages with the same key, you can -- NOTE: This is *symmetric* ciphers For the 'raw' interface to ECB mode block ciphers, see BlockCipher.hs -newtype Cipher = MkCipher { getCipherForeignPtr :: ForeignPtr BotanCipherStruct } +newtype Cipher = MkCipher { foreignPtr :: ForeignPtr BotanCipherStruct } withCipher :: Cipher -> (BotanCipher -> IO a) -> IO a -- | Destroy the cipher object immediately @@ -203,8 +203,8 @@ cipherDestroy :: Cipher -> IO () createCipher :: (Ptr BotanCipher -> IO CInt) -> IO Cipher (withCipher, cipherDestroy, createCipher) = mkBindings - MkBotanCipher (.runBotanCipher) - MkCipher (.getCipherForeignPtr) + MkBotanCipher (.ptr) + MkCipher (.foreignPtr) botan_cipher_destroy type CipherNonce = ByteString diff --git a/botan-low/src/Botan/Low/FPE.hs b/botan-low/src/Botan/Low/FPE.hs index c8d95632..995490fa 100644 --- a/botan-low/src/Botan/Low/FPE.hs +++ b/botan-low/src/Botan/Low/FPE.hs @@ -73,15 +73,15 @@ import Foreign.Ptr -- * Format Preserving Encryption -- */ -newtype FPE = MkFPE { getFPEForeignPtr :: ForeignPtr BotanFPEStruct } +newtype FPE = MkFPE { foreignPtr :: ForeignPtr BotanFPEStruct } withFPE :: FPE -> (BotanFPE -> IO a) -> IO a fpeDestroy :: FPE -> IO () createFPE :: (Ptr BotanFPE -> IO CInt) -> IO FPE (withFPE, fpeDestroy, createFPE) = mkBindings - MkBotanFPE (.runBotanFPE) - MkFPE (.getFPEForeignPtr) + MkBotanFPE (.ptr) + MkFPE (.foreignPtr) botan_fpe_destroy data FPEFlags = diff --git a/botan-low/src/Botan/Low/HOTP.hs b/botan-low/src/Botan/Low/HOTP.hs index 38071612..ab41b66c 100644 --- a/botan-low/src/Botan/Low/HOTP.hs +++ b/botan-low/src/Botan/Low/HOTP.hs @@ -166,15 +166,15 @@ The user should then be notified. -} -newtype HOTP = MkHOTP { getHOTPForeignPtr :: ForeignPtr BotanHOTPStruct } +newtype HOTP = MkHOTP { foreignPtr :: ForeignPtr BotanHOTPStruct } withHOTP :: HOTP -> (BotanHOTP -> IO a) -> IO a hotpDestroy :: HOTP -> IO () createHOTP :: (Ptr BotanHOTP -> IO CInt) -> IO HOTP (withHOTP, hotpDestroy, createHOTP) = mkBindings - MkBotanHOTP (.runBotanHOTP) - MkHOTP (.getHOTPForeignPtr) + MkBotanHOTP (.ptr) + MkHOTP (.foreignPtr) botan_hotp_destroy type HOTPHashName = HashName diff --git a/botan-low/src/Botan/Low/Hash.hs b/botan-low/src/Botan/Low/Hash.hs index 534b0d36..c46ca2e3 100644 --- a/botan-low/src/Botan/Low/Hash.hs +++ b/botan-low/src/Botan/Low/Hash.hs @@ -139,15 +139,15 @@ You can clear a hash's state, leaving it ready for reuse: -} -newtype Hash = MkHash { getHashForeignPtr :: ForeignPtr BotanHashStruct } +newtype Hash = MkHash { foreignPtr :: ForeignPtr BotanHashStruct } withHash :: Hash -> (BotanHash -> IO a) -> IO a hashDestroy :: Hash -> IO () createHash :: (Ptr BotanHash -> IO CInt) -> IO Hash (withHash, hashDestroy, createHash) = mkBindings - MkBotanHash (.runBotanHash) - MkHash (.getHashForeignPtr) + MkBotanHash (.ptr) + MkHash (.foreignPtr) botan_hash_destroy type HashName = ByteString diff --git a/botan-low/src/Botan/Low/MAC.hs b/botan-low/src/Botan/Low/MAC.hs index 54b60f02..fe6f465d 100644 --- a/botan-low/src/Botan/Low/MAC.hs +++ b/botan-low/src/Botan/Low/MAC.hs @@ -162,15 +162,15 @@ If you must use GMAC, a nonce needs to be set: -- * Message Authentication type -- */ -newtype MAC = MkMAC { getMACForeignPtr :: ForeignPtr BotanMACStruct } +newtype MAC = MkMAC { foreignPtr :: ForeignPtr BotanMACStruct } withMAC :: MAC -> (BotanMAC -> IO a) -> IO a macDestroy :: MAC -> IO () createMAC :: (Ptr BotanMAC -> IO CInt) -> IO MAC (withMAC, macDestroy, createMAC) = mkBindings - MkBotanMAC (.runBotanMAC) - MkMAC (.getMACForeignPtr) + MkBotanMAC (.ptr) + MkMAC (.foreignPtr) botan_mac_destroy type MACName = ByteString diff --git a/botan-low/src/Botan/Low/MPI.hs b/botan-low/src/Botan/Low/MPI.hs index ea80fbb3..0c846872 100644 --- a/botan-low/src/Botan/Low/MPI.hs +++ b/botan-low/src/Botan/Low/MPI.hs @@ -85,15 +85,15 @@ import Foreign.Storable -- NOTE: This whole module is not idiomatic - some methods mutate, some have a destination argument -- It will need furter wrapping. -newtype MP = MkMP { getMPForeignPtr :: ForeignPtr BotanMPStruct } +newtype MP = MkMP { foreignPtr :: ForeignPtr BotanMPStruct } withMP :: MP -> (BotanMP -> IO a) -> IO a mpDestroy :: MP -> IO () createMP :: (Ptr BotanMP -> IO CInt) -> IO MP (withMP, mpDestroy, createMP) = mkBindings - MkBotanMP (.runBotanMP) - MkMP (.getMPForeignPtr) + MkBotanMP (.ptr) + MkMP (.foreignPtr) botan_mp_destroy mpInit :: IO MP diff --git a/botan-low/src/Botan/Low/PubKey.hs b/botan-low/src/Botan/Low/PubKey.hs index 97834b07..cf4ba7b5 100644 --- a/botan-low/src/Botan/Low/PubKey.hs +++ b/botan-low/src/Botan/Low/PubKey.hs @@ -281,15 +281,15 @@ Verify a message: -- * Public/private key creation, import, ... -- */ -newtype PrivKey = MkPrivKey { getPrivKeyForeignPtr :: ForeignPtr BotanPrivKeyStruct } +newtype PrivKey = MkPrivKey { foreignPtr :: ForeignPtr BotanPrivKeyStruct } withPrivKey :: PrivKey -> (BotanPrivKey -> IO a) -> IO a privKeyDestroy :: PrivKey -> IO () createPrivKey :: (Ptr BotanPrivKey -> IO CInt) -> IO PrivKey (withPrivKey, privKeyDestroy, createPrivKey) = mkBindings - MkBotanPrivKey (.runBotanPrivKey) - MkPrivKey (.getPrivKeyForeignPtr) + MkBotanPrivKey (.ptr) + MkPrivKey (.foreignPtr) botan_privkey_destroy type PKName = ByteString @@ -672,15 +672,15 @@ privKeyAlgoName = mkGetCString withPrivKey botan_privkey_algo_name -- -> IO ByteString -- privKeyExportEncryptedPBKDFIter = undefined -newtype PubKey = MkPubKey { getPubKeyForeignPtr :: ForeignPtr BotanPubKeyStruct } +newtype PubKey = MkPubKey { foreignPtr :: ForeignPtr BotanPubKeyStruct } withPubKey :: PubKey -> (BotanPubKey -> IO a) -> IO a pubKeyDestroy :: PubKey -> IO () createPubKey :: (Ptr BotanPubKey -> IO CInt) -> IO PubKey (withPubKey, pubKeyDestroy, createPubKey) = mkBindings - MkBotanPubKey (.runBotanPubKey) - MkPubKey (.getPubKeyForeignPtr) + MkBotanPubKey (.ptr) + MkPubKey (.foreignPtr) botan_pubkey_destroy pubKeyLoad diff --git a/botan-low/src/Botan/Low/PubKey/Decrypt.hs b/botan-low/src/Botan/Low/PubKey/Decrypt.hs index 20a828b0..d797259d 100644 --- a/botan-low/src/Botan/Low/PubKey/Decrypt.hs +++ b/botan-low/src/Botan/Low/PubKey/Decrypt.hs @@ -41,15 +41,15 @@ import Foreign.Storable -- * Public Key Decryption -- */ -newtype Decrypt = MkDecrypt { getDecryptForeignPtr :: ForeignPtr BotanPKOpDecryptStruct } +newtype Decrypt = MkDecrypt { foreignPtr :: ForeignPtr BotanPKOpDecryptStruct } withDecrypt :: Decrypt -> (BotanPKOpDecrypt -> IO a) -> IO a decryptDestroy :: Decrypt -> IO () createDecrypt :: (Ptr BotanPKOpDecrypt -> IO CInt) -> IO Decrypt (withDecrypt, decryptDestroy, createDecrypt) = mkBindings - MkBotanPKOpDecrypt (.runBotanPKOpDecrypt) - MkDecrypt (.getDecryptForeignPtr) + MkBotanPKOpDecrypt (.ptr) + MkDecrypt (.foreignPtr) botan_pk_op_decrypt_destroy decryptCreate diff --git a/botan-low/src/Botan/Low/PubKey/Encrypt.hs b/botan-low/src/Botan/Low/PubKey/Encrypt.hs index 2d48148c..5f092688 100644 --- a/botan-low/src/Botan/Low/PubKey/Encrypt.hs +++ b/botan-low/src/Botan/Low/PubKey/Encrypt.hs @@ -42,15 +42,15 @@ import Foreign.Storable -- * Public Key Encryption -- */ -newtype Encrypt = MkEncrypt { getEncryptForeignPtr :: ForeignPtr BotanPKOpEncryptStruct } +newtype Encrypt = MkEncrypt { foreignPtr :: ForeignPtr BotanPKOpEncryptStruct } withEncrypt :: Encrypt -> (BotanPKOpEncrypt -> IO a) -> IO a encryptDestroy :: Encrypt -> IO () createEncrypt :: (Ptr BotanPKOpEncrypt -> IO CInt) -> IO Encrypt (withEncrypt, encryptDestroy, createEncrypt) = mkBindings - MkBotanPKOpEncrypt (.runBotanPKOpEncrypt) - MkEncrypt (.getEncryptForeignPtr) + MkBotanPKOpEncrypt (.ptr) + MkEncrypt (.foreignPtr) botan_pk_op_encrypt_destroy encryptCreate diff --git a/botan-low/src/Botan/Low/PubKey/KeyAgreement.hs b/botan-low/src/Botan/Low/PubKey/KeyAgreement.hs index 73419858..1987e896 100644 --- a/botan-low/src/Botan/Low/PubKey/KeyAgreement.hs +++ b/botan-low/src/Botan/Low/PubKey/KeyAgreement.hs @@ -115,15 +115,15 @@ agreed-upon salt: -} -newtype KeyAgreement = MkKeyAgreement { getKeyAgreementForeignPtr :: ForeignPtr BotanPKOpKeyAgreementStruct } +newtype KeyAgreement = MkKeyAgreement { foreignPtr :: ForeignPtr BotanPKOpKeyAgreementStruct } withKeyAgreement :: KeyAgreement -> (BotanPKOpKeyAgreement -> IO a) -> IO a keyAgreementDestroy :: KeyAgreement -> IO () createKeyAgreement :: (Ptr BotanPKOpKeyAgreement -> IO CInt) -> IO KeyAgreement (withKeyAgreement, keyAgreementDestroy, createKeyAgreement) = mkBindings - MkBotanPKOpKeyAgreement (.runBotanPKOpKeyAgreement) - MkKeyAgreement (.getKeyAgreementForeignPtr) + MkBotanPKOpKeyAgreement (.ptr) + MkKeyAgreement (.foreignPtr) botan_pk_op_key_agreement_destroy -- NOTE: Silently uses the system RNG diff --git a/botan-low/src/Botan/Low/PubKey/KeyEncapsulation.hs b/botan-low/src/Botan/Low/PubKey/KeyEncapsulation.hs index 76b69405..17cae307 100644 --- a/botan-low/src/Botan/Low/PubKey/KeyEncapsulation.hs +++ b/botan-low/src/Botan/Low/PubKey/KeyEncapsulation.hs @@ -120,15 +120,15 @@ Then, this shared key may be used for any suitable purpose. type KEMSharedKey = ByteString type KEMEncapsulatedKey = ByteString -newtype KEMEncrypt = MkKEMEncrypt { getKEMEncryptForeignPtr :: ForeignPtr BotanPKOpKEMEncryptStruct } +newtype KEMEncrypt = MkKEMEncrypt { foreignPtr :: ForeignPtr BotanPKOpKEMEncryptStruct } withKEMEncrypt :: KEMEncrypt -> (BotanPKOpKEMEncrypt -> IO a) -> IO a kemEncryptDestroy :: KEMEncrypt -> IO () createKEMEncrypt :: (Ptr BotanPKOpKEMEncrypt -> IO CInt) -> IO KEMEncrypt (withKEMEncrypt, kemEncryptDestroy, createKEMEncrypt) = mkBindings - MkBotanPKOpKEMEncrypt (.runBotanPKOpKEMEncrypt) - MkKEMEncrypt (.getKEMEncryptForeignPtr) + MkBotanPKOpKEMEncrypt (.ptr) + MkKEMEncrypt (.foreignPtr) botan_pk_op_kem_encrypt_destroy @@ -191,15 +191,15 @@ kemEncryptCreateSharedKey ke rng salt desiredLen = withKEMEncrypt ke $ \ kePtr - encapPtr encapSzPtr -newtype KEMDecrypt = MkKEMDecrypt { getKEMDecryptForeignPtr :: ForeignPtr BotanPKOpKEMDecryptStruct } +newtype KEMDecrypt = MkKEMDecrypt { foreignPtr :: ForeignPtr BotanPKOpKEMDecryptStruct } withKEMDecrypt :: KEMDecrypt -> (BotanPKOpKEMDecrypt -> IO a) -> IO a kemDecryptDestroy :: KEMDecrypt -> IO () createKEMDecrypt :: (Ptr BotanPKOpKEMDecrypt -> IO CInt) -> IO KEMDecrypt (withKEMDecrypt, kemDecryptDestroy, createKEMDecrypt) = mkBindings - MkBotanPKOpKEMDecrypt (.runBotanPKOpKEMDecrypt) - MkKEMDecrypt (.getKEMDecryptForeignPtr) + MkBotanPKOpKEMDecrypt (.ptr) + MkKEMDecrypt (.foreignPtr) botan_pk_op_kem_decrypt_destroy kemDecryptCreate diff --git a/botan-low/src/Botan/Low/PubKey/Sign.hs b/botan-low/src/Botan/Low/PubKey/Sign.hs index 6128f505..83d459bd 100644 --- a/botan-low/src/Botan/Low/PubKey/Sign.hs +++ b/botan-low/src/Botan/Low/PubKey/Sign.hs @@ -46,15 +46,15 @@ import Foreign.Storable -- * Signature Generation -- */ -newtype Sign = MkSign { getSignForeignPtr :: ForeignPtr BotanPKOpSignStruct } +newtype Sign = MkSign { foreignPtr :: ForeignPtr BotanPKOpSignStruct } withSign :: Sign -> (BotanPKOpSign -> IO a) -> IO a signDestroy :: Sign -> IO () createSign :: (Ptr BotanPKOpSign -> IO CInt) -> IO Sign (withSign, signDestroy, createSign) = mkBindings - MkBotanPKOpSign (.runBotanPKOpSign) - MkSign (.getSignForeignPtr) + MkBotanPKOpSign (.ptr) + MkSign (.foreignPtr) botan_pk_op_sign_destroy data SigningFlags = diff --git a/botan-low/src/Botan/Low/PubKey/Verify.hs b/botan-low/src/Botan/Low/PubKey/Verify.hs index fe285569..b39d81c5 100644 --- a/botan-low/src/Botan/Low/PubKey/Verify.hs +++ b/botan-low/src/Botan/Low/PubKey/Verify.hs @@ -37,15 +37,15 @@ import Foreign.Ptr -- * Signature Verification -- */ -newtype Verify = MkVerify { getVerifyForeignPtr :: ForeignPtr BotanPKOpVerifyStruct } +newtype Verify = MkVerify { foreignPtr :: ForeignPtr BotanPKOpVerifyStruct } withVerify :: Verify -> (BotanPKOpVerify -> IO a) -> IO a verifyDestroy :: Verify -> IO () createVerify :: (Ptr BotanPKOpVerify -> IO CInt) -> IO Verify (withVerify, verifyDestroy, createVerify) = mkBindings - MkBotanPKOpVerify (.runBotanPKOpVerify) - MkVerify (.getVerifyForeignPtr) + MkBotanPKOpVerify (.ptr) + MkVerify (.foreignPtr) botan_pk_op_verify_destroy verifyCreate diff --git a/botan-low/src/Botan/Low/RNG.hs b/botan-low/src/Botan/Low/RNG.hs index fd313726..86211901 100644 --- a/botan-low/src/Botan/Low/RNG.hs +++ b/botan-low/src/Botan/Low/RNG.hs @@ -90,14 +90,14 @@ You can also seed it with your own entropy; this is safe and can never -- NOTE: Uses ConstPtr / unConstPtr manually -- TODO: Take advantage of Remake / better peek / (peekConst or constPeek) functions -newtype RNG = MkRNG { getRNGForeignPtr :: ForeignPtr BotanRNGStruct } +newtype RNG = MkRNG { foreignPtr :: ForeignPtr BotanRNGStruct } withRNG :: RNG -> (BotanRNG -> IO a) -> IO a -- | Destroy a random number generator object immediately rngDestroy :: RNG -> IO () createRNG :: (Ptr BotanRNG -> IO CInt) -> IO RNG (withRNG, rngDestroy, createRNG) - = mkBindings MkBotanRNG (.runBotanRNG) MkRNG (.getRNGForeignPtr) botan_rng_destroy + = mkBindings MkBotanRNG (.ptr) MkRNG (.foreignPtr) botan_rng_destroy type RNGType = ByteString diff --git a/botan-low/src/Botan/Low/SRP6.hs b/botan-low/src/Botan/Low/SRP6.hs index 2d8c029c..6ce6b63c 100644 --- a/botan-low/src/Botan/Low/SRP6.hs +++ b/botan-low/src/Botan/Low/SRP6.hs @@ -276,7 +276,7 @@ type SRP6BValue = ByteString type SRP6AValue = ByteString type SRP6SharedSecret = ByteString -newtype SRP6ServerSession = MkSRP6ServerSession { getSRP6ServerSessionForeignPtr :: ForeignPtr BotanSRP6ServerSessionStruct } +newtype SRP6ServerSession = MkSRP6ServerSession { foreignPtr :: ForeignPtr BotanSRP6ServerSessionStruct } withSRP6ServerSession :: SRP6ServerSession -> (BotanSRP6ServerSession -> IO a) -> IO a -- | Frees all resources of the SRP-6 server session object @@ -284,8 +284,8 @@ srp6ServerSessionDestroy :: SRP6ServerSession -> IO () createSRP6ServerSession :: (Ptr BotanSRP6ServerSession -> IO CInt) -> IO SRP6ServerSession (withSRP6ServerSession, srp6ServerSessionDestroy, createSRP6ServerSession) = mkBindings - MkBotanSRP6ServerSession (.runBotanSRP6ServerSession) - MkSRP6ServerSession (.getSRP6ServerSessionForeignPtr) + MkBotanSRP6ServerSession (.ptr) + MkSRP6ServerSession (.foreignPtr) botan_srp6_server_session_destroy -- | Initialize an SRP-6 server session object diff --git a/botan-low/src/Botan/Low/TOTP.hs b/botan-low/src/Botan/Low/TOTP.hs index bf7b2fbe..576c697a 100644 --- a/botan-low/src/Botan/Low/TOTP.hs +++ b/botan-low/src/Botan/Low/TOTP.hs @@ -160,15 +160,15 @@ The user should then be notified. -} -newtype TOTP = MkTOTP { getTOTPForeignPtr :: ForeignPtr BotanTOTPStruct } +newtype TOTP = MkTOTP { foreignPtr :: ForeignPtr BotanTOTPStruct } withTOTP :: TOTP -> (BotanTOTP -> IO a) -> IO a totpDestroy :: TOTP -> IO () createTOTP :: (Ptr BotanTOTP -> IO CInt) -> IO TOTP (withTOTP, totpDestroy, createTOTP) = mkBindings - MkBotanTOTP (.runBotanTOTP) - MkTOTP (.getTOTPForeignPtr) + MkBotanTOTP (.ptr) + MkTOTP (.foreignPtr) botan_totp_destroy type TOTPHashName = HashName diff --git a/botan-low/src/Botan/Low/X509.hs b/botan-low/src/Botan/Low/X509.hs index 1e8dba78..c6890678 100644 --- a/botan-low/src/Botan/Low/X509.hs +++ b/botan-low/src/Botan/Low/X509.hs @@ -97,14 +97,14 @@ import Foreign.Storable type DistinguishedName = ByteString -newtype X509Cert = MkX509Cert { getX509CertForeignPtr :: ForeignPtr BotanX509CertStruct } +newtype X509Cert = MkX509Cert { foreignPtr :: ForeignPtr BotanX509CertStruct } withX509Cert :: X509Cert -> (BotanX509Cert -> IO a) -> IO a -- | Destroy an x509 cert object immediately x509CertDestroy :: X509Cert -> IO () createX509Cert :: (Ptr BotanX509Cert -> IO CInt) -> IO X509Cert (withX509Cert, x509CertDestroy, createX509Cert) - = mkBindings MkBotanX509Cert (.runBotanX509Cert) MkX509Cert (.getX509CertForeignPtr) botan_x509_cert_destroy + = mkBindings MkBotanX509Cert (.ptr) MkX509Cert (.foreignPtr) botan_x509_cert_destroy x509CertLoad :: ByteString -- ^ __cert[]__ @@ -352,13 +352,13 @@ x509CertValidationStatus code = do -- TODO: Move to Botan.Low.X509.CRL after merging extended FFI -newtype X509CRL = MkX509CRL { getX509CRLForeignPtr :: ForeignPtr BotanX509CRLStruct } +newtype X509CRL = MkX509CRL { foreignPtr :: ForeignPtr BotanX509CRLStruct } withX509CRL :: X509CRL -> (BotanX509CRL -> IO a) -> IO a x509CRLDestroy :: X509CRL -> IO () createX509CRL :: (Ptr BotanX509CRL -> IO CInt) -> IO X509CRL (withX509CRL, x509CRLDestroy, createX509CRL) - = mkBindings MkBotanX509CRL (.runBotanX509CRL) MkX509CRL (.getX509CRLForeignPtr) botan_x509_crl_destroy + = mkBindings MkBotanX509CRL (.ptr) MkX509CRL (.foreignPtr) botan_x509_crl_destroy x509CRLLoad :: ByteString -- ^ __crl_bits[]__ diff --git a/botan/src/Botan/BlockCipher.hs b/botan/src/Botan/BlockCipher.hs index c34750ff..1d5bdb2a 100644 --- a/botan/src/Botan/BlockCipher.hs +++ b/botan/src/Botan/BlockCipher.hs @@ -201,7 +201,7 @@ blockCiphers = -- 128-bit block cipher type -newtype BlockCipher128 = MkBlockCipher128 { unBlockCipher128 :: BlockCipher } +newtype BlockCipher128 = MkBlockCipher128 { un :: BlockCipher } deriving stock (Eq, Ord, Show) blockCipher128 :: BlockCipher -> Maybe BlockCipher128 @@ -243,10 +243,10 @@ isBlockCipher128 :: BlockCipher -> Bool isBlockCipher128 = isJust . blockCipher128 blockCipher128Name :: BlockCipher128 -> Low.BlockCipherName -blockCipher128Name = blockCipherName . (.unBlockCipher128) +blockCipher128Name = blockCipherName . (.un) blockCipher128KeySpec :: BlockCipher128 -> BlockCipherKeySpec -blockCipher128KeySpec = blockCipherKeySpec . (.unBlockCipher128) +blockCipher128KeySpec = blockCipherKeySpec . (.un) -- Associated types @@ -429,7 +429,7 @@ blockCipherDecryptLazy = undefined -- Tagged mutable context data MutableBlockCipher = MkMutableBlockCipher - { algo :: BlockCipher + { inner :: BlockCipher , ctx :: Low.BlockCipher } diff --git a/botan/src/Botan/Cipher.hs b/botan/src/Botan/Cipher.hs index add39dd3..e045cc1f 100644 --- a/botan/src/Botan/Cipher.hs +++ b/botan/src/Botan/Cipher.hs @@ -215,7 +215,7 @@ data CBCPadding -- AEAD data type -newtype AEAD = MkAEAD { unAEAD :: Cipher } +newtype AEAD = MkAEAD { un :: Cipher } deriving stock (Eq, Ord, Show) aead :: Cipher -> Maybe AEAD @@ -240,7 +240,7 @@ ciphers = concat [ [ CBC bc pd | bc <- blockCiphers, pd <- cbcPaddings ] , [ CFB bc (8 * blockCipherBlockSize bc) | bc <- blockCiphers ] , [ XTS bc | bc <- blockCiphers ] - , fmap (.unAEAD) aeads + , fmap (.un) aeads ] cbcPaddings :: [ CBCPadding ] @@ -363,7 +363,7 @@ cipherNonceSizeIsValid n (CFB bc _) = n == blockCipherBlockSize bc cipherNonceSizeIsValid n (XTS bc) = 1 <= n && n <= blockCipherBlockSize bc -- Always [ 1 .. 16 ] cipherNonceSizeIsValid n _haCha20Poly1305 = n `elem` [ 8, 12, 24 ] cipherNonceSizeIsValid n (GCM _ _) = 1 <= n && n <= internalMaximumCipherNonceSize -- True if unbounded -cipherNonceSizeIsValid n (OCB bc128 _) = 1 <= n && n <= blockCipherBlockSize bc128.unBlockCipher128 - 1 -- Always [ 1 .. 15 ] +cipherNonceSizeIsValid n (OCB bc128 _) = 1 <= n && n <= blockCipherBlockSize bc128.un - 1 -- Always [ 1 .. 15 ] cipherNonceSizeIsValid n (EAX _ _) = 1 <= n && n <= internalMaximumCipherNonceSize -- True if unbounded cipherNonceSizeIsValid n (SIV _) = 1 <= n && n <= internalMaximumCipherNonceSize -- True if unbounded cipherNonceSizeIsValid n (CCM _ _ _) = n == 12 @@ -419,8 +419,8 @@ cipherUpdateGranularity (CBC bc _) = blockCipherBlockSize bc cipherUpdateGranularity (CFB bc _) = blockCipherBlockSize bc cipherUpdateGranularity (XTS bc) = 2 * blockCipherBlockSize bc cipherUpdateGranularity ChaCha20Poly1305 = 1 -cipherUpdateGranularity (GCM bc128 _) = blockCipherBlockSize bc128.unBlockCipher128 -- always 16 -cipherUpdateGranularity (OCB bc128 _) = blockCipherBlockSize bc128.unBlockCipher128 -- always 16 +cipherUpdateGranularity (GCM bc128 _) = blockCipherBlockSize bc128.un -- always 16 +cipherUpdateGranularity (OCB bc128 _) = blockCipherBlockSize bc128.un -- always 16 cipherUpdateGranularity (EAX _ _) = 1 cipherUpdateGranularity (SIV _) = 1 cipherUpdateGranularity (CCM _ _ _) = 1 @@ -489,7 +489,7 @@ cipherDecryptLazy = undefined -- TODO: Wrap in Maybe aeadEncrypt :: AEAD -> CipherKey -> CipherNonce -> AEADAssociatedData -> ByteString -> Ciphertext aeadEncrypt c k n ad msg = unsafePerformIO $ do - ctx <- newCipher c.unAEAD CipherEncrypt + ctx <- newCipher c.un CipherEncrypt setCipherKey ctx k setAEADAssociatedData ctx ad startCipher ctx n @@ -498,7 +498,7 @@ aeadEncrypt c k n ad msg = unsafePerformIO $ do aeadDecrypt :: AEAD -> CipherKey -> CipherNonce -> AEADAssociatedData -> Ciphertext -> Maybe ByteString aeadDecrypt c k n ad ct = unsafePerformIO $ do - ctx <- newCipher c.unAEAD CipherDecrypt + ctx <- newCipher c.un CipherDecrypt setCipherKey ctx k setAEADAssociatedData ctx ad startCipher ctx n diff --git a/botan/src/Botan/Hash.hs b/botan/src/Botan/Hash.hs index 8d8db100..6f0d49a5 100644 --- a/botan/src/Botan/Hash.hs +++ b/botan/src/Botan/Hash.hs @@ -197,7 +197,7 @@ data Hash -- | Comb4P Hash Hash deriving stock (Eq, Ord, Show) -newtype CryptoHash = MkCryptoHash { unCryptoHash :: Hash } +newtype CryptoHash = MkCryptoHash { un :: Hash } deriving stock (Eq, Ord, Show) isCryptoHash :: Hash -> Bool @@ -229,7 +229,7 @@ isCryptoHash Streebog512 = True isCryptoHash Whirlpool = True isCryptoHash _ = False -newtype Checksum = MkChecksum { unChecksum :: Hash } +newtype Checksum = MkChecksum { un :: Hash } deriving stock (Eq, Ord, Show) isChecksum :: Hash -> Bool @@ -474,7 +474,7 @@ hashFileLazy h fp = do -- Tagged mutable context data MutableHash = MkMutableHash - { algo :: Hash + { inner :: Hash , ctx :: Low.Hash } @@ -524,7 +524,7 @@ copyHashState -> m MutableHash copyHashState mh = do ctx <- liftIO $ Low.hashCopyState mh.ctx - return $ MkMutableHash mh.algo ctx + return $ MkMutableHash mh.inner ctx clearHash :: (MonadIO m) diff --git a/botan/src/Botan/MAC.hs b/botan/src/Botan/MAC.hs index acf1b52f..897416cf 100644 --- a/botan/src/Botan/MAC.hs +++ b/botan/src/Botan/MAC.hs @@ -193,7 +193,7 @@ type MACDigest = ByteString macName :: MAC -> ByteString macName (CMAC bc) = Low.cmac (blockCipherName bc) macName (GMAC bc) = Low.gmac (blockCipherName bc) -macName (HMAC h) = Low.hmac (hashName h.unCryptoHash) +macName (HMAC h) = Low.hmac (hashName h.un) macName Poly1305 = Low.Poly1305 macName (SipHash ir fr) = Low.sipHash ir fr macName X9_19_MAC = Low.X9_19_MAC @@ -232,7 +232,7 @@ generateMACKeySpec = do macDigestLength :: MAC -> Int macDigestLength (CMAC bc) = blockCipherBlockSize bc macDigestLength (GMAC _) = 16 -- Always 16 -macDigestLength (HMAC h) = hashDigestSize h.unCryptoHash +macDigestLength (HMAC h) = hashDigestSize h.un macDigestLength Poly1305 = 16 -- TODO: Check more variants macDigestLength (SipHash 2 4) = 8 @@ -293,7 +293,7 @@ gmac _ _ _ _ = error "Expected GMAC" -- Tagged mutable context data MutableMAC = MkMutableMAC - { algo :: MAC + { inner :: MAC , ctx :: Low.MAC } diff --git a/botan/src/Botan/Types/Class.hs b/botan/src/Botan/Types/Class.hs index b2796832..5537465b 100644 --- a/botan/src/Botan/Types/Class.hs +++ b/botan/src/Botan/Types/Class.hs @@ -261,11 +261,11 @@ class (HasSecretKey alg, Monad m) => SecretKeyGen alg m where newSecretKey :: m (SecretKey alg) newSecretKeyMaybe :: Int -> m (Maybe (SecretKey alg)) -newtype GSecretKey = MkGSecretKey { unGSecretKey :: ByteString } +newtype GSecretKey = MkGSecretKey { un :: ByteString } deriving newtype (Eq, Ord, Encodable) instance Show GSecretKey where - show = showByteStringHex . (.unGSecretKey) + show = showByteStringHex . (.un) -- NOTE: Cannot do g- / default implementation of new keys since we do not yet -- have the secret key constructor. @@ -299,11 +299,11 @@ class (HasNonce alg, Monad m) => NonceGen alg m where newNonce :: m (Nonce alg) newNonceMaybe :: Int -> m (Maybe (Nonce alg)) -newtype GNonce = MkGNonce { unGNonce :: ByteString } +newtype GNonce = MkGNonce { un :: ByteString } deriving newtype (Eq, Ord, Encodable) instance Show GNonce where - show = showByteStringHex . (.unGNonce) + show = showByteStringHex . (.un) -- HACK: Grodiest bytestring incrementer ever instance IsNonce GNonce where @@ -325,11 +325,11 @@ class (HasSalt alg, Monad m) => SaltGen alg m where newSalt :: m (Salt alg) newSaltMaybe :: Int -> m (Maybe (Salt alg)) -newtype GSalt = MkGSalt { unGSalt :: ByteString } +newtype GSalt = MkGSalt { un :: ByteString } deriving newtype (Eq, Ord, Encodable) instance Show GSalt where - show = showByteStringHex . (.unGSalt) + show = showByteStringHex . (.un) -- -- Password @@ -340,11 +340,11 @@ instance Show GSalt where data family Password alg -newtype GPassword = MkGPassword { unGPassword :: Text } +newtype GPassword = MkGPassword { un :: Text } deriving newtype (Eq, Ord, Encodable) instance Show GPassword where - show = Text.unpack . (.unGPassword) + show = Text.unpack . (.un) -- -- Digest @@ -354,11 +354,11 @@ data family Digest alg class (Eq (Digest alg), Ord (Digest alg), Encodable (Digest alg)) => HasDigest alg where -newtype GDigest = MkGDigest { unGDigest :: ByteString } +newtype GDigest = MkGDigest { un :: ByteString } deriving newtype (Eq, Ord, Encodable) instance Show GDigest where - show = showByteStringHex . (.unGDigest) + show = showByteStringHex . (.un) -- -- Ciphertext @@ -368,11 +368,11 @@ data family Ciphertext alg class (Eq (Ciphertext alg), Ord (Ciphertext alg), Encodable (Ciphertext alg)) => HasCiphertext alg where -newtype GCiphertext = MkGCiphertext { unGCiphertext :: ByteString } +newtype GCiphertext = MkGCiphertext { un :: ByteString } deriving newtype (Eq, Ord, Encodable) instance Show GCiphertext where - show = showByteStringHex . (.unGCiphertext) + show = showByteStringHex . (.un) -- -- Incremental Ciphertext @@ -386,11 +386,11 @@ class (HasCiphertext alg, Eq (LazyCiphertext alg), Ord (LazyCiphertext alg), Laz fromStrictCiphertext :: Ciphertext alg -> LazyCiphertext alg fromStrictCiphertext = unsafeDecodeLazy . ByteString.fromStrict . encode -newtype GLazyCiphertext = MkGLazyCiphertext { unGLazyCiphertext :: Lazy.ByteString } +newtype GLazyCiphertext = MkGLazyCiphertext { un :: Lazy.ByteString } deriving newtype (Eq, Ord, Encodable, LazyEncodable) instance Show GLazyCiphertext where - show = showByteStringHex . ByteString.toStrict . (.unGLazyCiphertext) + show = showByteStringHex . ByteString.toStrict . (.un) -- -- TODO: classes / data families for: From 7f7386368dcf229eeceaba72d3e13eebda829271 Mon Sep 17 00:00:00 2001 From: Vladislav Sabanov Date: Tue, 6 Jan 2026 18:56:29 +0500 Subject: [PATCH 3/4] Update botan/src/Botan/Cipher.hs Co-authored-by: Joris Dral --- botan/src/Botan/Cipher.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/botan/src/Botan/Cipher.hs b/botan/src/Botan/Cipher.hs index e045cc1f..7094b740 100644 --- a/botan/src/Botan/Cipher.hs +++ b/botan/src/Botan/Cipher.hs @@ -513,7 +513,7 @@ aeadDecrypt c k n ad ct = unsafePerformIO $ do -- Tagged mutable context data MutableCipher = MkMutableCipher - { algo :: Cipher + { inner :: Cipher , direction :: CipherDirection , ctx :: Low.Cipher -- , mutableCipherProcessed :: Int From a49b872e4b97f3af4e39fbfb54c0bc7657d89430 Mon Sep 17 00:00:00 2001 From: Vladislav Sabanov Date: Wed, 7 Jan 2026 11:11:13 -0300 Subject: [PATCH 4/4] Fix ci failures --- botan-bindings/src/Botan/Bindings/ConstPtr.hs | 2 +- botan-low/src/Botan/Low/Error/Internal.hs | 14 ++++++++++-- botan-low/src/Botan/Low/RNG.hs | 2 +- botan-low/src/Botan/Low/Version.hs | 9 ++++++-- botan-low/src/Botan/Low/X509.hs | 10 +++++++-- botan/src/Botan/BlockCipher.hs | 2 +- botan/src/Botan/Cipher.hs | 22 +++++++++---------- botan/src/Botan/Hash.hs | 2 +- botan/src/Botan/MAC.hs | 2 +- 9 files changed, 43 insertions(+), 22 deletions(-) diff --git a/botan-bindings/src/Botan/Bindings/ConstPtr.hs b/botan-bindings/src/Botan/Bindings/ConstPtr.hs index 73710c4a..fab3b3ea 100644 --- a/botan-bindings/src/Botan/Bindings/ConstPtr.hs +++ b/botan-bindings/src/Botan/Bindings/ConstPtr.hs @@ -27,7 +27,7 @@ import Foreign.Storable -- botan_version_string type ConstPtr :: Type -> Type type role ConstPtr phantom -newtype ConstPtr a = ConstPtr { un :: Ptr a } +newtype ConstPtr a = ConstPtr { ptr :: Ptr a } deriving stock (Data) deriving newtype (Eq, Ord, Storable) diff --git a/botan-low/src/Botan/Low/Error/Internal.hs b/botan-low/src/Botan/Low/Error/Internal.hs index 5a2373b2..f2c45ffe 100644 --- a/botan-low/src/Botan/Low/Error/Internal.hs +++ b/botan-low/src/Botan/Low/Error/Internal.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE CPP #-} + {-| Module : Botan.Low.Error Description : Error codes and exception handling @@ -73,7 +75,11 @@ newtype BotanErrorCode = BotanErrorCode CInt botanErrorDescription :: BotanErrorCode -> IO ByteString botanErrorDescription (BotanErrorCode e) = do descPtr <- botan_error_description e - peekCString descPtr.unConstPtr +#if MIN_VERSION_base (4,18,0) + peekCString (unConstPtr descPtr) +#else + peekCString descPtr.ptr +#endif newtype BotanErrorMessage = BotanErrorMessage ByteString deriving newtype Show @@ -84,7 +90,11 @@ newtype BotanErrorMessage = BotanErrorMessage ByteString botanErrorLastExceptionMessage :: IO BotanErrorMessage botanErrorLastExceptionMessage = do msgPtr <- botan_error_last_exception_message - BotanErrorMessage <$> peekCString msgPtr.unConstPtr +#if MIN_VERSION_base (4,18,0) + BotanErrorMessage <$> peekCString (unConstPtr msgPtr) +#else + BotanErrorMessage <$> peekCString msgPtr.ptr +#endif {------------------------------------------------------------------------------- Exception hierarchy diff --git a/botan-low/src/Botan/Low/RNG.hs b/botan-low/src/Botan/Low/RNG.hs index 86211901..2a451eea 100644 --- a/botan-low/src/Botan/Low/RNG.hs +++ b/botan-low/src/Botan/Low/RNG.hs @@ -87,7 +87,7 @@ You can also seed it with your own entropy; this is safe and can never -} -- NOTE: Does not take advantage of Remake --- NOTE: Uses ConstPtr / unConstPtr manually +-- NOTE: Uses ConstPtr / ptr manually (unConstPtr if base <= 4.18 ) -- TODO: Take advantage of Remake / better peek / (peekConst or constPeek) functions newtype RNG = MkRNG { foreignPtr :: ForeignPtr BotanRNGStruct } diff --git a/botan-low/src/Botan/Low/Version.hs b/botan-low/src/Botan/Low/Version.hs index 135027d3..684f9efb 100644 --- a/botan-low/src/Botan/Low/Version.hs +++ b/botan-low/src/Botan/Low/Version.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE CPP #-} + {-| Module : Botan.Low.Version Description : Botan version info @@ -43,9 +45,12 @@ botanFFIAPIVersion = fromIntegral <$> botan_ffi_api_version botanFFISupportsAPI :: Int -> IO Bool botanFFISupportsAPI version = do throwBotanCatchingInvalidInput $ botan_ffi_supports_api (fromIntegral version) - botanVersionString :: IO ByteString -botanVersionString = botan_version_string >>= peekCString . (.unConstPtr) +#if MIN_VERSION_base (4,18,0) +botanVersionString = botan_version_string >>= peekCString . unConstPtr +#else +botanVersionString = botan_version_string >>= peekCString . (.ptr) +#endif -- | Returns the major version of the library botanVersionMajor :: IO Int diff --git a/botan-low/src/Botan/Low/X509.hs b/botan-low/src/Botan/Low/X509.hs index c6890678..ce37cc4d 100644 --- a/botan-low/src/Botan/Low/X509.hs +++ b/botan-low/src/Botan/Low/X509.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE CPP #-} + {-| Module : Botan.Low.X509 Description : X.509 Certificates and CRLs @@ -344,8 +346,12 @@ x509CertValidationStatus code = do status <- botan_x509_cert_validation_status (fromIntegral code) if status == ConstPtr nullPtr then return Nothing - else Just <$> packCString status.unConstPtr - + else +#if MIN_VERSION_base (4,18,0) + Just <$> packCString (unConstPtr status) +#else + Just <$> packCString status.ptr +#endif -- /* -- * X.509 CRL -- **************************/ diff --git a/botan/src/Botan/BlockCipher.hs b/botan/src/Botan/BlockCipher.hs index 1d5bdb2a..c945bed3 100644 --- a/botan/src/Botan/BlockCipher.hs +++ b/botan/src/Botan/BlockCipher.hs @@ -430,7 +430,7 @@ blockCipherDecryptLazy = undefined data MutableBlockCipher = MkMutableBlockCipher { inner :: BlockCipher - , ctx :: Low.BlockCipher + , ctx :: Low.BlockCipher } -- Destructor diff --git a/botan/src/Botan/Cipher.hs b/botan/src/Botan/Cipher.hs index 7094b740..008a4ae1 100644 --- a/botan/src/Botan/Cipher.hs +++ b/botan/src/Botan/Cipher.hs @@ -414,16 +414,16 @@ generateCipherTagLength = do -} cipherUpdateGranularity :: Cipher -> Int -cipherUpdateGranularity (CBC bc CTS) = 2 * blockCipherBlockSize bc -cipherUpdateGranularity (CBC bc _) = blockCipherBlockSize bc -cipherUpdateGranularity (CFB bc _) = blockCipherBlockSize bc -cipherUpdateGranularity (XTS bc) = 2 * blockCipherBlockSize bc -cipherUpdateGranularity ChaCha20Poly1305 = 1 -cipherUpdateGranularity (GCM bc128 _) = blockCipherBlockSize bc128.un -- always 16 -cipherUpdateGranularity (OCB bc128 _) = blockCipherBlockSize bc128.un -- always 16 -cipherUpdateGranularity (EAX _ _) = 1 -cipherUpdateGranularity (SIV _) = 1 -cipherUpdateGranularity (CCM _ _ _) = 1 +cipherUpdateGranularity (CBC bc CTS) = 2 * blockCipherBlockSize bc +cipherUpdateGranularity (CBC bc _) = blockCipherBlockSize bc +cipherUpdateGranularity (CFB bc _) = blockCipherBlockSize bc +cipherUpdateGranularity (XTS bc) = 2 * blockCipherBlockSize bc +cipherUpdateGranularity ChaCha20Poly1305 = 1 +cipherUpdateGranularity (GCM bc128 _) = blockCipherBlockSize bc128.un -- always 16 +cipherUpdateGranularity (OCB bc128 _) = blockCipherBlockSize bc128.un -- always 16 +cipherUpdateGranularity (EAX _ _) = 1 +cipherUpdateGranularity (SIV _) = 1 +cipherUpdateGranularity (CCM _ _ _) = 1 -- NOTE: Extracted / confirmed from inspecting: {- generateCipherUpdateGranularity :: IO () @@ -513,7 +513,7 @@ aeadDecrypt c k n ad ct = unsafePerformIO $ do -- Tagged mutable context data MutableCipher = MkMutableCipher - { inner :: Cipher + { inner :: Cipher , direction :: CipherDirection , ctx :: Low.Cipher -- , mutableCipherProcessed :: Int diff --git a/botan/src/Botan/Hash.hs b/botan/src/Botan/Hash.hs index 6f0d49a5..8e011e26 100644 --- a/botan/src/Botan/Hash.hs +++ b/botan/src/Botan/Hash.hs @@ -475,7 +475,7 @@ hashFileLazy h fp = do data MutableHash = MkMutableHash { inner :: Hash - , ctx :: Low.Hash + , ctx :: Low.Hash } -- Destructor diff --git a/botan/src/Botan/MAC.hs b/botan/src/Botan/MAC.hs index 897416cf..72fbd0c8 100644 --- a/botan/src/Botan/MAC.hs +++ b/botan/src/Botan/MAC.hs @@ -294,7 +294,7 @@ gmac _ _ _ _ = error "Expected GMAC" data MutableMAC = MkMutableMAC { inner :: MAC - , ctx :: Low.MAC + , ctx :: Low.MAC } -- Destructor