From 3e15a8a791d15c166557fa18f240639891a8754f Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 15 May 2011 12:25:58 -0400 Subject: Maybe reduction pass 2 --- Remote/Encryptable.hs | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) (limited to 'Remote/Encryptable.hs') diff --git a/Remote/Encryptable.hs b/Remote/Encryptable.hs index f9b388c8a..68ecfd01e 100644 --- a/Remote/Encryptable.hs +++ b/Remote/Encryptable.hs @@ -54,21 +54,14 @@ encryptableRemote c storeKeyEncrypted retrieveKeyFileEncrypted r = cost = cost r + encryptedRemoteCostAdj } where - store k = do - v <- cipherKey c k - case v of - Nothing -> (storeKey r) k - Just x -> storeKeyEncrypted x k - retrieve k f = do - v <- cipherKey c k - case v of - Nothing -> (retrieveKeyFile r) k f - Just x -> retrieveKeyFileEncrypted x f - withkey a k = do - v <- cipherKey c k - case v of - Nothing -> a k - Just (_, k') -> a k' + store k = cip k >>= maybe + (storeKey r k) + (\x -> storeKeyEncrypted x k) + retrieve k f = cip k >>= maybe + (retrieveKeyFile r k f) + (\x -> retrieveKeyFileEncrypted x f) + withkey a k = cip k >>= maybe (a k) (a . snd) + cip = cipherKey c {- Gets encryption Cipher. The decrypted Cipher is cached in the Annex - state. -} @@ -87,10 +80,8 @@ remoteCipher c = maybe expensive cached =<< Annex.getState Annex.cipher {- Gets encryption Cipher, and encrypted version of Key. -} cipherKey :: Maybe RemoteConfig -> Key -> Annex (Maybe (Cipher, Key)) cipherKey Nothing _ = return Nothing -cipherKey (Just c) k = do - cipher <- remoteCipher c - case cipher of - Just ciphertext -> do +cipherKey (Just c) k = remoteCipher c >>= maybe (return Nothing) encrypt + where + encrypt ciphertext = do k' <- liftIO $ encryptKey ciphertext k return $ Just (ciphertext, k') - Nothing -> return Nothing -- cgit v1.2.3