From 4c96f460a7ad615f344d1b2e88d037d7a0259776 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 4 Sep 2013 22:18:33 -0400 Subject: replace an over-explained Bool with a data type This also highlights several places where a Read/Show or similar for the new data type could avoid redundant strings. --- Test.hs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'Test.hs') diff --git a/Test.hs b/Test.hs index d9d1f066b..7ac87af5b 100644 --- a/Test.hs +++ b/Test.hs @@ -920,26 +920,26 @@ test_crypto env = "git-annex crypto" ~: TestList $ flip map ["shared","hybrid"," - that all keys are encrypted properly on the given directory remote. -} testEncryptedRemote scheme ks c keys = case Remote.Helper.Encryptable.extractCipher c of Just cip@Crypto.SharedCipher{} | scheme == "shared" && isNothing ks -> - checkKeys cip True - Just cip@(Crypto.EncryptedCipher encipher sym ks') - | checkScheme sym && keysMatch ks' -> - checkKeys cip sym <&&> checkCipher encipher ks' + checkKeys cip Nothing + Just cip@(Crypto.EncryptedCipher encipher v ks') + | checkScheme v && keysMatch ks' -> + checkKeys cip (Just v) <&&> checkCipher encipher ks' _ -> return False where keysMatch (Utility.Gpg.KeyIds ks') = maybe False (\(Utility.Gpg.KeyIds ks2) -> sort (nub ks2) == sort (nub ks')) ks checkCipher encipher = Utility.Gpg.checkEncryptionStream encipher . Just - checkScheme True = scheme == "hybrid" - checkScheme False = scheme == "pubkey" - checkKeys cip sym = do + checkScheme Types.Crypto.HybridCipher = scheme == "hybrid" + checkScheme Types.Crypto.PubKeyCipher = scheme == "pubkey" + checkKeys cip mvariant = do cipher <- Crypto.decryptCipher cip files <- filterM doesFileExist $ map ("dir" ) $ concatMap (key2files cipher) keys - return (not $ null files) <&&> allM (checkFile sym) files - checkFile sym filename = + return (not $ null files) <&&> allM (checkFile mvariant) files + checkFile mvariant filename = Utility.Gpg.checkEncryptionFile filename $ - if sym then Nothing else ks + if mvariant == Just Types.Crypto.PubKeyCipher then ks else Nothing key2files cipher = Locations.keyPaths . Crypto.encryptKey Types.Crypto.HmacSha1 cipher #else -- cgit v1.2.3