summaryrefslogtreecommitdiff
path: root/src/Propellor/Gpg.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Propellor/Gpg.hs')
-rw-r--r--src/Propellor/Gpg.hs17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/Propellor/Gpg.hs b/src/Propellor/Gpg.hs
index 55d89d29..4e6ceb79 100644
--- a/src/Propellor/Gpg.hs
+++ b/src/Propellor/Gpg.hs
@@ -32,14 +32,21 @@ getGpgBin = do
-- Lists the keys in propellor's keyring.
listPubKeys :: IO [KeyId]
listPubKeys = do
- gpgbin <- getGpgBin
keyring <- privDataKeyring
- parse . lines <$> readProcess gpgbin (listopts keyring)
+ map fst <$> listKeys ("--list-public-keys" : useKeyringOpts keyring)
+
+listSecretKeys :: IO [(KeyId, String)]
+listSecretKeys = listKeys ["--list-secret-keys"]
+
+listKeys :: [String] -> IO [(KeyId, String)]
+listKeys ps = do
+ gpgbin <- getGpgBin
+ parse . lines <$> readProcess gpgbin listopts
where
- listopts keyring = useKeyringOpts keyring ++
- ["--with-colons", "--list-public-keys"]
+ listopts = ps ++ ["--with-colons"]
parse = mapMaybe (keyIdField . split ":")
- keyIdField ("pub":_:_:_:f:_) = Just f
+ keyIdField (t:_:_:_:f:_:_:_:_:n:_)
+ | t == "pub" || t == "sec" = Just (f, n)
keyIdField _ = Nothing
useKeyringOpts :: FilePath -> [String]