Skip to content
Snippets Groups Projects
Commit 5248c188 authored by Ben Adida's avatar Ben Adida
Browse files

partial conversion to new serializations, not working yet

parent be46f3c6
Branches
Tags
No related merge requests found
......@@ -28,6 +28,24 @@ And when data comes in:
from helios import utils
class LDObjectContainer(object):
"""
a simple container for an LD Object.
"""
@property
def ld_object(self):
if not hasattr(self, '_ld_object'):
self._ld_object = LDObject.instantiate(self)
return self._ld_object
def toJSONDict(self):
return self.ld_object.toDict()
def toJSON(self):
return self.ld_object.serialize()
class LDObject(object):
"""
A linked-data object wraps another object and serializes it according to a particular
......
......
......@@ -11,5 +11,15 @@ class BigInteger(LDObject):
"""
def toDict(self):
if self.wrapped_obj:
return str(self.wrapped_obj)
else:
return None
class Timestamp(LDObject):
def toDict(self):
if self.wrapped_obj:
return str(self.wrapped_obj)
else:
return None
......@@ -12,7 +12,10 @@ class Election(LegacyObject):
'frozen_at', 'public_key', 'cast_url', 'use_voter_aliases', 'voting_starts_at', 'voting_ends_at']
STRUCTURED_FIELDS = {
'public_key' : 'legacy/EGPublicKey'
'public_key' : 'legacy/EGPublicKey',
'voting_starts_at': 'core/Timestamp',
'voting_ends_at': 'core/Timestamp',
'frozen_at': 'core/Timestamp'
}
class EncryptedAnswer(LegacyObject):
......@@ -26,10 +29,36 @@ class EncryptedAnswer(LegacyObject):
}
class Voter(LegacyObject):
pass
FIELDS = ['election_uuid', 'uuid', 'voter_type', 'voter_id_hash', 'name', 'alias']
ALIASED_VOTER_FIELDS = ['election_uuid', 'uuid', 'alias']
def toDict(self):
"""
depending on whether the voter is aliased, use different fields
"""
if self.wrapped_obj.alias != None:
return super(Voter, self).toDict(self.ALIASED_VOTER_FIELDS)
else:
return super(Voter,self).toDict()
class CastVote(LegacyObject):
pass
FIELDS = ['vote', 'cast_at', 'voter_uuid', 'voter_hash', 'vote_hash']
class Trustee(LegacyObject):
pass
FIELDS = ['uuid', 'public_key', 'public_key_hash', 'pok', 'decryption_factors', 'decryption_proofs', 'email']
STRUCTURED_FIELDS = {
'public_key' : 'legacy/EGPublicKey',
'pok': 'legacy/DLogProof',
'decryption_factors': arrayOf('core/BigInteger'),
'decryption_proofs' : arrayOf('legacy/DLogProof')}
class EGPublicKey(LegacyObject):
FIELDS = ['y', 'p', 'g', 'q']
STRUCTURED_FIELDS = {
'y': 'core/BigInteger',
'p': 'core/BigInteger',
'q': 'core/BigInteger',
'g': 'core/BigInteger'}
This diff is collapsed.
......@@ -17,6 +17,8 @@ from crypto import electionalgs, algs, utils
from helios import utils as heliosutils
import helios
from helios import datatypes
# useful stuff in auth
from auth.models import User, AUTH_SYSTEMS
from auth.jsonfield import JSONField
......@@ -28,7 +30,11 @@ GLOBAL_COUNTER_VOTERS = 'global_counter_voters'
GLOBAL_COUNTER_CAST_VOTES = 'global_counter_cast_votes'
GLOBAL_COUNTER_ELECTIONS = 'global_counter_elections'
class Election(models.Model, electionalgs.Election):
class HeliosModel(models.Model, datatypes.LDObjectContainer):
class Meta:
abstract = True
class Election(HeliosModel):
admin = models.ForeignKey(User)
uuid = models.CharField(max_length=50, null=False)
......@@ -554,7 +560,7 @@ class VoterFile(models.Model):
class Voter(models.Model, electionalgs.Voter):
class Voter(HeliosModel):
election = models.ForeignKey(Election)
# let's link directly to the user now
......@@ -722,7 +728,7 @@ class Voter(models.Model, electionalgs.Voter):
return CastVote(vote = self.vote, vote_hash = self.vote_hash, cast_at = self.cast_at, voter=self)
class CastVote(models.Model, electionalgs.CastVote):
class CastVote(HeliosModel):
# the reference to the voter provides the voter_uuid
voter = models.ForeignKey(Voter)
......@@ -834,7 +840,7 @@ class AuditedBallot(models.Model):
return query
class Trustee(models.Model, electionalgs.Trustee):
class Trustee(HeliosModel):
election = models.ForeignKey(Election)
uuid = models.CharField(max_length=50)
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment