aboutsummaryrefslogtreecommitdiff
path: root/nodejs/Main.hs
blob: 3cf74d9b8dca15f5123cb27eb64cabcc300b0f86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{-# LANGUAGE OverloadedStrings #-}

module Main where

import System.Environment (getArgs)
import System.Process (callProcess)
import Web.ZeroBin.SJCL (encrypt)
import Web.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
    ]