From 0ba86b7aa3e8b81208433a170c571121f65b6487 Mon Sep 17 00:00:00 2001 From: Joris Dral Date: Tue, 13 Jan 2026 17:03:25 +0100 Subject: [PATCH 1/2] Undo renaming of `unConstPtr` newtype record field to `ptr` in PR #114 We should probably keep the record field the same name as the `ConstPtr` type from `base`. --- botan-bindings/src/Botan/Bindings/ConstPtr.hs | 5 +++-- 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 | 8 ++------ 5 files changed, 10 insertions(+), 28 deletions(-) diff --git a/botan-bindings/src/Botan/Bindings/ConstPtr.hs b/botan-bindings/src/Botan/Bindings/ConstPtr.hs index fab3b3e..e693341 100644 --- a/botan-bindings/src/Botan/Bindings/ConstPtr.hs +++ b/botan-bindings/src/Botan/Bindings/ConstPtr.hs @@ -1,4 +1,5 @@ -{-# LANGUAGE CPP #-} +{-# LANGUAGE CPP #-} +{-# LANGUAGE FieldSelectors #-} module Botan.Bindings.ConstPtr ( ConstPtr(..) @@ -27,7 +28,7 @@ import Foreign.Storable -- botan_version_string type ConstPtr :: Type -> Type type role ConstPtr phantom -newtype ConstPtr a = ConstPtr { ptr :: Ptr a } +newtype ConstPtr a = ConstPtr { unConstPtr :: 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 f2c45ff..5a2373b 100644 --- a/botan-low/src/Botan/Low/Error/Internal.hs +++ b/botan-low/src/Botan/Low/Error/Internal.hs @@ -1,5 +1,3 @@ -{-# LANGUAGE CPP #-} - {-| Module : Botan.Low.Error Description : Error codes and exception handling @@ -75,11 +73,7 @@ newtype BotanErrorCode = BotanErrorCode CInt botanErrorDescription :: BotanErrorCode -> IO ByteString botanErrorDescription (BotanErrorCode e) = do descPtr <- botan_error_description e -#if MIN_VERSION_base (4,18,0) - peekCString (unConstPtr descPtr) -#else - peekCString descPtr.ptr -#endif + peekCString descPtr.unConstPtr newtype BotanErrorMessage = BotanErrorMessage ByteString deriving newtype Show @@ -90,11 +84,7 @@ newtype BotanErrorMessage = BotanErrorMessage ByteString botanErrorLastExceptionMessage :: IO BotanErrorMessage botanErrorLastExceptionMessage = do msgPtr <- botan_error_last_exception_message -#if MIN_VERSION_base (4,18,0) - BotanErrorMessage <$> peekCString (unConstPtr msgPtr) -#else - BotanErrorMessage <$> peekCString msgPtr.ptr -#endif + BotanErrorMessage <$> peekCString msgPtr.unConstPtr {------------------------------------------------------------------------------- Exception hierarchy diff --git a/botan-low/src/Botan/Low/RNG.hs b/botan-low/src/Botan/Low/RNG.hs index 2a451ee..8621190 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 / ptr manually (unConstPtr if base <= 4.18 ) +-- NOTE: Uses ConstPtr / unConstPtr manually -- 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 684f9ef..135027d 100644 --- a/botan-low/src/Botan/Low/Version.hs +++ b/botan-low/src/Botan/Low/Version.hs @@ -1,5 +1,3 @@ -{-# LANGUAGE CPP #-} - {-| Module : Botan.Low.Version Description : Botan version info @@ -45,12 +43,9 @@ botanFFIAPIVersion = fromIntegral <$> botan_ffi_api_version botanFFISupportsAPI :: Int -> IO Bool botanFFISupportsAPI version = do throwBotanCatchingInvalidInput $ botan_ffi_supports_api (fromIntegral version) + botanVersionString :: IO ByteString -#if MIN_VERSION_base (4,18,0) -botanVersionString = botan_version_string >>= peekCString . unConstPtr -#else -botanVersionString = botan_version_string >>= peekCString . (.ptr) -#endif +botanVersionString = botan_version_string >>= peekCString . (.unConstPtr) -- | 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 ce37cc4..700622b 100644 --- a/botan-low/src/Botan/Low/X509.hs +++ b/botan-low/src/Botan/Low/X509.hs @@ -346,12 +346,8 @@ x509CertValidationStatus code = do status <- botan_x509_cert_validation_status (fromIntegral code) if status == ConstPtr nullPtr then return Nothing - else -#if MIN_VERSION_base (4,18,0) - Just <$> packCString (unConstPtr status) -#else - Just <$> packCString status.ptr -#endif + else Just <$> packCString status.unConstPtr + -- /* -- * X.509 CRL -- **************************/ From e6dd94fb2119ed10b0b891b3dbe4ac4d31a080c9 Mon Sep 17 00:00:00 2001 From: Joris Dral Date: Tue, 13 Jan 2026 17:21:38 +0100 Subject: [PATCH 2/2] Add changelogs for PR #114 --- botan-bindings/CHANGELOG.md | 10 ++++++++++ botan-low/CHANGELOG.md | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/botan-bindings/CHANGELOG.md b/botan-bindings/CHANGELOG.md index 44a684e..86c306d 100644 --- a/botan-bindings/CHANGELOG.md +++ b/botan-bindings/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## ?.?.?.? -- ????-??-?? + +* BREAKING: for all newtypes with a record field name like `run*`, change the + name to `ptr`. See PR's + [#114](https://github.com/haskell-cryptography/botan/pull/114) and + [#117](https://github.com/haskell-cryptography/botan/pull/117). For example. + `runBotanBlockCipher` is changed to `ptr`. +* BREAKING: re-enable `FieldSelectors` for the `ConstPtr` module. See PR + [#117](https://github.com/haskell-cryptography/botan/pull/117). + ## 0.2.0.0 -- 2025-12-30 * BREAKING: remove experimental FFI code related to `x509`. See PR diff --git a/botan-low/CHANGELOG.md b/botan-low/CHANGELOG.md index 3822218..54c76b1 100644 --- a/botan-low/CHANGELOG.md +++ b/botan-low/CHANGELOG.md @@ -11,6 +11,11 @@ * BREAKING: `x509CertAllowedUsage` now takes a list of `X509KeyConstraints` instead of a single value. See PR [#113](https://github.com/haskell-cryptography/botan/pull/113). +* BREAKING: for all newtypes with a record field name like `get*ForeignPtr`, + change the name to `foreignPtr`. See PR's + [#114](https://github.com/haskell-cryptography/botan/pull/114) and + [#117](https://github.com/haskell-cryptography/botan/pull/117). For example. + `getBlockCipherForeignPtr` is changed to `foreignPtr`. ## 0.1.0.0 -- 2025-12-30