public void TestMasterPasswordDb()
        {
            var db  = Station.Database;
            var vn  = new VoterNumber(250000);
            var cpr = new CPR(2312881234);

            Assert.That(db[cpr, "yo boii"] == BallotStatus.Unavailable);

            db.Import(new List <EncryptedVoterData> {
                new EncryptedVoterData(new CipherText(Station.Crypto.AsymmetricEncrypt(Bytes.From(vn.Value), Station.Crypto.VoterDataEncryptionKey)), new CipherText(Station.Crypto.AsymmetricEncrypt(Bytes.From(cpr.Value), Station.Crypto.VoterDataEncryptionKey)), new CipherText(Station.Crypto.AsymmetricEncrypt(Bytes.From(cpr.Value + (uint)BallotStatus.NotReceived), Station.Crypto.VoterDataEncryptionKey))), new EncryptedVoterData(new CipherText(Station.Crypto.AsymmetricEncrypt(Bytes.From(vn.Value + 5), Station.Crypto.VoterDataEncryptionKey)), new CipherText(Station.Crypto.AsymmetricEncrypt(Bytes.From(cpr.Value + 5), Station.Crypto.VoterDataEncryptionKey)), new CipherText(Station.Crypto.AsymmetricEncrypt(Bytes.From(cpr.Value + (uint)BallotStatus.NotReceived + 5), Station.Crypto.VoterDataEncryptionKey)))
            });

            Assert.That(db.AllData != null);
            Assert.That(db.AllData.All(data => !Equals(data.BallotStatus, null) && !Equals(data.CPR, null) && !Equals(data.VoterNumber, null)));
            Assert.That(db[cpr, "yo boii"] == BallotStatus.NotReceived);

            //Contracts do not allow us to do this, but they can be disabled....
            //Assert.Throws<ArgumentException>(() => status = db[cpr, "yo boii"]);
            //Assert.Throws<ArgumentException>(() => db[new CPR(123), "yo boii"] = BallotStatus.NotReceived);

            db[cpr, "yo boii"] = BallotStatus.Received;
            Assert.That(db[cpr, "yo boii"] == BallotStatus.Received);
            db[cpr, "yo boii"] = BallotStatus.NotReceived;
            Assert.That(db[cpr, "yo boii"] == BallotStatus.NotReceived);

            var notNull = true;

            db.AllData.ForEach(row => notNull = notNull & !Equals(row.VoterNumber, null));
            Assert.That(notNull);
        }
 /// <summary>
 /// May I have a a command that revokes a ballot at the target?
 /// </summary>
 /// <param name="sender">The one sending the command.</param>
 /// <param name="cpr">The CPR-number to revoke a ballot for.</param>
 /// <param name="masterPassword">The masterpassword only the election secretary should know.</param>
 public RevokeBallotCPROnlyCommand(IPEndPoint sender, CPR cpr, string masterPassword)
 {
     Contract.Requires(sender != null);
     _cpr            = cpr;
     _masterPassword = masterPassword;
     Sender          = sender;
 }
Esempio n. 3
0
 /// <summary>
 /// May I have a new command that requests a ballot of the target?
 /// </summary>
 /// <param name="sender">The address of the one sending the command.</param>
 /// <param name="voternumber">The voternumber to request a ballot for.</param>
 /// <param name="cpr">The CPR-number to request a ballot for.</param>
 public RequestBallotCommand(IPEndPoint sender, VoterNumber voternumber, CPR cpr)
 {
     Contract.Requires(sender != null);
     Sender       = sender;
     _voternumber = voternumber;
     _cpr         = cpr;
 }
Esempio n. 4
0
        public static CPR CdmToCpr(CDM cdm)
        {
            var children = new List <string>();

            CPR cpr = new CPR()
            {
                //CprNo = "",
                EuccidNo  = cdm.EuccidNo,
                FirstName = cdm.ChristianName,
                Gender    = cdm.Gender,
                Surname   = cdm.FamilyName,
                Address1  = assembleCprAddress(cdm),
                //Address2 = "",
                PostalCode = cdm.PostalCode,
                City       = cdm.City,
                //MaritalStatus = "",
                //Spouse = "",
                Children = children,
                //Father = "",
                //Mother = "",
                //DoctorCVR = "",
            };

            return(cpr);
        }
        public void RequestBallotCommandsTest()
        {
            var ui      = (TestUi)Manager.UI;
            var vn      = new VoterNumber(250000);
            var cpr     = new CPR(2312881234);
            var cmd     = new RequestBallotCommand(Station.Address, vn, cpr);
            var pswdcmd = new RequestBallotCPROnlyCommand(Station.Address, cpr, "yo boii");
            var data    = new List <EncryptedVoterData> {
                new EncryptedVoterData(new CipherText(Station.Crypto.AsymmetricEncrypt(Bytes.From(vn.Value), Station.Crypto.VoterDataEncryptionKey)), new CipherText(Station.Crypto.AsymmetricEncrypt(Bytes.From(cpr.Value), Station.Crypto.VoterDataEncryptionKey)), new CipherText(Station.Crypto.AsymmetricEncrypt(Bytes.From(cpr.Value + (uint)BallotStatus.NotReceived), Station.Crypto.VoterDataEncryptionKey)))
            };

            Manager.Database.Import(data);
            Station.Database.Import(data);
            Station.MasterPassword = Manager.MasterPassword;
            Manager.BallotReceived(vn, cpr);
            cmd.Execute(Manager);
            Assert.That(!ui.HandOutBallot);
            pswdcmd.Execute(Manager);
            Assert.That(!ui.HandOutBallot);

            Manager.RevokeBallot(vn, cpr);

            cmd     = new RequestBallotCommand(Manager.Address, vn, cpr);
            pswdcmd = new RequestBallotCPROnlyCommand(Manager.Address, cpr, "yo boii");
            cmd.Execute(Manager);
            Assert.That(ui.HandOutBallot);
            Manager.RevokeBallot(vn, cpr);
            pswdcmd.Execute(Manager);
            Assert.That(ui.HandOutBallot);
        }
 public BallotStatus this[VoterNumber voternumber, CPR cpr] {
     get {
         var voter = GetVoter(cpr);
         if (voter == null)
         {
             return(BallotStatus.Unavailable);
         }
         var encVn = Parent.Crypto.AsymmetricEncrypt(Bytes.From(voternumber.Value), Parent.Crypto.VoterDataEncryptionKey);
         if (!voter.VoterNumber.IsIdenticalTo(encVn))
         {
             return(BallotStatus.Unavailable);
         }
         var encBallotReceived = Parent.Crypto.AsymmetricEncrypt(Bytes.From((uint)BallotStatus.Received), Parent.Crypto.VoterDataEncryptionKey);
         return(voter.BallotStatus.IsIdenticalTo(encBallotReceived) ? BallotStatus.Received : BallotStatus.NotReceived);
     }
     set {
         if (Parent.Logger != null)
         {
             Parent.Logger.Log("Setting ballotstatus for voternumber=" + voternumber + "; CPR=" + cpr + " to " + value, Level.Info);
         }
         var voter = GetVoter(cpr);
         voter.BallotStatus = Parent.Crypto.AsymmetricEncrypt(Bytes.From((uint)value), Parent.Crypto.VoterDataEncryptionKey);
         _db.SaveChanges();
     }
 }
        public void CPRTest()
        {
            var cpr = new CPR(2312881133);

            Assert.That(cpr.Value == 2312881133);
            Assert.That(cpr.ToString().Equals("2312881133"));
            Assert.That(2312881133.Equals(cpr));
        }
        private Voter GetVoter(CPR cpr)
        {
            var encCpr = Parent.Crypto.AsymmetricEncrypt(Bytes.From(cpr.Value), Parent.Crypto.VoterDataEncryptionKey);

            var res = _db.Voters.Where(data => data.CPR == encCpr.Value);

            return(!res.Any() ? null : res.Single());
        }
 /// <summary>
 /// May I have a new command that requests a ballot at the target?
 /// </summary>
 /// <param name="sender">The address of the one sending the command.</param>
 /// <param name="cpr">The CPR-number to request a ballot for.</param>
 /// <param name="password">The master-password that only the election secretary should know.</param>
 public RequestBallotCPROnlyCommand(IPEndPoint sender, CPR cpr, string password)
 {
     Contract.Requires(sender != null);
     Contract.Requires(password != null);
     _cpr      = cpr;
     _password = password;
     Sender    = sender;
 }
Esempio n. 10
0
 /// <summary>
 /// Request a ballot for this voter!
 /// </summary>
 /// <param name="voterNumber">The voternumber to request a ballot for.</param>
 /// <param name="cpr">The CPR number to request a ballot for.</param>
 public void RequestBallot(VoterNumber voterNumber, CPR cpr)
 {
     Contract.Requires(Database[voterNumber, cpr] == BallotStatus.NotReceived);
     Communicator.Send(new RequestBallotCommand(Address, voterNumber, cpr), Manager);
     if (Logger != null)
     {
         Logger.Log("Requesting ballot for: voternumber=" + voterNumber + "; CPR=" + cpr, Level.Info);
     }
 }
Esempio n. 11
0
        /// <summary>
        /// May I have a new command that tells the target that a ballot should be handed out and be marked as received?
        /// </summary>
        /// <param name="sender">The address of the one sending the command.</param>
        /// <param name="requester">The address of the station who initially requested the ballot.</param>
        /// <param name="voterNumber">The voternumber of the ballot to be handed out and to be marked as received.</param>
        /// <param name="cpr">The CPR-number of the ballot to be handed out and to be marked as received.</param>
        public BallotReceivedCommand(IPEndPoint sender, IPEndPoint requester, VoterNumber voterNumber, CPR cpr)
        {
            Contract.Requires(sender != null);
            Contract.Requires(requester != null);

            _requester   = requester;
            _voterNumber = voterNumber;
            _cpr         = cpr;
            Sender       = sender;
        }
Esempio n. 12
0
 /// <summary>
 /// Revoke this ballot!
 /// </summary>
 /// <param name="voterNumber">The voternumber to revoke a ballot for.</param>
 /// <param name="cpr">The CPR number to revoke a ballot for.</param>
 public void RevokeBallot(VoterNumber voterNumber, CPR cpr)
 {
     Contract.Requires(Database[voterNumber, cpr] == BallotStatus.Received);
     Contract.Ensures(Database[voterNumber, cpr] == BallotStatus.NotReceived);
     Database[voterNumber, cpr] = BallotStatus.NotReceived;
     if (Logger != null)
     {
         Logger.Log("Revoking ballot for voter with voternumber=" + voterNumber + "; CPR=" + cpr, Level.Warn);
     }
 }
Esempio n. 13
0
 /// <summary>
 /// This voter received a ballot!
 /// </summary>
 /// <param name="voterNumber">The voternumber to request a ballot for.</param>
 /// <param name="cpr">The CPR number to request a ballot for.</param>
 public void BallotReceived(VoterNumber voterNumber, CPR cpr)
 {
     Contract.Requires(Database[voterNumber, cpr] == BallotStatus.NotReceived);
     Contract.Ensures(Database[voterNumber, cpr] == BallotStatus.Received);
     Database[voterNumber, cpr] = BallotStatus.Received;
     if (Logger != null)
     {
         Logger.Log("Marking voternumber=" + voterNumber + "; CPR=" + cpr + " as having received a ballot.", Level.Info);
     }
 }
Esempio n. 14
0
 /// <summary>
 /// Request a ballot for this voter!
 /// </summary>
 /// <param name="cpr">The CPR number to request a ballot for.</param>
 /// <param name="password">The masterpassword.</param>
 public void RequestBallot(CPR cpr, string password)
 {
     Contract.Requires(password != null);
     Contract.Requires(ValidMasterPassword(password));
     Contract.Requires(Database[cpr, password] == BallotStatus.NotReceived);
     Communicator.Send(new RequestBallotCPROnlyCommand(Address, cpr, password), Manager);
     if (Logger != null)
     {
         Logger.Log("Requesting ballot with masterpassword for: CPR=" + cpr, Level.Info);
     }
 }
        /// <summary>
        /// May I have a new command that requests a ballot with just the CPR number and masterpassword known?
        /// </summary>
        /// <param name="sender">The address of the one sending the command.</param>
        /// <param name="requester">The address of the station requesting the command.</param>
        /// <param name="cpr">The CPR-number of the ballot being requested.</param>
        /// <param name="password">The masterpassword for the election, that only the election secretary should know.</param>
        public BallotReceivedCPROnlyCommand(IPEndPoint sender, IPEndPoint requester, CPR cpr, string password)
        {
            Contract.Requires(sender != null);
            Contract.Requires(requester != null);
            Contract.Requires(password != null);

            _requester = requester;
            _cpr       = cpr;
            _password  = password;
            Sender     = sender;
        }
