diff options
| author | Félix Sipma <felix.sipma@no-log.org> | 2015-12-13 23:08:56 +0100 |
|---|---|---|
| committer | Joey Hess <joeyh@joeyh.name> | 2015-12-16 12:04:45 -0400 |
| commit | e030dd833d57e2023f387a73b9d64fce4aa6145f (patch) | |
| tree | 9a5d512bd9f29445c404c831c198a0cc618fac98 /src/Propellor/Property/Gpg.hs | |
| parent | 47a2b72bed3770d3dfb26c4142479c436a11ce55 (diff) | |
Gpg: add hasPrivKey and hasPubKey
(cherry picked from commit 7196b884e35ba907891c00d6e2840a36dce2214c)
Diffstat (limited to 'src/Propellor/Property/Gpg.hs')
| -rw-r--r-- | src/Propellor/Property/Gpg.hs | 14 |
1 files changed, 14 insertions, 0 deletions
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 |
