saltine-0.2.1.0: Cryptography that's easy to digest (NaCl/libsodium bindings).
Safe HaskellSafe-Inferred
LanguageHaskell2010

Crypto.Saltine.Internal.Util

Synopsis

Documentation

compare :: ByteString -> ByteString -> Bool Source #

Constant-time comparison

randomByteString :: Int -> IO ByteString Source #

Build a sized random ByteString using Sodium's bindings to devurandom.

safeSubtract :: (Ord a, Num a) => a -> a -> Maybe a Source #

Returns Nothing if the subtraction would result in an underflow or a negative number.

cycleSucc :: (Bounded a, Enum a, Eq a) => a -> (Bool, a) Source #

snd . cycleSucc computes the succ of a Bounded, Eq Enum with wraparound. The fst . cycleSuc is whether the wraparound occurred (i.e. fst . cycleSucc == (== maxBound)).

nudgeBS :: ByteString -> ByteString Source #

Treats a ByteString as a little endian bitstring and increments it.

orbit :: Eq a => (a -> a) -> a -> [a] Source #

Computes the orbit of a endomorphism... in a very brute force manner. Exists just for the below property.

length . orbit nudgeBS . S.pack . replicate 0 == (256^)

unpad :: Int -> ByteString -> ByteString Source #

Remove a 0-padding from a ByteString

handleErrno :: CInt -> a -> Either String a Source #

Converts a C-convention errno to an Either

withCStrings :: [String] -> ([CString] -> IO a) -> IO a Source #

withCStringLens :: [String] -> ([CStringLen] -> IO a) -> IO a Source #

constByteStrings :: [ByteString] -> ([CStringLen] -> IO b) -> IO b Source #

Convenience function for accessing constant C strings

buildUnsafeByteString' :: Int -> (Ptr CChar -> IO b) -> IO (b, ByteString) Source #

Slightly safer cousin to buildUnsafeByteString that remains in the IO monad.

buildUnsafeVariableByteString' :: Int -> (Ptr CChar -> IO b) -> IO (b, ByteString) Source #

Sometimes we have to deal with variable-length strings

buildUnsafeByteString :: Int -> (Ptr CChar -> IO b) -> (b, ByteString) Source #

Extremely unsafe function, use with utmost care! Builds a new ByteString using a ccall which is given access to the raw underlying pointer. Overwrites are UNCHECKED and unsafePerformIO is used so it's difficult to predict the timing of the ByteString creation.

hush :: Either s a -> Maybe a Source #

To prevent a dependency on package errors

c_sodium_memcmp :: Ptr CChar -> Ptr CChar -> CInt -> IO CInt Source #

Constant time memory comparison

buildUnsafeScrubbedByteString' :: Int -> (Ptr CChar -> IO b) -> IO (b, ByteString) Source #

Not sure yet what to use this for

buildUnsafeScrubbedByteString :: Int -> (Ptr CChar -> IO b) -> (b, ByteString) Source #

Not sure yet what to use this for

c_sodium_bin2hex :: Ptr CChar -> CInt -> Ptr CChar -> CInt -> IO (Ptr CChar) Source #

bin2hex conversion for showing various binary types

uncurry3 :: (a -> b -> c -> d) -> (a, b, c) -> d Source #

uncurry5 :: (a -> b -> c -> d -> e -> f) -> (a, b, c, d, e) -> f Source #

withCString :: String -> (CString -> IO a) -> IO a #

Marshal a Haskell string into a NUL terminated C string using temporary storage.

  • the Haskell string may not contain any NUL characters
  • the memory is freed when the subcomputation terminates (either normally or via an exception), so the pointer to the temporary storage must not be used after this.

allocaBytes :: Int -> (Ptr a -> IO b) -> IO b #

allocaBytes n f executes the computation f, passing as argument a pointer to a temporarily allocated block of memory of n bytes. The block of memory is sufficiently aligned for any of the basic foreign types that fits into a memory block of the allocated size.

The memory is freed when f terminates (either normally or via an exception), so the pointer passed to f must not be used after this.