ソースを参照

Initial commit; two basic utilities (for generating RSA pairs and converting between YAML<>JSON)

Getty Ritter 10 年 前
コミット
15fb553e0c

+ 14 - 0
RSAPair/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.
+

+ 23 - 0
RSAPair/RSAPair.cabal

@@ -0,0 +1,23 @@
+-- Initial RSAPair.cabal generated by cabal init.  For further 
+-- documentation, see http://haskell.org/cabal/users-guide/
+
+name:                RSAPair
+version:             0.1.0.0
+license:             OtherLicense
+license-file:        LICENSE
+author:              Getty Ritter
+maintainer:          gdritter@galois.com
+-- copyright:
+category:            Codec
+build-type:          Simple
+-- extra-source-files:
+cabal-version:       >=1.10
+
+executable RSAPair
+  main-is:             RSAPair.hs
+  -- other-modules:
+  -- other-extensions:
+  build-depends:       base >=4.6 && <4.7,
+                       bytestring, binary, DRBG, crypto-api, RSA
+  hs-source-dirs:      src
+  default-language:    Haskell2010

+ 2 - 0
RSAPair/Setup.hs

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

+ 21 - 0
RSAPair/src/RSAPair.hs

@@ -0,0 +1,21 @@
+module Main where
+
+import           Codec.Crypto.RSA
+import           Crypto.Random
+import           Crypto.Random.DRBG
+import           Data.Binary
+import qualified Data.ByteString.Lazy as BS
+import           Numeric (showHex)
+
+toHex :: (Binary a) => a -> String
+toHex = concat . map (flip showHex "") . BS.unpack . encode
+
+main :: IO ()
+main = do
+  (pub, priv) <- genPair
+  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)

+ 14 - 0
YAMLize/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
YAMLize/Setup.hs

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

+ 21 - 0
YAMLize/YAMLize.cabal

@@ -0,0 +1,21 @@
+name:                YAMLize
+version:             0.1.0.0
+license:             OtherLicense
+license-file:        LICENSE
+author:              Getty Ritter
+maintainer:          gdritter@galois.com
+category:            Data
+build-type:          Simple
+cabal-version:       >=1.10
+
+executable ToYAML
+  main-is:             ToYAML.hs
+  build-depends:       base >=4.6 && <4.7, yaml, aeson, bytestring
+  hs-source-dirs:      src
+  default-language:    Haskell2010
+
+executable FromYAML
+  main-is:             FromYAML.hs
+  build-depends:       base >=4.6 && <4.7, yaml, aeson, bytestring
+  hs-source-dirs:      src
+  default-language:    Haskell2010

+ 15 - 0
YAMLize/src/FromYAML.hs

@@ -0,0 +1,15 @@
+{-# LANGUAGE ScopedTypeVariables #-}
+
+module Main where
+
+import Control.Monad ((>=>))
+import qualified Data.Aeson as Json
+import qualified Data.ByteString as BS
+import qualified Data.ByteString.Lazy.Char8 as BSL
+import Data.Maybe (fromJust)
+import qualified Data.Yaml as Yaml
+
+main = do
+  contents <- BS.getContents
+  let value :: Yaml.Value = fromJust (Yaml.decode contents)
+  BSL.putStrLn (Json.encode value)

+ 15 - 0
YAMLize/src/ToYAML.hs

@@ -0,0 +1,15 @@
+{-# LANGUAGE ScopedTypeVariables #-}
+
+module Main where
+
+import Control.Monad ((>=>))
+import qualified Data.Aeson as Json
+import qualified Data.ByteString.Char8 as BS
+import qualified Data.ByteString.Lazy.Char8 as BSL
+import Data.Maybe (fromJust)
+import qualified Data.Yaml as Yaml
+
+main = do
+  contents <- BSL.getContents
+  let value :: Yaml.Value = fromJust (Json.decode contents)
+  BS.putStrLn (Yaml.encode value)