Esempio n. 16
0
 public void AdmitPatientToRoom(DeliveryRoom room)
 {
     if (!room.PatientsInRoom.Contains(this))
     {
         room.PatientsInRoom.Add(this);
     }
     else
     {
         throw new ArgumentException(Name + " with CPR:" + CPR.ToString() + " is already in room:" + room.RoomID.ToString());
     }
 }
Esempio n. 17
0
 public void DischargePatientFromRoom(DeliveryRoom room)
 {
     if (room.PatientsInRoom.Contains(this))
     {
         room.PatientsInRoom.Remove(this);
     }
     else
     {
         throw new ArgumentException(Name + " with CPR:" + CPR.ToString() + " is NOT in room:" + room.RoomID.ToString());
     }
 }
Esempio n. 18
0
 /// <summary>
 /// Revoke this ballot!
 /// </summary>
 /// <param name="cpr">The CPR number to revoke a ballot for.</param>
 /// <param name="masterPassword">The masterpassword that only the election secretary should know.</param>
 public void RevokeBallot(CPR cpr, string masterPassword)
 {
     Contract.Requires(masterPassword != null);
     Contract.Requires(ValidMasterPassword(masterPassword));
     Contract.Requires(Database[cpr, masterPassword] == BallotStatus.Received);
     Contract.Ensures(Database[cpr, masterPassword] == BallotStatus.NotReceived);
     Database[cpr, masterPassword] = BallotStatus.NotReceived;
     if (Logger != null)
     {
         Logger.Log("Revoking ballot with masterpassword for voter with CPR=" + cpr, Level.Warn);
     }
 }
Esempio n. 19
0
 /// <summary>
 /// This voter received a ballot!
 /// </summary>
 /// <param name="cpr">The CPR number to request a ballot for.</param>
 /// <param name="password">The masterpassword.</param>
 public void BallotReceived(CPR cpr, string password)
 {
     Contract.Requires(password != null);
     Contract.Requires(ValidMasterPassword(password));
     Contract.Requires(Database[cpr, password] == BallotStatus.NotReceived);
     Contract.Ensures(Database[cpr, password] == BallotStatus.Received);
     Database[cpr, password] = BallotStatus.Received;
     if (Logger != null)
     {
         Logger.Log("Marking CPR=" + cpr + " with masterpassword as having received a ballot.", Level.Info);
     }
 }
