예제 #1
0
def test_generate(processes):
    d = tempfile.mkdtemp(prefix='zeus')
    try:
        filename = os.path.join(d, 'election.json')
        main(['--generate', filename, '--parallel', str(processes)])
        # Parse the results back.
        with open(filename) as f:
            from_canonical(f)
    finally:
        shutil.rmtree(d)
예제 #2
0
def add_remote_mix(election_id, mix_tmp_file, mix_id=None):
    e = Election.objects.get(pk=election_id)
    tmp_file = file(mix_tmp_file)
    mix = from_canonical(tmp_file)
    error = e.add_remote_mix(mix, mix_id)
    if error:
        election_notify_admin.delay(election_id=election_id,
                                    subject="Remote mix failed to add",
                                    body=error)
        return

    election_notify_admin.delay(election_id=election_id,
                                subject="Remote mix added to election",
                                body=traceback.format_exc())
예제 #3
0
def do_mix(mixfile, newfile, nr_rounds, nr_parallel, module):
    if exists(newfile):
        m = "file '%s' already exists, will not overwrite" % (newfile,)
        raise ValueError(m)

    with open(mixfile) as f:
        mix = from_canonical(f)

    new_mix = module.mix_ciphers(mix, nr_rounds=nr_rounds,
                          nr_parallel=nr_parallel)
    with open(newfile, "w") as f:
        to_canonical(new_mix, out=f)

    return new_mix
예제 #4
0
파일: client.py 프로젝트: gchatzip/zeus
def do_mix(mixfile, newfile, nr_rounds, nr_parallel):
    if exists(newfile):
        m = "file '%s' already exists, will not overwrite" % (newfile,)
        raise ValueError(m)

    with open(mixfile) as f:
        mix = from_canonical(f)

    new_mix = mix_ciphers(mix, nr_rounds=nr_rounds,
                          nr_parallel=nr_parallel)
    with open(newfile, "w") as f:
        to_canonical(new_mix, out=f)

    return new_mix
예제 #5
0
파일: tasks.py 프로젝트: peterhassapis/zeus
def add_remote_mix(election_id, mix_tmp_file, mix_id=None):
    e = Election.objects.get(pk=election_id)
    tmp_file = file(mix_tmp_file)
    mix = from_canonical(tmp_file)
    error = e.add_remote_mix(mix, mix_id)
    if error:
        election_notify_admin.delay(election_id=election_id,
                                    subject="Remote mix failed to add",
                                    body=error)
        return

    election_notify_admin.delay(election_id=election_id,
                                subject="Remote mix added to election",
                                body=traceback.format_exc())
예제 #6
0
def remote_mix(request, election, poll, mix_key):
    method = request.method
    if not election.check_mix_key(mix_key):
        raise PermissionDenied
    if method == 'GET':
        resp = poll.zeus.get_last_mix()
        # Use X_SEND_FILE
        return HttpResponse(to_canonical(resp),
                            content_type="application/octet-stream")
    if method == 'POST':
        data = from_canonical(request.body or '')
        result = poll.add_remote_mix(data)
        return HttpResponse(result, content_type="plain/text")

    raise PermissionDenied
예제 #7
0
파일: poll.py 프로젝트: grnet/zeus
def remote_mix(request, election, poll, mix_key):
    method = request.method
    if not election.check_mix_key(mix_key):
        raise PermissionDenied
    if method == 'GET':
        resp = poll.zeus.get_last_mix()
        # Use X_SEND_FILE
        return HttpResponse(to_canonical(resp),
                        content_type="application/octet-stream")
    if method == 'POST':
        data = from_canonical(request.body or '')
        result = poll.add_remote_mix(data)
        return HttpResponse(result, content_type="plain/text")

    raise PermissionDenied
예제 #8
0
def do_mix(mixfile, newfile, nr_rounds, nr_parallel, module):
    if exists(newfile):
        m = "file '%s' already exists, will not overwrite" % (newfile,)
        raise ValueError(m)

    if os.path.exists("{}.0".format(mixfile)):
        i = 0
        while os.path.exists("{}.{}".format(mixfile, i)):
            do_mix("{}.{}".format(mixfile, i), "{}.{}".format(newfile, i),
                   nr_rounds, nr_parallel, module)
            i = i + 1
        return

    with open(mixfile) as f:
        mix = from_canonical(f)

    new_mix = module.mix_ciphers(mix, nr_rounds=nr_rounds,
                          nr_parallel=nr_parallel)
    with open(newfile, "w") as f:
        to_canonical(new_mix, out=f)

    return new_mix