2013-09-26 20:09:45 +00:00
|
|
|
{- git-annex assistant gpg stuff
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2013 Joey Hess <id@joeyh.name>
|
2013-09-26 20:09:45 +00:00
|
|
|
-
|
2016-11-22 03:46:59 +00:00
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
2013-09-26 20:09:45 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Assistant.Gpg where
|
|
|
|
|
|
|
|
import Utility.Gpg
|
|
|
|
import Utility.UserInfo
|
|
|
|
import Types.Remote (RemoteConfigKey)
|
|
|
|
|
|
|
|
import qualified Data.Map as M
|
2016-06-13 19:53:02 +00:00
|
|
|
import Control.Applicative
|
|
|
|
import Prelude
|
2013-09-26 20:09:45 +00:00
|
|
|
|
|
|
|
{- Generates a gpg user id that is not used by any existing secret key -}
|
2015-09-09 22:06:49 +00:00
|
|
|
newUserId :: GpgCmd -> IO UserId
|
|
|
|
newUserId cmd = do
|
|
|
|
oldkeys <- secretKeys cmd
|
2016-06-08 19:04:15 +00:00
|
|
|
username <- either (const "unknown") id <$> myUserName
|
2014-10-09 18:53:13 +00:00
|
|
|
let basekeyname = username ++ "'s git-annex encryption key"
|
2013-09-26 20:09:45 +00:00
|
|
|
return $ Prelude.head $ filter (\n -> M.null $ M.filter (== n) oldkeys)
|
|
|
|
( basekeyname
|
|
|
|
: map (\n -> basekeyname ++ show n) ([2..] :: [Int])
|
|
|
|
)
|
|
|
|
|
|
|
|
data EnableEncryption = HybridEncryption | SharedEncryption | NoEncryption
|
|
|
|
deriving (Eq)
|
|
|
|
|
|
|
|
{- Generates Remote configuration for encryption. -}
|
|
|
|
configureEncryption :: EnableEncryption -> (RemoteConfigKey, String)
|
|
|
|
configureEncryption SharedEncryption = ("encryption", "shared")
|
|
|
|
configureEncryption NoEncryption = ("encryption", "none")
|
|
|
|
configureEncryption HybridEncryption = ("encryption", "hybrid")
|