module Crypto.PHKDF.Primitives.Assert where

import Data.Bits
import Data.Word
import Crypto.PHKDF.Primitives.Subtle

phkdfCtx_assertBufferPosition' :: Word64 -> PhkdfCtx -> PhkdfCtx
phkdfCtx_assertBufferPosition' :: Word64 -> PhkdfCtx -> PhkdfCtx
phkdfCtx_assertBufferPosition' Word64
n PhkdfCtx
ctx
  | Word64
len Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.&. Word64
63 Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word64
n Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.&. Word64
63
  = [Char] -> PhkdfCtx
forall a. HasCallStack => [Char] -> a
error ([Char]
"phkdf buffer position mismatch: " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Word64 -> [Char]
forall a. Show a => a -> [Char]
show Word64
len [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
" /= " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Word64 -> [Char]
forall a. Show a => a -> [Char]
show Word64
n [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
" (mod 64)")
  | Bool
otherwise = PhkdfCtx
ctx
  where len :: Word64
len = PhkdfCtx -> Word64
phkdfCtx_byteLen PhkdfCtx
ctx

phkdfSlowCtx_assertBufferPosition' :: Word64 -> PhkdfSlowCtx -> PhkdfSlowCtx
phkdfSlowCtx_assertBufferPosition' :: Word64 -> PhkdfSlowCtx -> PhkdfSlowCtx
phkdfSlowCtx_assertBufferPosition' Word64
n PhkdfSlowCtx
ctx
  | Word64
len Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.&. Word64
63 Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word64
n Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.&. Word64
63
  = [Char] -> PhkdfSlowCtx
forall a. HasCallStack => [Char] -> a
error ([Char]
"phkdf buffer position mismatch: " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Word64 -> [Char]
forall a. Show a => a -> [Char]
show Word64
len [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
" /= " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Word64 -> [Char]
forall a. Show a => a -> [Char]
show Word64
n [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
" (mod 64)")
  | Bool
otherwise = PhkdfSlowCtx
ctx
  where len :: Word64
len = PhkdfCtx -> Word64
phkdfCtx_byteLen (PhkdfSlowCtx -> PhkdfCtx
phkdfSlowCtx_phkdfCtx PhkdfSlowCtx
ctx)

-- TODO: set up a cabal flag and CPP to select between assertions enabled/not

{--}

phkdfCtx_assertBufferPosition :: Word64 -> PhkdfCtx -> PhkdfCtx
phkdfCtx_assertBufferPosition :: Word64 -> PhkdfCtx -> PhkdfCtx
phkdfCtx_assertBufferPosition = Word64 -> PhkdfCtx -> PhkdfCtx
phkdfCtx_assertBufferPosition'


phkdfSlowCtx_assertBufferPosition :: Word64 -> PhkdfSlowCtx -> PhkdfSlowCtx
phkdfSlowCtx_assertBufferPosition :: Word64 -> PhkdfSlowCtx -> PhkdfSlowCtx
phkdfSlowCtx_assertBufferPosition = Word64 -> PhkdfSlowCtx -> PhkdfSlowCtx
phkdfSlowCtx_assertBufferPosition'

--}

{--

phkdfCtx_assertBufferPosition :: Word64 -> PhkdfCtx -> PhkdfCtx
phkdfCtx_assertBufferPosition _ = id

phkdfSlowCtx_assertBufferPosition :: Word64 -> PhkdfSlowCtx -> PhkdfSlowCtx
phkdfSlowCtx_assertBufferPosition _ = id

--}