Beispiel #1
0
 public void AddVoter(IVoter voter)
 {
     if (!voterDictionary.ContainsKey(voter.Name))
     {
         voterDictionary[voter.Name] = voter;
     }
 }
Beispiel #2
0
        public void AddVoterWithChoice(String voterName, String choice)
        {
            IVoter voter = findVoter(voterName).VoterItem;

            voter.Pick(choice);
            AddVoter(voter);
        }
        /// <summary>
        /// Saves the current voter progress and his answers to the database
        /// </summary>
        public void SaveVoterProgress(VoterAnswersData voterAnswers)
        {
            IVoter           voter = VoterFactory.Create();
            VoterAnswersData data  = new VoterAnswersData();

            data.Merge(voterAnswers, false);
            voter.AddVoter(data);
        }
Beispiel #4
0
        public void AddVoterWithDelegate(String voterName, String delegateName)
        {
            IVoter voter = findVoter(voterName).VoterItem;

            voter.DelegateToVoter = new Voter(delegateName);
            AddVoter(voter);
            AddVoter(voter.DelegateToVoter);
        }
Beispiel #5
0
        FindVoterResult findVoter(IVoter voter)
        {
            String voterName = (voter != null) ? voter.Name : "";

            if (voterDictionary.ContainsKey(voterName))
            {
                return(new FindVoterResult(voterDictionary[voterName], true));
            }

            return(new FindVoterResult(new Voter(voterName), false));
        }
Beispiel #6
0
        public void DelegateVote(IVoter fromWhom, IVoter toWhom)
        {
            FindVoterResult voterResult = findVoter(fromWhom);

            if (voterResult.IsFound)
            {
                voterResult.VoterItem.DelegateToVoter = toWhom;
            }
            else
            {
                fromWhom.DelegateToVoter = toWhom;
                AddVoter(fromWhom);
            }
        }
Beispiel #7
0
        bool AreVotesInvalidForVoter(IVoter voter)
        {
            HashSet <IVoter> uniqueVoters = new HashSet <IVoter>();
            FindVoterResult  voterResult  = findVoter(voter);

            while (voterResult.IsFound)
            {
                if (uniqueVoters.Contains(voterResult.VoterItem))
                {
                    return(true);
                }
                uniqueVoters.Add(voterResult.VoterItem);
                voterResult = findVoter(voterResult.VoterItem.DelegateToVoter);
            }
            return(false);
        }
Beispiel #8
0
        public byte[] AddVote(List <uint> rawVoteData, IVoter voter)
        {
            if (rawVoteData.Any(v => !(v == 0 || v == 1)))
            {
                throw new ArgumentException("Allowed values are 0 and 1");
            }

            if (rawVoteData.Sum(v => v) > 1)
            {
                rawVoteData = NullVote.ToList();
            }

            var publicKey = homomorphicKeyManager.DeserializePublicKey(boothInit.HomomorphicPublicKey);

            List <byte[]> encryptedTexts = new List <byte[]>();

            foreach (var candidate_vote in rawVoteData)
            {
                var encryptedVote = homomorphicKeyManager.Encrypt(publicKey, candidate_vote);
                encryptedTexts.Add(homomorphicKeyManager.SerializeCiphertext(encryptedVote));
            }
            var serializedVote = SerializeList(encryptedTexts);

            Vote vote = new Vote
            {
                BoothPublicCertificate = signCertificate.GetPublicKey(),
                CandidateVotes         = encryptedTexts,
                ID          = voter.ID,
                DisplayName = voter.DisplayName
            };

            vote.VoteSignature = signCertificate.Sign(vote.VoteHash);

            votes.Add(vote);

            return(vote.VoteHash);
        }
Beispiel #9
0
 public PostController(ICrud <Post> pc, IVoter voter)
 {
     this.pc    = pc;
     this.voter = voter;
 }
Beispiel #10
0
 public FindVoterResult(IVoter voter, bool isFound)
 {
     VoterItem = voter;
     IsFound   = isFound;
 }