summaryrefslogtreecommitdiffhomepage
path: root/Gpg.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-08-28 13:00:02 -0400
committerJoey Hess <joeyh@joeyh.name>2016-08-28 13:00:02 -0400
commitb35b44e0d47abca77107ad689b620c0721412cb6 (patch)
treece264e531b475638fbd2dd6a781ca1214a9dae23 /Gpg.hs
parentb0aa14ea3b12ab0559793bfb46df4625d7792bd4 (diff)
downloadkeysafe-b35b44e0d47abca77107ad689b620c0721412cb6.tar.gz
Fix gpg secret key list parser to support gpg 2.
Should also support gpg 1.
Diffstat (limited to 'Gpg.hs')
-rw-r--r--Gpg.hs20
1 files changed, 13 insertions, 7 deletions
diff --git a/Gpg.hs b/Gpg.hs
index de45c45..9a743f0 100644
--- a/Gpg.hs
+++ b/Gpg.hs
@@ -11,7 +11,6 @@ import Types
import UI
import System.Process
import Data.List.Split
-import Data.Maybe
import System.IO
import System.Exit
import qualified Data.ByteString as B
@@ -37,13 +36,20 @@ anyKey :: SecretKeySource
anyKey = GpgKey (KeyId "")
listSecretKeys :: IO [(Name, KeyId)]
-listSecretKeys = mapMaybe parse . lines <$> readProcess "gpg"
- ["--batch", "--with-colons", "--list-secret-keys"] ""
+listSecretKeys = map mk . parse . lines <$> readProcess "gpg"
+ ["--batch", "--with-colons", "--list-secret-keys", "--fixed-list-mode"] ""
where
- parse l = case splitOn ":" l of
- ("sec":_:_:_:kid:_:_:_:_:n:_) -> Just
- (Name (BU8.fromString n), KeyId (BU8.fromString kid))
- _ -> Nothing
+ parse = extract [] Nothing . map (splitOn ":")
+ extract c (Just keyid) (("uid":_:_:_:_:_:_:_:_:userid:_):rest) =
+ extract ((userid, keyid):c) Nothing rest
+ extract c (Just keyid) rest =
+ extract (("", keyid):c) Nothing rest
+ extract c _ [] = c
+ extract c _ (("sec":_:_:_:keyid:_):rest) =
+ extract c (Just keyid) rest
+ extract c k (_:rest) =
+ extract c k rest
+ mk (userid, keyid) = (Name (BU8.fromString userid), KeyId (BU8.fromString keyid))
getSecretKey :: KeyId -> IO SecretKey
getSecretKey (KeyId kid) = do