summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2019-10-08 21:19:51 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2019-10-09 20:57:52 +0200
commit681c68ef5843c13df1a8e5da3540b2b00ba2eb03 (patch)
treef0aaeec4af0fa8b4d3f8ad08568356501ea4a8dc /src
parentb222cd40d4a0bfe081dafee91db1aa2154f47649 (diff)
Commands to show object contents and signatures
Diffstat (limited to 'src')
-rw-r--r--src/Main.hs29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/Main.hs b/src/Main.hs
index 6b06811..4a6d3cd 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -6,6 +6,8 @@ import Control.Monad.Reader
import Control.Monad.State
import Control.Monad.Trans.Maybe
+import qualified Data.ByteString.Char8 as BC
+import qualified Data.ByteString.Lazy as BL
import Data.Char
import Data.List
import Data.Maybe
@@ -72,10 +74,31 @@ updateErebosHead st f = do
return x
main :: IO ()
-main = runInputT defaultSettings $ do
- bhost <- liftIO getArgs >>= \case [bhost] -> return bhost
- _ -> error "Expecting broadcast address"
+main = do
st <- liftIO $ openStorage "test"
+ getArgs >>= \case
+ ["cat-file", sref] -> do
+ readRef st (BC.pack sref) >>= \case
+ Nothing -> error "ref does not exist"
+ Just ref -> BL.putStr $ lazyLoadBytes ref
+
+ ["cat-file", objtype, sref] -> do
+ readRef st (BC.pack sref) >>= \case
+ Nothing -> error "ref does not exist"
+ Just ref -> case objtype of
+ "signed" -> do
+ let signed = load ref :: Signed Object
+ BL.putStr $ lazyLoadBytes $ storedRef $ signedData signed
+ forM_ (signedSignature signed) $ \sig -> do
+ putStr $ "SIG "
+ BC.putStrLn $ showRef $ storedRef $ sigKey $ fromStored sig
+ _ -> error $ "unknown object type '" ++ objtype ++ "'"
+
+ [bhost] -> interactiveLoop st bhost
+ _ -> error "Expecting broadcast address"
+
+interactiveLoop :: Storage -> String -> IO ()
+interactiveLoop st bhost = runInputT defaultSettings $ do
erebosHead <- liftIO $ loadErebosHead st
let serebos = wrappedLoad (headRef erebosHead) :: Stored Erebos
self = erbIdentity $ fromStored serebos