ch.openchvote.administrator.plain.states.S400 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of administrator Show documentation
Show all versions of administrator Show documentation
This module implements the 'administrator' party of the CHVote protocol.
/*
* 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.administrator.plain.states;
import ch.openchvote.administrator.Administrator;
import ch.openchvote.administrator.plain.EventContext;
import ch.openchvote.administrator.plain.states.error.A400;
import ch.openchvote.administrator.plain.states.error.B400;
import ch.openchvote.administrator.plain.tasks.T400;
import ch.openchvote.algorithms.AlgorithmException;
import ch.openchvote.framework.annotations.state.Notify;
import ch.openchvote.framework.annotations.state.Phase;
import ch.openchvote.framework.communication.Message;
import ch.openchvote.framework.communication.Status;
import ch.openchvote.framework.exceptions.TaskException;
import ch.openchvote.framework.party.State;
import ch.openchvote.protocol.protocols.plain.content.message.MEA1;
import ch.openchvote.protocol.protocols.plain.content.publication.PAT1;
import ch.openchvote.protocol.phases.Tallying;
import ch.openchvote.utilities.tuples.Pair;
@SuppressWarnings("MissingJavadoc")
@Phase(Tallying.class)
@Notify(Status.Type.READY)
public final class S400 extends State {
public S400(Administrator administrator, EventContext eventContext) {
super(administrator, eventContext);
this.registerMessageHandler(MEA1.class, this::handleMEA1);
}
private void handleMEA1(Message message) {
// decompose event context
var eventId = this.eventContext.getEventId();
var publicData = this.eventContext.getPublicData();
var secretData = this.eventContext.getSecretData();
var securityLevel = this.eventContext.getSecurityLevel();
// select setup parameters
var ES = publicData.get_ES().get();
var j = ES.get_SP().getIndexOf(message.getSenderId());
// select election parameters
var EP = publicData.get_EP().get();
// get and check message content
var aux = new Pair<>(ES, EP);
var MEA1 = this.party.getAndCheckContent(MEA1.class, message, aux, securityLevel);
// update public data
publicData.setContent(j, MEA1);
// check if all MEA1 messages are available
if (T400.isReady(publicData)) {
try {
// perform task
T400.run(publicData, secretData);
// select event data
var ER = publicData.get_ER().get();
// publish PAT1 (no auxiliary data)
this.party.sendPublication(eventId, new PAT1(ES, EP, ER), null, securityLevel);
// update state
this.party.updateState(this.eventContext, S500.class);
} catch (AlgorithmException exception) {
// move to error state
this.party.updateState(this.eventContext, A400.class);
} catch (TaskException exception) {
// move to error state
this.party.updateState(this.eventContext, B400.class);
}
}
}
}