Skip to content

Commit 7562b69

Browse files
committed
WIP: fix GHC warnings
1 parent d8af95a commit 7562b69

File tree

10 files changed

+83
-36
lines changed

10 files changed

+83
-36
lines changed

botan-bindings/botan-bindings.cabal

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,32 @@ library
141141
Botan.Bindings.X509.Path
142142
Botan.Bindings.X509.Store
143143
cpp-options: -DXFFI
144+
145+
--library x509
146+
-- if !flag(xffi)
147+
-- buildable: False
148+
--
149+
-- visibility: private
150+
-- hs-source-dirs: src
151+
-- exposed-modules:
152+
-- Botan.Bindings.X509.CA
153+
-- Botan.Bindings.X509.CRL
154+
-- Botan.Bindings.X509.CSR
155+
-- Botan.Bindings.X509.DN
156+
-- Botan.Bindings.X509.Extensions
157+
-- Botan.Bindings.X509.Options
158+
-- Botan.Bindings.X509.Path
159+
-- Botan.Bindings.X509.Store
160+
--
161+
-- -- Botan.Bindings.X509.OCSP
162+
-- cpp-options: -DXFFI
163+
--
164+
-- if flag(pkg-config)
165+
-- -- NB: pkg-config is available on windows as well when using msys2
166+
-- pkgconfig-depends: botan-3 >=3.0.0
167+
--
168+
-- else
169+
-- extra-libraries: botan-3
170+
--
171+
-- build-depends:
172+
-- , base <5

botan-low/bench/Bcrypt.hs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ longtext = ByteString.concat $ replicate 10000 $ plaintext
3737
cryptonHash :: ByteString -> Crypton.Digest Crypton.SHA3_512
3838
cryptonHash = Crypton.hash
3939

40-
botanHash :: ByteString -> IO Botan.HashDigest
41-
botanHash = Botan.hashWithName "SHA-3(512)"
40+
-- TODO: hashWithName is not exposed from Botan.Low.Hash
41+
{- botanHash :: ByteString -> IO Botan.HashDigest
42+
botanHash = Botan.hashWithName "SHA-3(512)"
43+
-}
4244

4345
main :: IO ()
4446
main = defaultMain
@@ -60,11 +62,13 @@ main = defaultMain
6062
, bench "plaintext" $ nf cryptonHash plaintext
6163
, bench "longtext" $ nf cryptonHash longtext
6264
]
63-
, bgroup "Botan"
65+
-- TODO: hashWithName is not exposed from Botan.Low.Hash
66+
{- , bgroup "Botan"
6467
[ bench "password" $ nfIO $ botanHash password
6568
, bench "plaintext" $ nfIO $ botanHash plaintext
6669
, bench "longtext" $ nfIO $ botanHash longtext
6770
]
71+
-}
6872
]
6973
]
7074

botan-low/src/Botan/Low/BlockCipher.hs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ type BlockCipherKey = ByteString
238238

