Skip to content

Commit

Permalink
fixed API client support and test driver
Browse files Browse the repository at this point in the history
  • Loading branch information
benadida committed Nov 3, 2008
1 parent 59a0c3f commit 3cf4fbb
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions client/heliosclient.py
Expand Up @@ -29,7 +29,7 @@ def params(self):
return algs.ElGamal.fromJSONDict(utils.from_json(params_json))

def election_new(self, name, public_key):
election_id = self.post("/elections/new_2", {"name" : name, "public_key" : utils.to_json(public_key.toJSONDict())})
election_id = self.post("/elections/new_3", {"name" : name, "public_key" : utils.to_json(public_key.toJSONDict())})
return election_id

def election_get(self, election_id):
Expand All @@ -40,7 +40,7 @@ def election_set_reg(self, election_id, open_reg=False):
return result == "SUCCESS"

def election_questions_save(self, election_id, questions):
result = self.post("/elections/%s/save" % election_id, {'election_json' : utils.to_json({'questions':questions})})
result = self.post("/elections/%s/save_questions" % election_id, {'questions_json' : utils.to_json(questions)})
return result == "SUCCESS"

def election_freeze(self, election_id):
Expand Down
2 changes: 1 addition & 1 deletion client/oauthclient.py
Expand Up @@ -28,7 +28,7 @@ def access_resource(self, method, url, parameters):
if parameters == {}:
headers['Content-Length'] = 0

print "headers: " + str(headers)
#print "headers: " + str(headers)

connection = httplib.HTTPConnection("%s:%d" % (self.server, self.port))
connection.request(method, url, headers= headers, body = utils.dictToURLParams(parameters))
Expand Down
8 changes: 5 additions & 3 deletions crypto/electionalgs.py
Expand Up @@ -60,9 +60,10 @@ def fromJSONDict(cls, d, pk):
return ea

@classmethod
def fromElectionAndAnswer(cls, election, question_num, answer_index):
def fromElectionAndAnswer(cls, election, question_num, answer_indexes):
"""
Given an election, a question number, and an answer to that question in the form of a 0-based index into the answer array,
Given an election, a question number, and a list of answers to that question
in the form of an array of 0-based indexes into the answer array,
produce an EncryptedAnswer that works.
"""
question = election.questions[question_num]
Expand All @@ -89,7 +90,8 @@ def fromElectionAndAnswer(cls, election, question_num, answer_index):
for answer_num in range(len(answers)):
plaintext_index = 0

if answer_num == answer_index:
# assuming a list of answers
if answer_num in answer_indexes:
plaintext_index = 1
num_selected_answers += 1

Expand Down
6 changes: 3 additions & 3 deletions index.yaml
Expand Up @@ -10,14 +10,14 @@ indexes:
# automatically uploaded to the admin console when you next deploy
# your application using appcfg.py.

# Used once in query history.
# Used 6 times in query history.
- kind: ElectionExponent
properties:
- name: election
- name: exponent
direction: desc

# Used 33 times in query history.
# Unused in query history -- copied from input.
- kind: KeyShare
properties:
- name: election
Expand All @@ -43,7 +43,7 @@ indexes:
- name: tallied_at
- name: cast_id

# Used 24 times in query history.
# Unused in query history -- copied from input.
- kind: Voter
properties:
- name: election
Expand Down
2 changes: 1 addition & 1 deletion static/docs/verification-specs.html
Expand Up @@ -351,7 +351,7 @@ <h2>Verifying a Single Ballot</h2>
return False

# the overall challenge
computed_challenge = sum([proof.challenge for proof in disjunctive_proof]) % public_key.p
computed_challenge = sum([proof.challenge for proof in disjunctive_proof]) % public_key.q

# concatenate the arrays of A,B values
list_of_values_to_hash = sum([[p.commitment.A, p.commitment.B] for p in disjunctive_proof], [])
Expand Down
8 changes: 4 additions & 4 deletions tests/heliosclient.py
Expand Up @@ -14,7 +14,7 @@

# instantiate the client
# modify variables here
helios = heliosclient.HeliosClient({'consumer_key': 'votehere', 'consumer_secret': 'votehere',
helios = heliosclient.HeliosClient({'consumer_key': 'test', 'consumer_secret': 'test',
'access_token': '123', 'access_token_secret' : '123'},
host = 'localhost',
port = 8082)
Expand Down Expand Up @@ -47,9 +47,9 @@
print "election hash is %s" % election.hash

# create three ballots
ballot_1 = electionalgs.EncryptedVote.fromElectionAndAnswers(election, [1])
ballot_2 = electionalgs.EncryptedVote.fromElectionAndAnswers(election, [1])
ballot_3 = electionalgs.EncryptedVote.fromElectionAndAnswers(election, [0])
ballot_1 = electionalgs.EncryptedVote.fromElectionAndAnswers(election, [[1]])
ballot_2 = electionalgs.EncryptedVote.fromElectionAndAnswers(election, [[1]])
ballot_3 = electionalgs.EncryptedVote.fromElectionAndAnswers(election, [[0]])

print "created 3 ballots"

Expand Down

0 comments on commit 3cf4fbb

Please sign in to comment.