gdritter repos GRUtils / e9fa0c9
JSString conversion utility Getty Ritter 10 years ago
6 changed file(s) with 64 addition(s) and 4 deletion(s). Collapse all Expand all
66 import Data.Binary
77 import qualified Data.ByteString.Lazy as BS
88 import Numeric (showHex)
9 import System.Environment (getArgs)
10 import System.IO (hPutStrLn, stderr)
911
1012 toHex :: (Binary a) => a -> String
1113 toHex = concat . map (flip showHex "") . BS.unpack . encode
1214
1315 main :: IO ()
1416 main = do
15 (pub, priv) <- genPair
17 args <- getArgs
18 let size = case args of (s:_) -> read s
19 _ -> 1024
20 hPutStrLn stderr ("Generating key pair of size " ++ show size)
21 (pub, priv) <- genPair size
1622 putStrLn ("pub: " ++ toHex pub)
1723 putStrLn ("priv: " ++ toHex priv)
1824
19 genPair :: IO (PublicKey, PrivateKey)
20 genPair = go `fmap` (newGenIO :: IO HashDRBG)
21 where go g = let (pub, priv, _) = generateKeyPair g 1024 in (pub, priv)
25 genPair :: Int -> IO (PublicKey, PrivateKey)
26 genPair size = go `fmap` (newGenIO :: IO HashDRBG)
27 where go g = let (pub, priv, _) = generateKeyPair g size in (pub, priv)
1 DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2 Version 2, December 2004
3
4 Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
5
6 Everyone is permitted to copy and distribute verbatim or modified
7 copies of this license document, and changing it is allowed as long
8 as the name is changed.
9
10 DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12
13 0. You just DO WHAT THE FUCK YOU WANT TO.
14
1 import Distribution.Simple
2 main = defaultMain
1 -- Initial ToJSString.cabal generated by cabal init. For further
2 -- documentation, see http://haskell.org/cabal/users-guide/
3
4 name: ToJSString
5 version: 0.1.0.0
6 -- synopsis:
7 -- description:
8 -- license:
9 license-file: LICENSE
10 author: Getty Ritter
11 maintainer: gdritter@galois.com
12 -- copyright:
13 category: Codec
14 build-type: Simple
15 -- extra-source-files:
16 cabal-version: >=1.10
17
18 executable ToJSString
19 main-is: ToJSString.hs
20 build-depends: base >=4.6 && <4.7, aeson, text, bytestring
21 hs-source-dirs: src
22 default-language: Haskell2010
1 module Main where
2
3 import Data.Aeson (Value(String), encode)
4 import Data.ByteString.Lazy.Char8 (putStrLn)
5 import Data.Text.IO (getContents)
6 import Prelude hiding (getContents, putStrLn)
7
8 main = getContents >>= putStrLn . encode . String
1 module Main where
2
3 import Control.Monad ((>=>))
4 import Data.Aeson (Value(String))
5 import Data.Text.IO (getContents)
6 import Prelude hiding (getContents)
7
8 main = getContents >>= putStrLn . show . String