Maybe reduction pass 2
This commit is contained in:
parent
cad0e1c8b7
commit
3e15a8a791
4 changed files with 33 additions and 51 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue