Quellcode durchsuchen

JSString conversion utility

Getty Ritter vor 10 Jahren
Ursprung
Commit
e9fa0c9dcc

+ 10 - 4
RSAPair/src/RSAPair.hs

@@ -6,16 +6,22 @@ import           Crypto.Random.DRBG
 import           Data.Binary
 import qualified Data.ByteString.Lazy as BS
 import           Numeric (showHex)
+import           System.Environment (getArgs)
+import           System.IO (hPutStrLn, stderr)
 
 toHex :: (Binary a) => a -> String
 toHex = concat . map (flip showHex "") . BS.unpack . encode
 
 main :: IO ()
 main = do
-  (pub, priv) <- genPair
+  args <- getArgs
+  let size = case args of (s:_) -> read s
+                          _     -> 1024
+  hPutStrLn stderr ("Generating key pair of size " ++ show size)
+  (pub, priv) <- genPair size
   putStrLn ("pub: " ++ toHex pub)
   putStrLn ("priv: " ++ toHex priv)
 
-genPair :: IO (PublicKey, PrivateKey)
-genPair = go `fmap` (newGenIO :: IO HashDRBG)
-  where go g = let (pub, priv, _) = generateKeyPair g 1024 in (pub, priv)
+genPair :: Int -> IO (PublicKey, PrivateKey)
+genPair size = go `fmap` (newGenIO :: IO HashDRBG)
+  where go g = let (pub, priv, _) = generateKeyPair g size in (pub, priv)

+ 14 - 0
ToJSString/LICENSE

@@ -0,0 +1,14 @@
+            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+                    Version 2, December 2004
+
+ Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
+
+ Everyone is permitted to copy and distribute verbatim or modified
+ copies of this license document, and changing it is allowed as long
+ as the name is changed.
+
+            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. You just DO WHAT THE FUCK YOU WANT TO.
+

+ 2 - 0
ToJSString/Setup.hs

@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain

+ 22 - 0
ToJSString/ToJSString.cabal

@@ -0,0 +1,22 @@
+-- Initial ToJSString.cabal generated by cabal init.  For further 
+-- documentation, see http://haskell.org/cabal/users-guide/
+
+name:                ToJSString
+version:             0.1.0.0
+-- synopsis:            
+-- description:         
+-- license:             
+license-file:        LICENSE
+author:              Getty Ritter
+maintainer:          gdritter@galois.com
+-- copyright:           
+category:            Codec
+build-type:          Simple
+-- extra-source-files:  
+cabal-version:       >=1.10
+
+executable ToJSString
+  main-is:             ToJSString.hs
+  build-depends:       base >=4.6 && <4.7, aeson, text, bytestring
+  hs-source-dirs:      src
+  default-language:    Haskell2010

+ 8 - 0
ToJSString/src/ToJSString.hs

@@ -0,0 +1,8 @@
+module Main where
+
+import Data.Aeson (Value(String), encode)
+import Data.ByteString.Lazy.Char8 (putStrLn)
+import Data.Text.IO (getContents)
+import Prelude hiding (getContents, putStrLn)
+
+main = getContents >>= putStrLn . encode . String

+ 8 - 0
ToJSString/src/ToJSString.hs~

@@ -0,0 +1,8 @@
+module Main where
+
+import Control.Monad ((>=>))
+import Data.Aeson (Value(String))
+import Data.Text.IO (getContents)
+import Prelude hiding (getContents)
+
+main = getContents >>= putStrLn . show . String