add incremental hashing interface to Backend
As yet unused. Backend.External could perhaps implement it too, although that would involve sending chunks of data to it via a pipe or something, so likely to be slow.
This commit is contained in:
parent
fd51b0cd83
commit
ed684f651e
6 changed files with 204 additions and 65 deletions
|
@ -2,7 +2,7 @@
|
|||
-
|
||||
- Most things should not need this, using Types instead
|
||||
-
|
||||
- Copyright 2010-2020 Joey Hess <id@joeyh.name>
|
||||
- Copyright 2010-2021 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- Licensed under the GNU AGPL version 3 or higher.
|
||||
-}
|
||||
|
@ -11,16 +11,21 @@ module Types.Backend where
|
|||
|
||||
import Types.Key
|
||||
import Types.KeySource
|
||||
|
||||
import Utility.Metered
|
||||
import Utility.FileSystemEncoding
|
||||
|
||||
import Data.ByteString (ByteString)
|
||||
|
||||
data BackendA a = Backend
|
||||
{ backendVariety :: KeyVariety
|
||||
, genKey :: Maybe (KeySource -> MeterUpdate -> a Key)
|
||||
-- Verifies the content of a key using a hash. This does not need
|
||||
-- to be cryptographically secure.
|
||||
-- Verifies the content of a key, stored in a file, using a hash.
|
||||
-- This does not need to be cryptographically secure.
|
||||
, verifyKeyContent :: Maybe (Key -> RawFilePath -> a Bool)
|
||||
-- Incrementally verifies the content of a key, using the same
|
||||
-- hash as verifyKeyContent, but with the content provided
|
||||
-- incrementally a peice at a time, until finalized.
|
||||
, verifyKeyContentIncrementally :: Maybe (Key -> a IncrementalVerifier)
|
||||
-- Checks if a key can be upgraded to a better form.
|
||||
, canUpgradeKey :: Maybe (Key -> Bool)
|
||||
-- Checks if there is a fast way to migrate a key to a different
|
||||
|
@ -38,3 +43,11 @@ instance Show (BackendA a) where
|
|||
|
||||
instance Eq (BackendA a) where
|
||||
a == b = backendVariety a == backendVariety b
|
||||
|
||||
data IncrementalVerifier = IncrementalVerifier
|
||||
{ updateIncremental :: ByteString -> IO ()
|
||||
-- ^ Called repeatedly on each peice of the content.
|
||||
, finalizeIncremental :: IO Bool
|
||||
-- ^ Called once the full content has been sent, returns true
|
||||
-- if the hash verified.
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue