From e030dd833d57e2023f387a73b9d64fce4aa6145f Mon Sep 17 00:00:00 2001 From: FĂ©lix Sipma Date: Sun, 13 Dec 2015 23:08:56 +0100 Subject: Gpg: add hasPrivKey and hasPubKey (cherry picked from commit 7196b884e35ba907891c00d6e2840a36dce2214c) --- src/Propellor/Property/Gpg.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/Propellor/Property/Gpg.hs') diff --git a/src/Propellor/Property/Gpg.hs b/src/Propellor/Property/Gpg.hs index a16df11d..59448bca 100644 --- a/src/Propellor/Property/Gpg.hs +++ b/src/Propellor/Property/Gpg.hs @@ -41,3 +41,17 @@ dotDir :: User -> IO FilePath dotDir (User u) = do home <- homeDirectory <$> getUserEntryForName u return $ home ".gnupg" + +hasPrivKey :: GpgKeyId -> User -> IO Bool +hasPrivKey (GpgKeyId keyid) (User u) = do + value <- catchMaybeIO $ readProcess "su" ["-c", "gpg --list-secret-keys " ++ keyid, u] + return $ case value of + Just _ -> True + _ -> False + +hasPubKey :: GpgKeyId -> User -> IO Bool +hasPubKey (GpgKeyId keyid) (User u) = do + value <- catchMaybeIO $ readProcess "su" ["-c", "gpg --list-public-keys " ++ keyid, u] + return $ case value of + Just _ -> True + _ -> False -- cgit v1.2.3