aboutsummaryrefslogtreecommitdiff
path: root/nodejs/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'nodejs/Main.hs')
-rw-r--r--nodejs/Main.hs32
1 files changed, 32 insertions, 0 deletions
diff --git a/nodejs/Main.hs b/nodejs/Main.hs
new file mode 100644
index 0000000..e1acb5d
--- /dev/null
+++ b/nodejs/Main.hs
@@ -0,0 +1,32 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+module Main where
+
+import System.Environment (getArgs)
+import System.Process (callProcess)
+import ZeroBin.SJCL (encrypt)
+import ZeroBin.Utils (makePassword)
+import qualified Data.Aeson as JSON
+import qualified Data.ByteString as BS
+import qualified Data.ByteString.Char8 as C
+import qualified Data.ByteString.Lazy as L
+
+-- nodejs is a Debian's thing, others may have simple "node"
+
+getText :: IO BS.ByteString
+getText = do
+ args <- map C.pack `fmap` getArgs
+ if null args
+ then return "heinrich hertz"
+ else return . BS.intercalate " " $ args
+
+main :: IO ()
+main = do
+ password <- makePassword 32
+ text <- getText
+ cont <- encrypt password text
+ callProcess "nodejs" [ "nodejs/decrypt.js"
+ , password
+ , C.unpack . L.toStrict $ JSON.encode cont
+ ]
+