convert tailVerify to not finalize the verification

Added failIncremental so it can force failure to verify.

Sponsored-by: Dartmouth College's DANDI project
This commit is contained in:
Joey Hess 2021-08-13 13:39:02 -04:00
parent 9d533b347f
commit e07625df8a
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 55 additions and 38 deletions

View file

@ -280,13 +280,19 @@ md5Hasher = mkHasher md5 md5_context
mkIncrementalVerifier :: HashAlgorithm h => Context h -> Key -> IO IncrementalVerifier
mkIncrementalVerifier ctx key = do
v <- newIORef ctx
v <- newIORef (Just ctx)
return $ IncrementalVerifier
{ updateIncremental = modifyIORef' v . flip hashUpdate
, finalizeIncremental = do
ctx' <- readIORef v
let digest = hashFinalize ctx'
return $ sameCheckSum key (show digest)
{ updateIncremental = \b ->
modifyIORef' v $ \case
Just ctx' -> Just (hashUpdate ctx' b)
Nothing -> Nothing
, finalizeIncremental =
readIORef v >>= \case
Just ctx' -> do
let digest = hashFinalize ctx'
return $ sameCheckSum key (show digest)
Nothing -> return False
, failIncremental = writeIORef v Nothing
}
{- A varient of the SHA256E backend, for testing that needs special keys