started Annex.Sim

Have most of the sim command handler, but to keep it pure while implementing
the rest will need some refactoring.

It seems likely that running the simulation itself will not be able to be
entirely pure. Preferred content evaluation runs in Annex after all.

Note that the somewhat awkward randomWords is because the i386ancient
build depends on a version of random too old to support generating a
random ByteString on its own.
This commit is contained in:
Joey Hess 2024-09-04 15:10:39 -04:00
parent 84c781d924
commit b932acf4ad
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
6 changed files with 281 additions and 6 deletions

View file

@ -9,13 +9,14 @@
module Backend.Hash (
backends,
testKeyBackend,
keyHash,
descChecksum,
Hash(..),
cryptographicallySecure,
hashFile,
checkKeyChecksum
checkKeyChecksum,
testKeyBackend,
genTestKey,
) where
import Annex.Common
@ -296,13 +297,25 @@ descChecksum = "checksum"
-}
testKeyBackend :: Backend
testKeyBackend =
let b = genBackendE (SHA2Hash (HashSize 256))
let b = genBackendE testKeyHash
gk = case genKey b of
Nothing -> Nothing
Just f -> Just (\ks p -> addTestE <$> f ks p)
in b { genKey = gk }
addTestE :: Key -> Key
addTestE k = alterKey k $ \d -> d
{ keyName = keyName d <> longext
}
where
addTestE k = alterKey k $ \d -> d
{ keyName = keyName d <> longext
}
longext = ".this-is-a-test-key"
testKeyHash :: Hash
testKeyHash = SHA2Hash (HashSize 256)
genTestKey :: L.ByteString -> Key
genTestKey content = addTestE $ mkKey $ \kd -> kd
{ keyName = S.toShort $ encodeBS $
(fst $ hasher testKeyHash) content
, keyVariety = backendVariety testKeyBackend
}