All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ch.openchvote.electionauthority.writein.tasks.TE9 Maven / Gradle / Ivy

/*
 * Copyright (C) 2024 Berner Fachhochschule https://e-voting.bfh.ch
 *
 *  - This program is free software: you can redistribute it and/or modify                           -
 *  - it under the terms of the GNU Affero General Public License as published by                    -
 *  - the Free Software Foundation, either version 3 of the License, or                              -
 *  - (at your option) any later version.                                                            -
 *  -                                                                                                -
 *  - This program is distributed in the hope that it will be useful,                                -
 *  - but WITHOUT ANY WARRANTY; without even the implied warranty of                                 -
 *  - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                                   -
 *  - GNU General Public License for more details.                                                   -
 *  -                                                                                                -
 *  - You should have received a copy of the GNU Affero General Public License                       -
 *  - along with this program. If not, see .                           -
 */
package ch.openchvote.electionauthority.writein.tasks;

import ch.openchvote.algorithms.AlgorithmService;
import ch.openchvote.algorithms.protocols.common.algorithms.CheckConfirmation;
import ch.openchvote.algorithms.protocols.common.model.Confirmation;
import ch.openchvote.algorithms.protocols.common.model.Finalization;
import ch.openchvote.algorithms.protocols.writein.algorithms.GetVotingParameters;
import ch.openchvote.algorithms.protocols.writein.model.VotingParametersWriteIn;
import ch.openchvote.electionauthority.writein.PublicData;
import ch.openchvote.framework.exceptions.TaskException;
import ch.openchvote.protocol.parameters.SecurityParameters;
import ch.openchvote.utilities.tuples.Pair;

@SuppressWarnings("MissingJavadoc")
public final class TE9 {

    static public Pair
    run(int v, Confirmation gamma, PublicData publicData) {

        // get algorithm service
        var algorithmService = AlgorithmService.load();

        // select setup parameters
        var ES = publicData.get_ES().get();
        var SL = ES.get_SL();

        // get security parameters
        var securityParameters = new SecurityParameters(SL);

        // select election parameters
        var EP = publicData.get_EP().get();

        // select event data
        var bold_y_hat = publicData.get_bold_y_hat().get();
        var bold_z_hat = publicData.get_bold_z_hat().get();
        var C_j = publicData.get_C_j();
        var F_j = publicData.get_F_j();

        // perform task
        if (!algorithmService.run(CheckConfirmation.class, securityParameters, v, gamma, bold_y_hat, bold_z_hat)) {
            throw new TaskException(TaskException.Type.INVALID_CONFIRMATION, TE9.class);
        }
        var VP_v = algorithmService.run(GetVotingParameters.class, v, EP);
        if (!F_j.isPresent(v)) {
            throw new TaskException(TaskException.Type.MISSING_BALLOT, TE9.class);
        }
        var delta_j = F_j.get(v);
        if (C_j.isPresent(v)) {
            throw new TaskException(TaskException.Type.DUPLICATE_CONFIRMATION, TE9.class);
        }
        C_j.set(v, gamma);

        // return data
        return new Pair<>(VP_v, delta_j);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy