diff --git a/README.md b/README.md index c34c52b86a12b2c23ee4ecc7bfbc3d7659a67339..b125ead62c5b1422eea5065034692bb6f03377eb 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,8 @@ It aims for bit-for-bit compatibility with the original Python implementation. ### What is the current state? -It's just starting. -It can't do much. +* It can download immutable and mutable shares from Great Black Swamp storage servers. +* It can interpret, decode, and decrypt the data for CHK- and SDMF-encoded shares to recover the plaintext. ## Why does it exist? diff --git a/download-sdmf/Main.hs b/download-sdmf/Main.hs new file mode 100644 index 0000000000000000000000000000000000000000..4e981e104d4c59e4c7e37b885b1851ab1a5d2a43 --- /dev/null +++ b/download-sdmf/Main.hs @@ -0,0 +1,34 @@ +module Main where + +import qualified Data.ByteString as B +import qualified Data.ByteString.Char8 as C8 +import qualified Data.ByteString.Lazy as BL +import qualified Data.Text as T +import Data.Yaml (decodeEither') +import System.Environment (getArgs) +import Tahoe.Announcement (Announcements (..)) +import Tahoe.Download (announcementToMutableStorageServer, download) +import Tahoe.SDMF (SDMF (..), pCapability, writerReader) +import Text.Megaparsec (parse) + +main :: IO () +main = do + [announcementPath, readCap] <- getArgs + -- Load server announcements + announcementsBytes <- B.readFile announcementPath + let Right (Announcements announcements) = decodeEither' announcementsBytes + + -- Accept & parse read capability + case parse pCapability "<argv>" (T.pack readCap) of + Left e -> print $ "Failed to parse cap: " <> show e + Right (SDMFVerifier _) -> C8.putStrLn "Nothing currently implemented for verifier caps." + Right (SDMFWriter rwcap) -> go announcements (writerReader rwcap) + Right (SDMFReader rocap) -> go announcements rocap + where + go announcements cap = do + -- Download & decode the shares + result <- download announcements cap announcementToMutableStorageServer + + -- Show the result + putStrLn "Your result:" + either print (C8.putStrLn . BL.toStrict) result diff --git a/gbs-downloader.cabal b/gbs-downloader.cabal index 908ee891719fb132e1d80e2575152ee292e5420a..d386c9d06b46e7fd44a3fe4ee2fd9f147d2b6dd2 100644 --- a/gbs-downloader.cabal +++ b/gbs-downloader.cabal @@ -155,6 +155,26 @@ executable gbs-download-chk -- Base language which the package is written in. default-language: Haskell2010 +executable gbs-download-sdmf + import: + warnings + , language + + main-is: Main.hs + build-depends: + , aeson + , base + , bytestring + , containers + , gbs-downloader + , megaparsec + , tahoe-ssk + , text + , yaml + + hs-source-dirs: download-sdmf + default-language: Haskell2010 + test-suite gbs-downloader-test -- Import common warning flags. import: