Ejemplo n.º 1
0
        public void Test_Encrypt_Ballot_Simple_Succeeds()
        {
            // Configure the election context
            var keypair = ElGamalKeyPair.FromSecret(Constants.TWO_MOD_Q);
            var description = new Manifest(manifest_json);
            var manifest = new InternalManifest(description);
            var context = new CiphertextElectionContext(
                1UL, 1UL, keypair.PublicKey, Constants.TWO_MOD_Q, manifest.ManifestHash);
            var device = new EncryptionDevice(12345UL, 23456UL, 34567UL, "Location");
            var mediator = new EncryptionMediator(manifest, context, device);

            var ballot = new PlaintextBallot(plaintext_json);

            // Act
            var ciphertext = mediator.Encrypt(ballot);

            // Assert
            
            // a property
            Assert.That(ciphertext.ObjectId == ballot.ObjectId);

            // json serialization
            var json = ciphertext.Json;
            var fromJson = new CiphertextBallot(json);
            Assert.That(ciphertext.ObjectId == fromJson.ObjectId);

            // binary serialization
            var bson = ciphertext.Bson;
            var fromBson = CiphertextBallot.FromBson(bson);
            Assert.That(ciphertext.ObjectId == fromBson.ObjectId);

            // submitted ballot
            var submitted = SubmittedBallot.From(ciphertext, BallotBoxState.cast);
            Assert.That(ciphertext.ObjectId == submitted.ObjectId);
        }
Ejemplo n.º 2
0
        public void Test_Compact_Encrypt_Ballot_Simple_Succeeds()
        {
            var keypair     = ElGamalKeyPair.FromSecret(Constants.TWO_MOD_Q);
            var description = new Manifest(jsonManifest);
            var manifest    = new InternalManifest(description);
            var context     = new CiphertextElectionContext(1UL, 1UL, keypair.PublicKey, Constants.TWO_MOD_Q, manifest.ManifestHash);
            var device      = new EncryptionDevice(12345UL, 23456UL, 34567UL, "Location");
            var mediator    = new EncryptionMediator(manifest, context, device);

            var ballot = new PlaintextBallot(plaintext);

            // Act
            var compact = mediator.CompactEncrypt(ballot);

            // Assert
            Assert.That(compact.ObjectId == ballot.ObjectId);

            var msgpack     = compact.ToMsgPack();
            var fromMsgpack = new CompactCiphertextBallot(msgpack);

            Assert.That(compact.ObjectId == fromMsgpack.ObjectId);
        }