gdritter repos GRUtils / cce3212
Misc deletions and restructuring Getty Ritter 7 years ago
9 changed file(s) with 81 addition(s) and 98 deletion(s). Collapse all Expand all
+0
-14
RSAPair/LICENSE less more
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
+0
-16
RSAPair/RSAPair.cabal less more
1 name: RSAPair
2 version: 0.1.0.1
3 license: OtherLicense
4 license-file: LICENSE
5 author: Getty Ritter
6 maintainer: gdritter@galois.com
7 category: Codec
8 build-type: Simple
9 cabal-version: >=1.10
10
11 executable rsa-pair
12 main-is: RSAPair.hs
13 build-depends: base >=4.6 && <4.8,
14 bytestring, binary, DRBG, crypto-api, RSA
15 hs-source-dirs: src
16 default-language: Haskell2010
+0
-2
RSAPair/Setup.hs less more
1 import Distribution.Simple
2 main = defaultMain
+0
-27
RSAPair/src/RSAPair.hs less more
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 import System.Environment (getArgs)
10 import System.IO (hPutStrLn, stderr)
11
12 toHex :: (Binary a) => a -> String
13 toHex = concat . map (flip showHex "") . BS.unpack . encode
14
15 main :: IO ()
16 main = do
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
22 putStrLn ("pub: " ++ toHex pub)
23 putStrLn ("priv: " ++ toHex priv)
24
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)
1212
1313 executable json2bencode
1414 main-is: Main.hs
15 -- other-modules:
16 -- other-extensions:
17 build-depends: base >=4.8 && <4.9,
15 build-depends: base,
1816 aeson,
1917 bencode,
2018 bytestring,
+0
-32
json2bencode/stack.yaml less more
1 # For more information, see: https://github.com/commercialhaskell/stack/blob/release/doc/yaml_configuration.md
2
3 # Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2)
4 resolver: lts-3.19
5
6 # Local packages, usually specified by relative directory name
7 packages:
8 - '.'
9
10 # Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3)
11 extra-deps: []
12
13 # Override default flag values for local packages and extra-deps
14 flags: {}
15
16 # Extra package databases containing global packages
17 extra-package-dbs: []
18
19 # Control whether we use the GHC we find on the path
20 # system-ghc: true
21
22 # Require a specific version of stack, using version ranges
23 # require-stack-version: -any # Default
24 # require-stack-version: >= 0.1.4.0
25
26 # Override the architecture used by stack, especially useful on Windows
27 # arch: i386
28 # arch: x86_64
29
30 # Extra directories used by stack for building
31 # extra-include-dirs: [/path/to/dir]
32 # extra-lib-dirs: [/path/to/dir]
1 #!/usr/bin/python
2
3 import os
4 import sys
5 import json
6 import yaml
7
8
9 def die(msg, *args):
10 sys.stderr.write(msg + '\n', *args)
11 sys.exit(99)
12
13
14 def load_dir(dir_name):
15 if not os.path.isdir(dir_name):
16 die("{0} is not a directory", dir_name)
17 else:
18 return dict((path, load_elem(os.path.join(dir_name, path)))
19 for path in os.listdir(dir_name) if path[0] != '.')
20
21
22 def load_elem(path):
23 if os.path.isdir(path):
24 return load_dir(path)
25 else:
26 with open(path) as f:
27 content = f.read()
28 try:
29 return json.loads(content)
30 except ValueError:
31 return content.strip()
32
33 if __name__ == '__main__':
34 if sys.argv[1:]:
35 dir_name = sys.argv[1]
36 else:
37 dir_name = os.getcwd()
38 yaml.dump(load_dir(dir_name), sys.stdout)
3939 EOF
4040
4141 cd $DIR
42 cabal sandbox init
43 cabal install
44 cabal configure
45 exec cabal repl
42 cabal new-build
43 exec cabal new-repl
1 #!/usr/bin/python
2
3 import os
4 import sys
5 import json
6 import yaml
7
8
9 def die(msg, *args):
10 sys.stderr.write(msg + '\n', *args)
11 sys.exit(99)
12
13
14 def emit(datum, root='./'):
15 if type(datum) is not dict:
16 die("Unexpected type: {0} of type {1}", datum, type(datum))
17 else:
18 for key, val in datum.items():
19 if type(val) is dict:
20 new_root = os.path.join(root, key)
21 os.makedir(new_root)
22 emit(val, root=new_root)
23 elif type(val) is list:
24 die("Cannot serialize lists: {0}", datum)
25 elif type(val) is str or type(val) is unicode:
26 with open(os.path.join(root, key), 'w') as f:
27 f.write(val)
28 f.write('\n')
29 else:
30 with open(os.path.join(root, key), 'w') as f:
31 json.dump(val, f)
32 f.write('\n')
33
34 if __name__ == '__main__':
35 if sys.argv[:1] and sys.argv[1] != '-':
36 with open(sys.argv[1]) as f:
37 datum = yaml.load(f)
38 else:
39 datum = yaml.load(sys.stdin)
40 emit(datum)