def get_hamilton_election_from_file(self) -> ElectionDescription:
        with open(
                os.path.join(data, "hamilton-county",
                             "election_manifest.json"), "r") as subject:
            result = subject.read()
            target = ElectionDescription.from_json(result)

        return target
    def test_simple_election_can_serialize(self):
        # Arrange
        subject = election_factory.get_simple_election_from_file()
        intermediate = subject.to_json()

        # Act
        result = ElectionDescription.from_json(intermediate)

        # Assert
        self.assertIsNotNone(result.election_scope_id)
        self.assertEqual(result.election_scope_id, "jefferson-county-primary")
Beispiel #3
0
    def setupElectionBuilder(self):
        # Create an election builder instance, and configure it for a single public-private keypair.
        # in a real election, you would configure this for a group of guardians.  See Key Ceremony for more information.
        with open(os.path.join(self.manifest_path, self.manifest_file),
                  "r") as manifest:
            string_representation = manifest.read()
            election_description = ElectionDescription.from_json(
                string_representation)

        builder = ElectionBuilder(
            number_of_guardians=self.
            NUMBER_OF_GUARDIANS,  # since we will generate a single public-private keypair, we set this to 1
            quorum=self.
            QUORUM,  # since we will generate a single public-private keypair, we set this to 1
            description=election_description)

        builder.set_public_key(self.joint_public_key)
        self.metadata, self.context = get_optional(builder.build())
        self.builder = builder
def create() -> Tuple:
    """
    An election with only one guardian and random keys gets generated.
    More configuration options and the ability to hold a key ceremony should be added later.
    """
    # Open an election manifest file
    with open(os.path.join(ELECTION_MANIFEST), "r") as manifest:
        string_representation = manifest.read()
        election_description = ElectionDescription.from_json(
            string_representation)

    # Create an election builder instance, and configure it for a single public-private keypair.
    # in a real election, you would configure this for a group of guardians.  See Key Ceremony for more information.
    # TODO: Allow real key ceremony
    builder = ElectionBuilder(
        number_of_guardians=
        1,  # since we will generate a single public-private keypair, we set this to 1
        quorum=
        1,  # since we will generate a single public-private keypair, we set this to 1
        description=election_description)

    # We simply generate a random keypair. For a real election this step should
    # be replaced by the key ceremony
    keypair = elgamal_keypair_random()

    builder.set_public_key(keypair.public_key)

    # get an `InternalElectionDescription` and `CiphertextElectionContext`
    # that are used for the remainder of the election.
    (metadata, context) = builder.build()

    # Configure an encryption device
    # In the docs the encrypter device gets defined when encrypting a ballot.
    # I think for our usecase it makes more sense to define one encrypter and use for the whole election
    device = EncryptionDevice("polling-place-one")
    encrypter = EncryptionMediator(metadata, context, device)

    store = BallotStore()
    ballot_box = BallotBox(metadata, context, store)

    return metadata, context, encrypter, ballot_box, store, keypair
    def _get_election_from_file(self, filename: str) -> ElectionDescription:
        with open(os.path.join(data, filename), "r") as subject:
            result = subject.read()
            target = ElectionDescription.from_json(result)

        return target