summaryrefslogtreecommitdiffhomepage
path: root/Gpg.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-11-06 11:50:16 -0400
committerJoey Hess <joeyh@joeyh.name>2016-11-06 11:50:16 -0400
commit2a555c479e078519b2e7d7b7258e6ba37ec3e22f (patch)
treec51663051d601cc59ea9d49ebcd5a26cdde91498 /Gpg.hs
parent9e0ca8324a28f38acc0deefa23fb056830fecf0a (diff)
downloadkeysafe-2a555c479e078519b2e7d7b7258e6ba37ec3e22f.tar.gz
Defer requesting secret key from gpg until just before backup
So the user knows why gpg is asking for this secret key to be backed up. Before, this was done as soon as keysafe started, which didn't give the user any indication what was going on, unless they had multiple keys and so picked the key to back up from a list. This commit was sponsored by Thomas Hochstein on Patreon.
Diffstat (limited to 'Gpg.hs')
-rw-r--r--Gpg.hs10
1 files changed, 4 insertions, 6 deletions
diff --git a/Gpg.hs b/Gpg.hs
index 91b53cd..192ab1c 100644
--- a/Gpg.hs
+++ b/Gpg.hs
@@ -21,19 +21,17 @@ import qualified Data.Text as T
--
-- If there is only one gpg secret key,
-- the choice is obvious. Otherwise prompt the user with a list.
-getKeyToBackup :: UI -> IO (SecretKeySource, SecretKey)
+getKeyToBackup :: UI -> IO SecretKeySource
getKeyToBackup ui = go =<< listSecretKeys
where
go [] = do
showError ui "You have no gpg secret keys to back up."
error "Aborting on no gpg secret keys."
- go [(_, kid)] = mkret kid
- go l = maybe (error "Canceled") mkret
+ go [(_, kid)] = selected kid
+ go l = maybe (error "Canceled") selected
=<< promptKeyId ui "Pick gpg secret key"
"Pick gpg secret key to back up:" l
- mkret kid = do
- sk <- getSecretKey kid
- return (GpgKey kid, sk)
+ selected = return . GpgKey
listSecretKeys :: IO [(Name, KeyId)]
listSecretKeys = map mk . parse . lines <$> readProcess "gpg"