aboutsummaryrefslogtreecommitdiff
path: root/Assistant/Gpg.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-11-21 23:46:59 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-11-21 23:46:59 -0400
commit598d063b2f009637c0c14bfc8025a597832a1652 (patch)
treebb5389bc86c4122f980e3900aefbafb6f284f8ff /Assistant/Gpg.hs
parentcbfedce7e9b1b6f7bf1f43122cc8d21f8f9bfba1 (diff)
Relicense 5 source files that are not part of the webapp from AGPL to GPL.
Building w/o the webapp is not supposed to pull in any AGPLed files. I appear to have written all the code in these files; the only commit by anyone else is 0d555aa363482ed041db2d9c63da271ba7f4ced8 and is a spelling fix that is not copyrightable.
Diffstat (limited to 'Assistant/Gpg.hs')
-rw-r--r--Assistant/Gpg.hs36
1 files changed, 36 insertions, 0 deletions
diff --git a/Assistant/Gpg.hs b/Assistant/Gpg.hs
new file mode 100644
index 000000000..34d00a384
--- /dev/null
+++ b/Assistant/Gpg.hs
@@ -0,0 +1,36 @@
+{- git-annex assistant gpg stuff
+ -
+ - Copyright 2013 Joey Hess <id@joeyh.name>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module Assistant.Gpg where
+
+import Utility.Gpg
+import Utility.UserInfo
+import Types.Remote (RemoteConfigKey)
+
+import qualified Data.Map as M
+import Control.Applicative
+import Prelude
+
+{- Generates a gpg user id that is not used by any existing secret key -}
+newUserId :: GpgCmd -> IO UserId
+newUserId cmd = do
+ oldkeys <- secretKeys cmd
+ username <- either (const "unknown") id <$> myUserName
+ let basekeyname = username ++ "'s git-annex encryption key"
+ 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")