Esempio n. 20
0
        private void button2_Click(object sender, EventArgs e)
        {
            double temperature = hScrollBar1.Value + 215;
            double speed = hScrollBar2.Value * 10.0;
            double pressure = vScrollBar3.Value;
            double throttle = 100.0 - vScrollBar2.Value;
            
            status_string = "Temperature:\t" + temperature.ToString() + " K\r\n"
                + "Throttle:\t\t" + throttle.ToString() + " %\r\n"
                + "Pressure:\t\t" + pressure.ToString() + " Kpa\r\n"
                + "Speed:\t\t" + speed.ToString() + " m/s\r\n";

            status_string += "\r\n\r\n";
            status_string += "\tMODULE\r\n";
            status_string += "\t{\r\n";
            status_string += "\t\tname = AJEModule\r\n";
            status_string += "\t\tArea = " + Area.ToString() + "\r\n";
            status_string += "\t\tBPR = " + BPR.ToString() + "\r\n";
            status_string += "\t\tCPR = " + CPR.ToString() + "\r\n";
            status_string += "\t\tFPR = " + FPR.ToString() + "\r\n";
            status_string += "\t\tMdes = " + Mach_D.ToString() + "\r\n";
            status_string += "\t\tTdes = " + Temp_D.ToString() + "\r\n";
            status_string += "\t\teta_c = " + eta_c.ToString() + "\r\n";
            status_string += "\t\teta_t = " + eta_t.ToString() + "\r\n";
            status_string += "\t\teta_n = " + eta_n.ToString() + "\r\n";
            status_string += "\t\tFHV = " + FHV.ToString() + "\r\n";
            status_string += "\t\tTIT = " + TIT.ToString() + "\r\n";
            status_string += "\t\tTAB = " + TAB.ToString() + "\r\n";
            status_string += "\t\texhaustMixer = " + checkBox1.Checked.ToString() + "\r\n";
            status_string += "\t\tmaxThrust = 999999\r\n";
            status_string += "\t\tmaxT3 = 9999\r\n";
            status_string += "\t}\r\n\r\n\r\n";

            aje.InitializeOverallEngineData(
                Area,
                TPR,
                BPR,
                CPR,
                FPR,
                Mach_D,
                Temp_D,
                eta_c,
                eta_t,
                eta_n,
                FHV,
                TIT,
                TAB,
                checkBox1.Checked
            );
            aje.CalculatePerformance(pressure, temperature, speed, throttle/100);
            result_string = aje.debugstring;
        }
 public EUCCID CprToEuccid(CPR cpr)
 {
     return(new EUCCID()
     {
         ChristianName = cpr.FirstName,
         FamilyName = cpr.Surname,
         ApartmentNumber = GetApartmentNumberFromCprAddress(cpr.Address1),
         StreetHouseNumber = GetAddressWithouthAppartmentNumber(cpr.Address1),
         City = cpr.City,
         EuCcid = GetEuccidNumberBeginning(cpr.CprNumber),
         Gender = GetGenderFromCprNumber(cpr.CprNumber)
     });
 }
Esempio n. 22
0
        //Method related to announcing changes regarding ballot-statuses.
        #region Ballots
        /// <summary>
        /// Announce to all that they should revoke this update!
        /// </summary>
        /// <param name="voterNumber">The voternumber to revoke a ballot for.</param>
        /// <param name="cpr">The CPR number to revoke a ballot for.</param>
        public void AnnounceRevokeBallot(VoterNumber voterNumber, CPR cpr)
        {
            Contract.Requires(IsManager);
            Contract.Requires(Database[voterNumber, cpr] == BallotStatus.Received);
            var cmd = new RevokeBallotCommand(Address, voterNumber, cpr);

            Peers.Keys.ForEach(peer => Communicator.Send(cmd, peer));
            cmd.Execute(this);
            if (Logger != null)
            {
                Logger.Log("Announcing that this ballot should be revoked: voternumber=" + voterNumber + "; CPR=" + cpr, Level.Warn);
            }
        }
Esempio n. 23
0
        /// <summary>
        /// This method is called when an election offical wants to mark a voter by only using their CPR number.
        /// The election official will also need to enter the master password.
        /// </summary>
        /// <param name="cpr">the CPR number of the voter</param>
        /// <param name="masterPassword">the systems master password</param>
        public void RequestBallotOnlyCPR(string cpr, string masterPassword)
        {
            var ncpr = new CPR(uint.Parse(cpr));

            if (_station.Database[ncpr, masterPassword] == BallotStatus.NotReceived)
            {
                _station.RequestBallot(ncpr, masterPassword);
            }
            else
            {
                BallotRequestReply(false);
            }
        }
