Beispiel #1
0
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
Beispiel #2
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
Beispiel #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)

    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
Beispiel #4
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
Beispiel #5
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