summaryrefslogtreecommitdiffhomepage
path: root/CmdLine.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-08-17 17:29:11 -0400
committerJoey Hess <joeyh@joeyh.name>2016-08-17 17:29:46 -0400
commitc394b41a2ffb7e987864fa64fd583017c717703b (patch)
tree9aaaf9467badba9baeed3b634a1155be1ee833a0 /CmdLine.hs
parentb66b497244ab2a094bec5c3a678f448f23c8404d (diff)
downloadkeysafe-c394b41a2ffb7e987864fa64fd583017c717703b.tar.gz
allow configuring N and M
User has to remember they did this and use the same configuration on restore.
Diffstat (limited to 'CmdLine.hs')
-rw-r--r--CmdLine.hs22
1 files changed, 21 insertions, 1 deletions
diff --git a/CmdLine.hs b/CmdLine.hs
index 910aa81..1c0abd2 100644
--- a/CmdLine.hs
+++ b/CmdLine.hs
@@ -3,9 +3,10 @@
- Licensed under the GNU AGPL version 3 or higher.
-}
-module CmdLine (CmdLine(..), Mode(..), get, parse, selectMode) where
+module CmdLine where
import Types
+import Tunables
import qualified Gpg
import Options.Applicative
import qualified Data.ByteString.UTF8 as BU8
@@ -20,6 +21,7 @@ data CmdLine = CmdLine
, storage :: Storage
, gui :: Bool
, testMode :: Bool
+ , customShardParams :: Maybe ShardParams
}
data Mode = Backup | Restore | Benchmark
@@ -32,6 +34,7 @@ parse = CmdLine
<*> localstorageflag
<*> guiswitch
<*> testmodeswitch
+ <*> optional (ShardParams <$> totalobjects <*> neededobjects)
where
backup = flag' Backup
( long "backup"
@@ -47,10 +50,12 @@ parse = CmdLine
)
gpgswitch = GpgKey . KeyId . BU8.fromString <$> strOption
( long "gpgkeyid"
+ <> metavar "KEYID"
<> help "Specify keyid of gpg key to back up or restore. (When this option is used to back up a key, it must also be used at restore time.)"
)
fileswitch = KeyFile <$> strOption
( long "keyfile"
+ <> metavar "FILE"
<> help "Specify secret key file to back up or restore. (The same filename must be used to restore a key as was used to back it up.)"
)
localstorageflag = flag networkStorage localStorage
@@ -65,6 +70,16 @@ parse = CmdLine
( long "gui"
<> help "Use GUI interface for interaction. Default is to use readline interface when run in a terminal, and GUI otherwise."
)
+ totalobjects = option auto
+ ( long "totalshards"
+ <> metavar "M"
+ <> help ("Configure the number of shards to split encrypted secret key into. Default: " ++ show (totalObjects (shardParams defaultTunables)) ++ " (When this option is used to back up a key, it must also be provided at restore time.)")
+ )
+ neededobjects = option auto
+ ( long "neededshards"
+ <> metavar "N"
+ <> help ("Configure the number of shards needed to restore. Default: " ++ show (neededObjects (shardParams defaultTunables)) ++ " (When this option is used to back up a key, it must also be provided at restore time.)")
+ )
get :: IO CmdLine
get = execParser opts
@@ -85,3 +100,8 @@ selectMode cmdline = case mode cmdline of
where
present True = Backup
present False = Restore
+
+customizeShardParams :: CmdLine -> Tunables -> Tunables
+customizeShardParams cmdline t = case customShardParams cmdline of
+ Nothing -> t
+ Just ps -> t { shardParams = ps }