Esempio n. 24
0
        public void RequestBallotAndAnnounceBallotReceivedAndRevokedTest()
        {
            var vn  = new VoterNumber(250000);
            var cpr = new CPR(2312881234);

            Assert.That(Peer1.Database[vn, cpr] == BallotStatus.Unavailable);
            Assert.That(Peer2.Database[vn, cpr] == BallotStatus.Unavailable);
            Assert.That(Peer3.Database[vn, cpr] == BallotStatus.Unavailable);
            Assert.That(Manager.Database[vn, cpr] == BallotStatus.Unavailable);
            var data = new List <EncryptedVoterData> {
                new EncryptedVoterData(new CipherText(Peer1.Crypto.AsymmetricEncrypt(Bytes.From(vn.Value), Peer1.Crypto.VoterDataEncryptionKey)), new CipherText(Peer1.Crypto.AsymmetricEncrypt(Bytes.From(cpr.Value), Peer1.Crypto.VoterDataEncryptionKey)), new CipherText(Peer1.Crypto.AsymmetricEncrypt(Bytes.From(cpr.Value + (uint)BallotStatus.NotReceived), Peer1.Crypto.VoterDataEncryptionKey)))
            };

            Peer1.Database.Import(data);
            Peer2.Database.Import(data);
            Peer3.Database.Import(data);
            Manager.Database.Import(data);


            Assert.That(Peer1.Database[vn, cpr] == BallotStatus.NotReceived);
            Assert.That(Peer2.Database[vn, cpr] == BallotStatus.NotReceived);
            Assert.That(Peer3.Database[vn, cpr] == BallotStatus.NotReceived);
            Assert.That(Manager.Database[vn, cpr] == BallotStatus.NotReceived);
            var managerListenerResult = ManagerListener.BeginInvoke(null, null);

            AsyncManagerAnnounce(() => Peer1.RequestBallot(vn, cpr));
            ManagerListener.EndInvoke(managerListenerResult);
            Assert.That(Peer1.Database[vn, cpr] == BallotStatus.Received);
            Assert.That(Peer2.Database[vn, cpr] == BallotStatus.Received);
            Assert.That(Peer3.Database[vn, cpr] == BallotStatus.Received);
            Assert.That(Manager.Database[vn, cpr] == BallotStatus.Received);
            AsyncManagerAnnounce(() => Manager.AnnounceRevokeBallot(vn, cpr));
            Assert.That(Peer1.Database[vn, cpr] == BallotStatus.NotReceived);
            Assert.That(Peer2.Database[vn, cpr] == BallotStatus.NotReceived);
            Assert.That(Peer3.Database[vn, cpr] == BallotStatus.NotReceived);
            Assert.That(Manager.Database[vn, cpr] == BallotStatus.NotReceived);

            managerListenerResult = ManagerListener.BeginInvoke(null, null);
            AsyncManagerAnnounce(() => Peer1.RequestBallot(cpr, "yo boii"));
            ManagerListener.EndInvoke(managerListenerResult);
            Assert.That(Peer1.Database[vn, cpr] == BallotStatus.Received);
            Assert.That(Peer2.Database[vn, cpr] == BallotStatus.Received);
            Assert.That(Peer3.Database[vn, cpr] == BallotStatus.Received);
            Assert.That(Manager.Database[vn, cpr] == BallotStatus.Received);

            AsyncManagerAnnounce(() => Manager.AnnounceRevokeBallot(cpr, "yo boii"));
            Assert.That(Peer1.Database[vn, cpr] == BallotStatus.NotReceived);
            Assert.That(Peer2.Database[vn, cpr] == BallotStatus.NotReceived);
            Assert.That(Peer3.Database[vn, cpr] == BallotStatus.NotReceived);
            Assert.That(Manager.Database[vn, cpr] == BallotStatus.NotReceived);
        }
Esempio n. 25
0
        /// <summary>
        /// This method is called when a voter wants to request a ballot after entering their voternumber and CPR number
        /// </summary>
        /// <param name="voterNumber">the voternumber of the voter</param>
        /// <param name="cpr">the CPR number of the voter</param>
        public void RequestBallot(string voterNumber, string cpr)
        {
            var vn   = new VoterNumber(uint.Parse(voterNumber));
            var ncpr = new CPR(uint.Parse(cpr));

            if (_station.Database[vn, ncpr] == BallotStatus.NotReceived)
            {
                _station.RequestBallot(vn, ncpr);
            }
            else
            {
                BallotRequestReply(false);
            }
        }
Esempio n. 26
0
        /// <summary>
        /// Announce to all that they should revoke this update!
        /// </summary>
        /// <param name="cpr">The CPR number to revoke a ballot for.</param>
        /// <param name="masterPassword">The masterpassword that only the election secretary should know.</param>
        public void AnnounceRevokeBallot(CPR cpr, string masterPassword)
        {
            Contract.Requires(masterPassword != null);
            Contract.Requires(ValidMasterPassword(masterPassword));
            Contract.Requires(Database[cpr, masterPassword] == BallotStatus.Received);
            Contract.Requires(IsManager);
            var cmd = new RevokeBallotCPROnlyCommand(Address, cpr, masterPassword);

            Peers.Keys.ForEach(peer => Communicator.Send(cmd, peer));
            cmd.Execute(this);
            if (Logger != null)
            {
                Logger.Log("Announcing that this ballot should be revoked with masterpassword: CPR=" + cpr, Level.Warn);
            }
        }
