diff options
author | Joey Hess <joey@kitenet.net> | 2011-05-15 12:25:58 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2011-05-15 12:25:58 -0400 |
commit | 3e15a8a791d15c166557fa18f240639891a8754f (patch) | |
tree | e4aab63486d489a0c4e78c0d31da6406f7f7a515 /Remote/Encryptable.hs | |
parent | cad0e1c8b7eb21f8dceca8dd9fa3bc1d1aa7eabd (diff) |
Maybe reduction pass 2
Diffstat (limited to 'Remote/Encryptable.hs')
-rw-r--r-- | Remote/Encryptable.hs | 31 |
1 files changed, 11 insertions, 20 deletions
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 |