refactor(saltine): fix hlint and ghc warnings

This commit is contained in:
Steffen Jost 2024-12-19 09:13:00 +01:00
parent 032a344ed1
commit 2e3c51562b

View File

@ -1,5 +1,4 @@
{-# LANGUAGE BangPatterns #-} {-# OPTIONS_GHC -Wwarn -fno-warn-orphans #-}
{-# OPTIONS_GHC -Wwarn #-}
-- SPDX-FileCopyrightText: 2024 Sarah Vaupel <sarah.vaupel@uniworx.de> -- SPDX-FileCopyrightText: 2024 Sarah Vaupel <sarah.vaupel@uniworx.de>
-- --
@ -50,7 +49,7 @@ buildUnsafeByteString' n k = do
-- | Convenience function for accessing constant C strings -- | Convenience function for accessing constant C strings
constByteStrings :: [ByteString] -> ([CStringLen] -> IO b) -> IO b constByteStrings :: [ByteString] -> ([CStringLen] -> IO b) -> IO b
constByteStrings = constByteStrings =
foldr (\v kk -> \k -> (unsafeUseAsCStringLen v) (\a -> kk (\as -> k (a:as)))) ($ []) foldr (\v kk k -> unsafeUseAsCStringLen v (\a -> kk (\as -> k (a:as)))) ($ [])
-- | bin2hex conversion for showing various binary types -- | bin2hex conversion for showing various binary types
foreign import ccall unsafe "sodium_bin2hex" foreign import ccall unsafe "sodium_bin2hex"
@ -64,8 +63,9 @@ foreign import ccall unsafe "sodium_bin2hex"
bin2hex :: ByteString -> String bin2hex :: ByteString -> String
bin2hex bs = let tlen = S.length bs * 2 + 1 in bin2hex bs = let tlen = S.length bs * 2 + 1 in
S8.unpack . S8.init . snd . buildUnsafeByteString tlen $ \t -> S8.unpack . S8.init . snd . buildUnsafeByteString tlen $ \t ->
constByteStrings [bs] $ \[(pbs, _)] -> let aux [(pbs, _)] = c_sodium_bin2hex t (fromIntegral tlen) pbs (fromIntegral $ S.length bs)
c_sodium_bin2hex t (fromIntegral tlen) pbs (fromIntegral $ S.length bs) aux _ = error "Crypto.Saltine.Instances.bin2hex reached an impossible computation path"
in constByteStrings [bs] aux
instance Show Key where instance Show Key where
show k = "SecretBox.Key {hashesTo = \"" <> (bin2hex . shorthash nullShKey $ encode k) <> "}\"" show k = "SecretBox.Key {hashesTo = \"" <> (bin2hex . shorthash nullShKey $ encode k) <> "}\""