Esempio n. 27
0
 public BallotStatus this[VoterNumber voternumber, CPR cpr] {
     get {
         return(default(BallotStatus));
     }
     set {
         //You can't set a ballot as unavailable. If it's in the DB, it's either received or not received.
         Contract.Requires(value != BallotStatus.Unavailable);
         //When you're setting a value, it must be in the DB
         Contract.Requires(this[voternumber, cpr] != BallotStatus.Unavailable);
         //You can only hand out or revoke ballots if they have the opposite state
         //If it's not handed out, you can hand it out
         Contract.Requires(value != BallotStatus.Received || this[voternumber, cpr] == BallotStatus.NotReceived);
         //If it's handed out, you can revoke it.
         Contract.Requires(value != BallotStatus.NotReceived || this[voternumber, cpr] == BallotStatus.Received);
         Contract.Ensures(this[voternumber, cpr] == value);
     }
 }
 public BallotStatus this[CPR cpr, string masterPassword] {
     get {
         var encBallotReceived = Parent.Crypto.AsymmetricEncrypt(Bytes.From((uint)BallotStatus.Received), Parent.Crypto.VoterDataEncryptionKey);
         var voter             = GetVoter(cpr);
         if (voter == null)
         {
             return(BallotStatus.Unavailable);
         }
         return(voter.BallotStatus.IsIdenticalTo(encBallotReceived) ? BallotStatus.Received : BallotStatus.NotReceived);
     }
     set {
         if (Parent.Logger != null)
         {
             Parent.Logger.Log("Setting ballotstatus for CPR=" + cpr + " with masterpassword to " + value, Level.Info);
         }
         var voter = GetVoter(cpr);
         voter.BallotStatus = Parent.Crypto.AsymmetricEncrypt(Bytes.From((uint)value), Parent.Crypto.VoterDataEncryptionKey);
         _db.SaveChanges();
     }
 }
Esempio n. 29
0
        public BallotStatus this[CPR cpr, string masterPassword] {
            get {
                Contract.Requires(masterPassword != null);
                Contract.Requires(Parent.ValidMasterPassword(masterPassword));
                return(default(BallotStatus));
            }
            set {
                Contract.Requires(Parent.ValidMasterPassword(masterPassword));

                //You can't set a ballot as unavailable. If it's in the DB, it's either received or not received.
                Contract.Requires(value != BallotStatus.Unavailable);
                //When you're setting a value, it must be in the DB
                Contract.Requires(this[cpr, masterPassword] != BallotStatus.Unavailable);
                //You can only hand out or revoke ballots if they have the opposite state
                //If it's not handed out, you can hand it out
                Contract.Requires(value != BallotStatus.Received || this[cpr, masterPassword] == BallotStatus.NotReceived);
                //If it's handed out, you can revoke it.
                Contract.Requires(value != BallotStatus.NotReceived || this[cpr, masterPassword] == BallotStatus.Received);
                Contract.Ensures(this[cpr, masterPassword] == value);
            }
        }
Esempio n. 30
0
        public static CDM CprToCdm(CPR cpr)
        {
            CprAddress cprAddress = splitCprAddress(cpr.Address1);

            CDM cdm = new CDM()
            {
                EuccidNo      = cpr.EuccidNo,
                ChristianName = cpr.FirstName,
                FamilyName    = cpr.Surname,
                Gender        = cpr.Gender,
                Street        = cprAddress.street,
                HouseNo       = cprAddress.houseNo,
                ApartmentNo   = cprAddress.apartmentNo,
                //County = "",
                PostalCode = cpr.PostalCode,
                City       = cpr.City,
                //BirthCountry = "",
                CountryOfResidence = "Denmark"
            };

            return(cdm);
        }