gdritter repos GRUtils / 15fb553
Initial commit; two basic utilities (for generating RSA pairs and converting between YAML<>JSON) Getty Ritter 10 years ago
9 changed file(s) with 127 addition(s) and 0 deletion(s). Collapse all Expand all
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 -- Initial RSAPair.cabal generated by cabal init. For further
2 -- documentation, see http://haskell.org/cabal/users-guide/
3
4 name: RSAPair
5 version: 0.1.0.0
6 license: OtherLicense
7 license-file: LICENSE
8 author: Getty Ritter
9 maintainer: gdritter@galois.com
10 -- copyright:
11 category: Codec
12 build-type: Simple
13 -- extra-source-files:
14 cabal-version: >=1.10
15
16 executable RSAPair
17 main-is: RSAPair.hs
18 -- other-modules:
19 -- other-extensions:
20 build-depends: base >=4.6 && <4.7,
21 bytestring, binary, DRBG, crypto-api, RSA
22 hs-source-dirs: src
23 default-language: Haskell2010
1 import Distribution.Simple
2 main = defaultMain
1 module Main where
2
3 import Codec.Crypto.RSA
4 import Crypto.Random
5 import Crypto.Random.DRBG
6 import Data.Binary
7 import qualified Data.ByteString.Lazy as BS
8 import Numeric (showHex)
9
10 toHex :: (Binary a) => a -> String
11 toHex = concat . map (flip showHex "") . BS.unpack . encode
12
13 main :: IO ()
14 main = do
15 (pub, priv) <- genPair
16 putStrLn ("pub: " ++ toHex pub)
17 putStrLn ("priv: " ++ toHex priv)
18
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)
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 name: YAMLize
2 version: 0.1.0.0
3 license: OtherLicense
4 license-file: LICENSE
5 author: Getty Ritter
6 maintainer: gdritter@galois.com
7 category: Data
8 build-type: Simple
9 cabal-version: >=1.10
10
11 executable ToYAML
12 main-is: ToYAML.hs
13 build-depends: base >=4.6 && <4.7, yaml, aeson, bytestring
14 hs-source-dirs: src
15 default-language: Haskell2010
16
17 executable FromYAML
18 main-is: FromYAML.hs
19 build-depends: base >=4.6 && <4.7, yaml, aeson, bytestring
20 hs-source-dirs: src
21 default-language: Haskell2010
1 {-# LANGUAGE ScopedTypeVariables #-}
2
3 module Main where
4
5 import Control.Monad ((>=>))
6 import qualified Data.Aeson as Json
7 import qualified Data.ByteString as BS
8 import qualified Data.ByteString.Lazy.Char8 as BSL
9 import Data.Maybe (fromJust)
10 import qualified Data.Yaml as Yaml
11
12 main = do
13 contents <- BS.getContents
14 let value :: Yaml.Value = fromJust (Yaml.decode contents)
15 BSL.putStrLn (Json.encode value)
1 {-# LANGUAGE ScopedTypeVariables #-}
2
3 module Main where
4
5 import Control.Monad ((>=>))
6 import qualified Data.Aeson as Json
7 import qualified Data.ByteString.Char8 as BS
8 import qualified Data.ByteString.Lazy.Char8 as BSL
9 import Data.Maybe (fromJust)
10 import qualified Data.Yaml as Yaml
11
12 main = do
13 contents <- BSL.getContents
14 let value :: Yaml.Value = fromJust (Json.decode contents)
15 BS.putStrLn (Yaml.encode value)