refactoring

This commit is contained in:
Joey Hess 2025-02-27 14:54:03 -04:00
parent 9c2c3002a6
commit 1704b5e327
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 25 additions and 14 deletions

View file

@ -10,13 +10,14 @@
module Backend (
builtinList,
defaultBackend,
defaultHashBackend,
hashBackend,
genKey,
getBackend,
chooseBackend,
lookupBackendVariety,
lookupBuiltinBackendVariety,
maybeLookupBackendVariety,
unknownBackendVarietyMessage,
isStableKey,
isCryptographicallySecureKey,
isCryptographicallySecure,
@ -54,6 +55,15 @@ defaultBackend = maybe cache return =<< Annex.getState Annex.backend
valid name = not (null name)
lookupname = lookupBackendVariety . parseKeyVariety . encodeBS
{- A hashing backend. Takes git config into account, but
- guarantees the backend is cryptographically secure. -}
hashBackend :: Annex Backend
hashBackend = do
db <- defaultBackend
return $ if isCryptographicallySecure db
then db
else defaultHashBackend
{- Generates a key for a file. -}
genKey :: KeySource -> MeterUpdate -> Backend -> Annex (Key, Backend)
genKey source meterupdate b = case B.genKey b of