Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion botan-bindings/src/Botan/Bindings/BlockCipher.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion botan-bindings/src/Botan/Bindings/Cipher.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion botan-bindings/src/Botan/Bindings/ConstPtr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 { ptr :: Ptr a }
deriving stock (Data)
deriving newtype (Eq, Ord, Storable)

Expand Down
2 changes: 1 addition & 1 deletion botan-bindings/src/Botan/Bindings/FPE.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion botan-bindings/src/Botan/Bindings/HOTP.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion botan-bindings/src/Botan/Bindings/Hash.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion botan-bindings/src/Botan/Bindings/MAC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion botan-bindings/src/Botan/Bindings/MPI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions botan-bindings/src/Botan/Bindings/PubKey.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion botan-bindings/src/Botan/Bindings/PubKey/Decrypt.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion botan-bindings/src/Botan/Bindings/PubKey/Encrypt.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion botan-bindings/src/Botan/Bindings/PubKey/Sign.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion botan-bindings/src/Botan/Bindings/PubKey/Verify.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion botan-bindings/src/Botan/Bindings/RNG.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion botan-bindings/src/Botan/Bindings/SRP6.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion botan-bindings/src/Botan/Bindings/TOTP.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions botan-bindings/src/Botan/Bindings/X509.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions botan-low/src/Botan/Low/BlockCipher.hs
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,16 @@ 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
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


Expand Down
6 changes: 3 additions & 3 deletions botan-low/src/Botan/Low/Cipher.hs
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,16 @@ 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
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
Expand Down
14 changes: 12 additions & 2 deletions botan-low/src/Botan/Low/Error/Internal.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE CPP #-}

{-|
Module : Botan.Low.Error
Description : Error codes and exception handling
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions botan-low/src/Botan/Low/FPE.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
6 changes: 3 additions & 3 deletions botan-low/src/Botan/Low/HOTP.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions botan-low/src/Botan/Low/Hash.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions botan-low/src/Botan/Low/MAC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions botan-low/src/Botan/Low/MPI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading