Changeset - 4fa21dbcdb9d
[Not reviewed]
default
9 0 13
Laman - 4 years ago 2020-04-13 14:46:29

created installation script, reorganized directory structure
13 files changed with 45 insertions and 32 deletions:
0 comments (0 inline, 0 general)
.hgignore
Show inline comments
 
new file 100644
 
^\..*
 
\.pyc$
 
^build/
 
^dist/
 
.egg-info/
setup.py
Show inline comments
 
new file 100644
 
from setuptools import setup
 

	
 

	
 
setup(
 
	name="Shamira",
 
	version="0.1",
 
	packages=["shamira"],
 
	package_dir={"": "src"}
 
)
src/shamira/__init__.py
Show inline comments
 
new file 100644
 
from .core import generate, generate_raw, reconstruct, reconstruct_raw
 
from .core import SException, InvalidParams, DetectionException, DecodingException, MalformedShare
src/shamira/__main__.py
Show inline comments
 
new file 100644
 
from . import cli
 

	
 
cli.run()
src/shamira/benchmark.py
Show inline comments
 
file renamed from src/benchmark.py to src/shamira/benchmark.py
 
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):
 
	secret = "1234567890123456"
 
	shares = generate(secret, args.k, args.n)
 
	symbols = globals()
 
	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):
 
	t = TestShamira()
 

	
 
	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)
src/shamira/cli.py
Show inline comments
 
file renamed from src/cli.py to src/shamira/cli.py
 
# GNU GPLv3, see LICENSE
 

	
 
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():
 
	parser = ArgumentParser()
 
	subparsers = parser.add_subparsers()
 

	
 
	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"))
 

	
 
	args = parser.parse_args()
 
	args.func(args)
 

	
src/shamira/condensed.py
Show inline comments
 
file renamed from src/condensed.py to src/shamira/condensed.py
src/shamira/core.py
Show inline comments
 
file renamed from src/shamira.py to src/shamira/core.py
 
@@ -2,13 +2,13 @@
 

	
 
import os
 
import re
 
import base64
 
import binascii
 

	
 
import gf256
 
from . import gf256
 

	
 

	
 
class SException(Exception): pass
 
class InvalidParams(SException): pass
 
class DetectionException(SException): pass
 
class DecodingException(SException): pass
 
@@ -121,11 +121,6 @@ def detect_encoding(shares):
 
		(re.compile(r"(.*\.)?\d+\.([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{2}={2}|[A-Za-z0-9+/]{3}={1})"), "b64")
 
	]
 
	for (regexp, res) in classes:
 
		if all(regexp.fullmatch(share) for share in shares):
 
			return res
 
	raise DetectionException("No expected encoding detected")
 

	
 

	
 
if __name__=="__main__":
 
	import cli
 
	cli.run()
src/shamira/gf256.py
Show inline comments
 
file renamed from src/gf256.py to src/shamira/gf256.py
src/shamira/tests/__init__.py
Show inline comments
 
file renamed from src/tests/__init__.py to src/shamira/tests/__init__.py
src/shamira/tests/test_condensed.py
Show inline comments
 
file renamed from src/tests/test_condensed.py to src/shamira/tests/test_condensed.py
 
# GNU GPLv3, see LICENSE
 

	
 
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):
 
	_urandom = os.urandom
 

	
 
	@classmethod
src/shamira/tests/test_gf256.py
Show inline comments
 
file renamed from src/tests/test_gf256.py to src/shamira/tests/test_gf256.py
 
# GNU GPLv3, see LICENSE
 

	
 
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):
 
	def test__gfmul(self):
 
		self.assertEqual(_gfmul(0, 0), 0)
 
		self.assertEqual(_gfmul(1, 1), 1)
src/shamira/tests/test_shamira.py
Show inline comments
 
file renamed from src/tests/test_shamira.py to src/shamira/tests/test_shamira.py
 
# 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):
 
	_urandom = os.urandom
 

	
 
	@classmethod
0 comments (0 inline, 0 general)