From c394b41a2ffb7e987864fa64fd583017c717703b Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 17 Aug 2016 17:29:11 -0400 Subject: allow configuring N and M User has to remember they did this and use the same configuration on restore. --- CmdLine.hs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'CmdLine.hs') 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 } -- cgit v1.2.3