diff --git a/.hgignore b/.hgignore new file mode 100644 --- /dev/null +++ b/.hgignore @@ -0,0 +1,5 @@ +^\..* +\.pyc$ +^build/ +^dist/ +.egg-info/ diff --git a/setup.py b/setup.py new file mode 100644 --- /dev/null +++ b/setup.py @@ -0,0 +1,9 @@ +from setuptools import setup + + +setup( + name="Shamira", + version="0.1", + packages=["shamira"], + package_dir={"": "src"} +) diff --git a/src/shamira/__init__.py b/src/shamira/__init__.py new file mode 100644 --- /dev/null +++ b/src/shamira/__init__.py @@ -0,0 +1,2 @@ +from .core import generate, generate_raw, reconstruct, reconstruct_raw +from .core import SException, InvalidParams, DetectionException, DecodingException, MalformedShare diff --git a/src/shamira/__main__.py b/src/shamira/__main__.py new file mode 100644 --- /dev/null +++ b/src/shamira/__main__.py @@ -0,0 +1,3 @@ +from . import cli + +cli.run() diff --git a/src/benchmark.py b/src/shamira/benchmark.py rename from src/benchmark.py rename to src/shamira/benchmark.py --- a/src/benchmark.py +++ b/src/shamira/benchmark.py @@ -1,9 +1,8 @@ -from argparse import ArgumentParser import cProfile import timeit -from shamira import generate, reconstruct -from tests.test_shamira import TestShamira +from . import generate, reconstruct +from .tests.test_shamira import TestShamira def measure(args): @@ -13,10 +12,10 @@ def measure(args): symbols.update(locals()) time = timeit.timeit("""generate(secret, args.k, args.n)""", number=1, globals=symbols) - print("The generation took {0:.3}s, {1:.3} per byte.".format(time, time/16)) + print("The generation took {0:.3}s, {1:.3}s per byte.".format(time, time/16)) time = timeit.timeit("""reconstruct(*shares)""", number=1, globals=symbols) - print("The reconstruction took {0:.3}s, {1:.3} per byte.".format(time, time/16)) + print("The reconstruction took {0:.3}s, {1:.3}s per byte.".format(time, time/16)) def profile(args): @@ -25,17 +24,14 @@ def profile(args): cProfile.runctx(r"""t.test_generate_reconstruct()""", globals=globals(), locals=locals()) -parser = ArgumentParser() -parser.set_defaults(func=lambda _: parser.error("missing command")) -subparsers = parser.add_subparsers() - -profile_parser = subparsers.add_parser("profile") -profile_parser.set_defaults(func=profile) +def build_subparsers(parent): + parent.set_defaults(func=lambda _: parent.error("missing command")) + subparsers = parent.add_subparsers() -measure_parser = subparsers.add_parser("measure") -measure_parser.add_argument("-k", type=int, required=True) -measure_parser.add_argument("-n", type=int, required=True) -measure_parser.set_defaults(func=measure) + profile_parser = subparsers.add_parser("profile") + profile_parser.set_defaults(func=profile) -args = parser.parse_args() -args.func(args) + measure_parser = subparsers.add_parser("measure") + measure_parser.add_argument("-k", type=int, required=True) + measure_parser.add_argument("-n", type=int, required=True) + measure_parser.set_defaults(func=measure) diff --git a/src/cli.py b/src/shamira/cli.py rename from src/cli.py rename to src/shamira/cli.py --- a/src/cli.py +++ b/src/shamira/cli.py @@ -3,7 +3,8 @@ import sys from argparse import ArgumentParser -from shamira import generate, reconstruct, SException +from .core import generate, reconstruct, SException +from .benchmark import build_subparsers as build_benchmark def run(): @@ -12,6 +13,7 @@ def run(): build_split_parser(subparsers.add_parser("split")) build_join_parser(subparsers.add_parser("join")) + build_benchmark(subparsers.add_parser("benchmark")) parser.set_defaults(func=lambda _: parser.error("missing command")) diff --git a/src/condensed.py b/src/shamira/condensed.py rename from src/condensed.py rename to src/shamira/condensed.py diff --git a/src/shamira.py b/src/shamira/core.py rename from src/shamira.py rename to src/shamira/core.py --- a/src/shamira.py +++ b/src/shamira/core.py @@ -5,7 +5,7 @@ import re import base64 import binascii -import gf256 +from . import gf256 class SException(Exception): pass @@ -124,8 +124,3 @@ def detect_encoding(shares): if all(regexp.fullmatch(share) for share in shares): return res raise DetectionException("No expected encoding detected") - - -if __name__=="__main__": - import cli - cli.run() diff --git a/src/gf256.py b/src/shamira/gf256.py rename from src/gf256.py rename to src/shamira/gf256.py diff --git a/src/tests/__init__.py b/src/shamira/tests/__init__.py rename from src/tests/__init__.py rename to src/shamira/tests/__init__.py diff --git a/src/tests/test_condensed.py b/src/shamira/tests/test_condensed.py rename from src/tests/test_condensed.py rename to src/shamira/tests/test_condensed.py --- a/src/tests/test_condensed.py +++ b/src/shamira/tests/test_condensed.py @@ -4,9 +4,9 @@ import os import random from unittest import TestCase -from gf256 import _gfmul, evaluate -from shamira import generate_raw, generate -from condensed import * +from ..gf256 import _gfmul, evaluate +from .. import generate_raw, generate +from ..condensed import * class TestCondensed(TestCase): diff --git a/src/tests/test_gf256.py b/src/shamira/tests/test_gf256.py rename from src/tests/test_gf256.py rename to src/shamira/tests/test_gf256.py --- a/src/tests/test_gf256.py +++ b/src/shamira/tests/test_gf256.py @@ -4,8 +4,8 @@ import random import unittest from unittest import TestCase -from gf256 import _gfmul -from gf256 import * +from ..gf256 import _gfmul +from ..gf256 import * class TestGF256(TestCase): diff --git a/src/tests/test_shamira.py b/src/shamira/tests/test_shamira.py rename from src/tests/test_shamira.py rename to src/shamira/tests/test_shamira.py --- a/src/tests/test_shamira.py +++ b/src/shamira/tests/test_shamira.py @@ -1,10 +1,11 @@ # GNU GPLv3, see LICENSE - +import os import random from unittest import TestCase -from shamira import _share_byte -from shamira import * +from .. import * +from .. import gf256 +from ..core import encode, decode,detect_encoding, _share_byte class TestShamira(TestCase):