239239
-- | A block cipher ciphertext
240240
type BlockCipherCiphertext = ByteString
241-
241+
242242
-- | Initialize a block cipher object
243243
blockCipherInit
244244
:: BlockCipherName -- ^ __cipher_name__
@@ -293,7 +293,6 @@ blockCipherEncryptBlocks blockCipher bytes = withBlockCipher blockCipher $ \ blo
293293
(ConstPtr bytesPtr)
294294
destPtr
295295
bytesLen
296-
{-# WARNING blockCipherEncryptBlocks "The plaintext length should be a multiple of the block size." #-}
297296

298297
{- |
299298
Decrypt one or more blocks with a block cipher.
@@ -314,7 +313,6 @@ blockCipherDecryptBlocks blockCipher bytes = withBlockCipher blockCipher $ \ blo
314313
(ConstPtr bytesPtr)
315314
destPtr
316315
bytesLen
317-
{-# WARNING blockCipherDecryptBlocks "The ciphertext length should be a multiple of the block size." #-}
318316

319317
{- |
320318
Get the name of a block cipher.

botan-low/src/Botan/Low/PubKey/KeyAgreement.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module Botan.Low.PubKey.KeyAgreement
2323
, keyAgreementDestroy
2424
, keyAgreementExportPublic
2525
, keyAgreementSize
26-
, keyAgreement
26+
, keyAgreement
2727

2828
) where
2929

@@ -80,9 +80,9 @@ First, Alice and Bob generate their private keys:
8080
> import Botan.Low.KDF
8181
> rng <- rngInit "system"
8282
> -- Alice creates her private key
83-
> alicePrivKey <- privKeyCreate ECDH Secp521r1 rng
83+
> alicePrivKey <- privKeyCreate ECDH Secp521r1 rng
8484
> -- Bob creates his private key
85-
> bobPrivKey <- privKeyCreate ECDH Secp521r1 rng
85+
> bobPrivKey <- privKeyCreate ECDH Secp521r1 rng
8686
8787
Then, they exchange their public keys using any channel, private or public:
8888
@@ -171,7 +171,8 @@ keyAgreementSize
171171
-> IO Int -- ^ __out_len__
172172
keyAgreementSize = mkGetSize withKeyAgreement botan_pk_op_key_agreement_size
173173

174-
{-# WARNING keyAgreement "This function was leaking memory and causing crashes. Please observe carefully and report any future leaks." #-}
174+
-- | TODO: This function was leaking memory and causing crashes. Please observe
175+
-- carefully and report any future leaks.
175176
keyAgreement
176177
:: KeyAgreement -- ^ __op__
177178
-> ByteString -- ^ __out[]__

botan-low/src/Botan/Low/PubKey/Sign.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,16 @@ signUpdate
9292
-- signUpdate = mkSetBytesLen withSign botan_pk_op_sign_update
9393
signUpdate = mkWithObjectSetterCBytesLen withSign botan_pk_op_sign_update
9494

95-
-- TODO: Signature type
96-
-- NOTE: This function is still highly suspect
95+
-- | Finish signing
96+
--
97+
-- Note: depending on the algorithm, signatures produced using
98+
-- StandardFormatSignature may have trailing null bytes.
9799
signFinish
98100
:: Sign -- ^ __op__
99101
-> RNG -- ^ __rng__
100102
-> IO ByteString -- ^ __sig[]__
103+
-- TODO: Signature type
104+
-- NOTE: This function is still highly suspect
101105
signFinish sign rng = withSign sign $ \ signPtr -> do
102106
withRNG rng $ \ botanRNG -> do
103107
-- NOTE: Investigation into DER format shows lots of trailing nulls that may need to be trimmed
@@ -120,7 +124,6 @@ signFinish sign rng = withSign sign $ \ signPtr -> do
120124
throwBotanIfNegative_ $ botan_pk_op_sign_finish signPtr botanRNG sigPtr szPtr
121125
peek szPtr
122126
return $!! ByteString.take (fromIntegral sz') bytes
123-
{-# WARNING signFinish "Depending on the algorithm, signatures produced using StandardFormatSignature may have trailing null bytes." #-}
124127

125128
-- /**
126129
-- * Signature Scheme Utility Functions

botan-low/src/Botan/Low/PwdHash.hs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module Botan.Low.PwdHash
3030
, pattern Bcrypt_PBKDF
3131
, pattern OpenPGP_S2K
3232
, openPGP_S2K
33-
33+
3434
) where
3535

3636
import qualified Data.ByteString as ByteString
@@ -71,6 +71,11 @@ openPGP_S2K h = OpenPGP_S2K /$ h
7171

7272
-- NOTE: Should passphrase be Text or ByteString? Text is implied by use of const char*
7373
-- as well as the non-null context implied by passphrase_len == 0. ByteString for now.
74+
75+
-- | Password hash
76+
--
77+
-- Note: 'pwdhash' and 'pwdhashTimed'\'s parameter order may be inconsistent. See
78+
-- botan-low/test/Botan/Low/PwdHashSpec.hs for more information.
7479
pwdhash
7580
:: PBKDFName -- ^ __algo__: PBKDF algorithm, e.g., "Scrypt" or "PBKDF2(SHA-256)"
7681
-> Int -- ^ __param1__: the first PBKDF algorithm parameter
@@ -95,10 +100,11 @@ pwdhash algo p1 p2 p3 outLen passphrase salt = allocBytes outLen $ \ outPtr -> d
95100
passphraseLen
96101
(ConstPtr saltPtr)
97102
saltLen
98-
{-# WARNING pwdhash "pwdhash and pwdhashTimed's parameter order may be inconsistent. See botan-low/test/Botan/Low/PwdHashSpec.hs for more information." #-}
99-
100-
101103

104+
-- | Timed password hash
105+
--
106+
-- Note: 'pwdhash' and 'pwdhashTimed'\'s parameter order may be inconsistent. See
107+
-- botan-low/test/Botan/Low/PwdHashSpec.hs for more information.
102108
pwdhashTimed
103109
:: PBKDFName -- ^ __algo__: PBKDF algorithm, e.g., "Scrypt" or "PBKDF2(SHA-256)"
104110
-> Int -- ^ __msec__: the desired runtime in milliseconds
@@ -127,4 +133,3 @@ pwdhashTimed algo msec outLen passphrase salt = alloca $ \ p1Ptr -> alloca $ \ p
127133
p2 <- fromIntegral <$> peek p2Ptr
128134
p3 <- fromIntegral <$> peek p3Ptr
129135
return (p1,p2,p3,out)
130-
{-# WARNING pwdhashTimed "pwdhash and pwdhashTimed's parameter order may be inconsistent. See botan-low/test/Botan/Low/PwdHashSpec.hs for more information." #-}

botan-low/src/Botan/Low/Remake.hs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ createByteString sz f = ByteString.create sz (f . castPtr)
6565

6666
--
6767

68-
-- type NewObject object botan = botan -> IO object
68+
-- type NewObject object botan = botan -> IO object
6969
-- type WithObject object botan = (forall a . object -> (botan -> IO a) -> IO a)
7070
-- type DestroyObject object botan = object -> IO ()
7171
-- type CreateObject object botan = (Ptr botan -> IO CInt) -> IO object
@@ -81,7 +81,7 @@ rngDestroy :: RNG -> IO ()
8181
createRNG :: (Ptr BotanRNG -> IO CInt) -> IO RNG
8282
(newRNG, withRNG, rngDestroy, createRNG, _)
8383
= mkBindings MkBotanRNG runBotanRNG MkRNG getRNGForeignPtr botan_rng_destroy
84-
84+
8585
rngInit :: RNGType -> IO RNG
8686
rngInit name = asCString name $ \ namePtr -> do
8787
createRNG $ \ outPtr -> botan_rng_init outPtr (ConstPtr namePtr)
@@ -174,15 +174,16 @@ mkCreateObjectCString1
174174
mkCreateObjectCString1 createObject init str a = withCString str $ \ cstr -> do
175175
createObject $ \ outPtr -> init outPtr (ConstPtr cstr) a
176176

177-
-- TODO: Rename mkCreateCBytes
177+
-- | Note: You probably want mkCreateObjectCBytesLen; this is for functions that
178+
-- expect a bytestring of known exact length.
178179
mkCreateObjectCBytes
179180
:: ((Ptr botan -> IO CInt) -> IO object)
180181
-> (Ptr botan -> ConstPtr Word8 -> IO CInt)
181182
-> ByteString
182183
-> IO object
184+
-- TODO: Rename mkCreateCBytes
183185
mkCreateObjectCBytes createObject init bytes = withCBytes bytes $ \ cbytes -> do
184186
createObject $ \ out -> init out (ConstPtr cbytes)
185-
{-# WARNING mkCreateObjectCBytes "You probably want mkCreateObjectCBytesLen; this is for functions that expect a bytestring of known exact length." #-}
186187

187188
-- TODO: Rename mkCreateCBytesLen
188189
mkCreateObjectCBytesLen
@@ -205,7 +206,7 @@ mkCreateObjectCBytesLen1 createObject init bytes a = withCBytesLen bytes $ \ (cb
205206
{-
206207
Action
207208
-}
208-
209+
209210
-- TODO: Rename mkAction
210211
mkWithObjectAction
211212
:: (forall a . object -> (botan -> IO a) -> IO a)
@@ -250,7 +251,7 @@ Setters
250251
-}
251252

252253
-- TODO: Rename mkSetterCString
253-
mkWithObjectSetterCString
254+
mkWithObjectSetterCString
254255
:: (forall a . object -> (botan -> IO a) -> IO a)
255256
-> (botan -> ConstPtr CChar -> IO BotanErrorCode)
256257
-> object

botan-low/src/Botan/Low/X509.hs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ x509CertGetAuthorityKeyId
183183
-> IO ByteString -- ^ __out[]__
184184
x509CertGetAuthorityKeyId = mkGetBytes withX509Cert botan_x509_cert_get_authority_key_id
185185

186-
x509CertGetSubjectKeyId
186+
x509CertGetSubjectKeyId
187187
:: X509Cert -- ^ __cert__
188188
-> IO ByteString -- ^ __out[]__
189189
x509CertGetSubjectKeyId = mkGetBytes withX509Cert botan_x509_cert_get_subject_key_id
@@ -275,21 +275,23 @@ pattern CRLSign = CRL_SIGN
275275
pattern EncipherOnly = ENCIPHER_ONLY
276276
pattern DecipherOnly = DECIPHER_ONLY
277277

278-
{-# WARNING x509CertAllowedUsage "Unexplained function, best-guess implementation" #-}
278+
-- | Note: unexplained function, best-guess implementation
279+
--
279280
-- NOTE: This function lacks documentation, and it is unknown whether this is
280-
-- setting a value (as implied by Z-botan), or whether it is using either
281-
-- a negative error or INVALID_IDENTIFIER to return a bool
281+
-- setting a value (as implied by Z-botan), or whether it is using either
282+
-- a negative error or INVALID_IDENTIFIER to return a bool
282283
x509CertAllowedUsage
283284
:: X509Cert -- ^ __cert__
284285
-> X509KeyConstraints -- ^ __key_usage__
285286
-> IO Bool
286287
x509CertAllowedUsage cert usage = withX509Cert cert $ \ certPtr -> do
287288
throwBotanCatchingSuccess $ botan_x509_cert_allowed_usage certPtr usage
288289

289-
{-# WARNING x509CertHostnameMatch "Unexplained function, best-guess implementation" #-}
290290
{- |
291291
Check if the certificate matches the specified hostname via alternative name or CN match.
292292
RFC 5280 wildcards also supported.
293+
294+
Note: unexplained function, best-guess implementation
293295
-}
294296
x509CertHostnameMatch
295297
:: X509Cert -- ^ __cert__
@@ -369,8 +371,8 @@ createX509CRL :: (Ptr BotanX509CRL -> IO CInt) -> IO X509CRL
369371
= mkBindings MkBotanX509CRL runBotanX509CRL MkX509CRL getX509CRLForeignPtr botan_x509_crl_destroy
370372

371373
x509CRLLoad
372-
:: ByteString -- ^ __crl_bits[]__
373-
-> IO X509CRL -- ^ __crl_obj__
374+
:: ByteString -- ^ __crl_bits[]__
375+
-> IO X509CRL -- ^ __crl_obj__
374376
x509CRLLoad = mkCreateObjectCBytesLen createX509CRL botan_x509_crl_load
375377

376378
x509CRLLoadFile

botan-low/test/Botan/Low/CipherSpec.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{-# OPTIONS_GHC -Wno-deprecations #-}
2+
13
module Main where
24

35
import Test.Prelude

botan/src/Botan/Cipher.hs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{-# OPTIONS_GHC -Wno-overlapping-patterns #-}
2+
13
{-|
24
Module : Botan.Low.Cipher
35
Description : Symmetric cipher modes
@@ -272,7 +274,7 @@ newCipherKey :: (MonadRandomIO m) => Cipher -> m CipherKey
272274
newCipherKey = newKey . cipherKeySpec
273275

274276
newCipherKeyMaybe :: (MonadRandomIO m) => Int -> Cipher -> m (Maybe CipherKey)
275-
newCipherKeyMaybe sz bc = newKeyMaybe sz (cipherKeySpec bc)
277+
newCipherKeyMaybe sz bc = newKeyMaybe sz (cipherKeySpec bc)
276278

277279
type CipherNonce = ByteString
278280

@@ -347,7 +349,7 @@ cipherDefaultNonceSize (CBC bc _) = blockCipherBlockSize bc
347349
cipherDefaultNonceSize (CFB bc _) = blockCipherBlockSize bc
348350
cipherDefaultNonceSize (XTS bc) = blockCipherBlockSize bc
349351
-- NOTE: This is the value at current, and matches the default in botan,
350-
-- presumably because 12 is valid for all remaining cipher / AEAD nonces
352+
-- presumably because 12 is valid for all remaining cipher / AEAD nonces
351353
cipherDefaultNonceSize _ = 12
352354
-- NOTE: Extracted from inspecting:
353355
{-
@@ -467,7 +469,7 @@ cipherIdealUpdateGranularity cipher = unsafePerformIO $ do
467469
Low.cipherGetIdealUpdateGranularity ctx
468470
{-# NOINLINE cipherIdealUpdateGranularity #-}
469471
-- NOTE: This is machine-dependent, but should stay consistent per-machine
470-
-- so we do this instead of inlining the values
472+
-- so we do this instead of inlining the values
471473

472474
cipherOutputLength :: Cipher -> CipherDirection -> Int -> Int
473475
cipherOutputLength c dir n = unsafePerformIO $ do
@@ -550,7 +552,7 @@ data CipherDirection
550552
= CipherEncrypt
551553
| CipherDecrypt
552554
deriving (Eq, Ord, Show)
553-
555+
554556
cipherDirectionFlags :: CipherDirection -> Low.CipherInitFlags
555557
cipherDirectionFlags CipherEncrypt = Low.Encrypt
556558
cipherDirectionFlags CipherDecrypt = Low.Decrypt
@@ -612,7 +614,7 @@ getCipherEstimateOutputLength ctx input = do
612614
t <- getCipherTagSize ctx
613615
if mutableCipherDirection ctx == CipherEncrypt
614616
then return (o + u + t)
615-
else return (o + u - t) -- TODO: Maybe just 'o'...
617+
else return (o + u - t) -- TODO: Maybe just 'o'...
616618

617619
-- NOTE: Supposed to be an upper bound, may not always be valid? - needs checking
618620
{-# WARNING getCipherOutputLength "Needs to be confirmed accurate, use getCipherEstimateOutputLength" #-}

0 commit comments

Comments
 (0)