From feb9fdaa30d0d647c29feb992299f3ffb6325fff Mon Sep 17 00:00:00 2001 From: Sergey Ivanov Date: Thu, 16 Feb 2023 08:09:59 +0400 Subject: [PATCH] Drop keyring, pubkey opts from store command --- hbs2/Main.hs | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/hbs2/Main.hs b/hbs2/Main.hs index 5a712b0d..bcb08b5c 100644 --- a/hbs2/Main.hs +++ b/hbs2/Main.hs @@ -68,22 +68,19 @@ newtype OptKeyringFile = OptKeyringFile { unOptKeyringFile :: FilePath } deriving newtype (Eq,Ord,IsString) deriving stock (Data) +newtype OptGroupkeyFile = OptGroupkeyFile { unOptGroupkeyFile :: FilePath } + deriving newtype (Eq,Ord,IsString) + deriving stock (Data) + newtype OptInit = OptInit { fromOptInit :: Bool } deriving newtype (Eq,Ord,Pretty) deriving stock (Data,Generic) -data OptEncryption e = OptEncryption - { encoptGroupkeyFile :: FilePath - , encoptKeyringFile :: Maybe FilePath - , encoptFromPubKey :: Maybe Text - } - deriving stock (Data) - -data StoreOpts e = +data StoreOpts = StoreOpts { storeInit :: Maybe OptInit , storeInputFile :: Maybe OptInputFile - , storeEncryption :: Maybe (OptEncryption e) + , storeGroupkeyFile :: Maybe OptGroupkeyFile } deriving stock (Data) @@ -212,13 +209,13 @@ runStore opts ss = do handle <- maybe (pure stdin) (flip openFile ReadMode . unOptFile) fname - case (uniLastMay @(OptEncryption MerkleEncryptionType) opts) of + case (uniLastMay @OptGroupkeyFile opts) of Nothing -> do root <- putAsMerkle ss handle print $ "merkle-root: " <+> pretty root - Just encOpts -> do + Just gkfile -> do gk :: GroupKey MerkleEncryptionType 'NaClAsymm - <- (parseGroupKey . AsGroupKeyFile <$> BS.readFile (encoptGroupkeyFile encOpts)) + <- (parseGroupKey . AsGroupKeyFile <$> BS.readFile (unOptGroupkeyFile gkfile)) `orDie` "bad groupkey file" accKeyh <- maybe (die "can not store access key") pure @@ -350,12 +347,7 @@ main = join . customExecParser (prefs showHelpOnError) $ file <- optional $ strArgument ( metavar "FILE" ) init <- optional $ flag' True ( long "init" <> help "just init storage") <&> OptInit groupkeyFile <- optional $ strOption ( long "groupkey" <> help "path to groupkey file" ) - encoptKeyringFile <- optional $ strOption ( long "keyring" <> help "path to keyring file" ) - encoptFromPubKey <- optional $ strOption ( metavar "PUB-KEY-BASE58" ) - pure do - let encOps :: Maybe (OptEncryption MerkleEncryptionType) - encOps = groupkeyFile <&> \encoptGroupkeyFile -> OptEncryption{..} - withStore o (runStore ( StoreOpts init file encOps )) + pure $ withStore o (runStore ( StoreOpts init file (OptGroupkeyFile <$> groupkeyFile) )) pCat = do o <- common