ch.openchvote.electionauthority.plain.states.S600 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.plain.states;
import ch.openchvote.algorithms.Algorithm;
import ch.openchvote.electionauthority.ElectionAuthority;
import ch.openchvote.electionauthority.plain.EventContext;
import ch.openchvote.electionauthority.plain.tasks.TE16;
import ch.openchvote.framework.annotations.state.Notify;
import ch.openchvote.framework.annotations.state.Phase;
import ch.openchvote.framework.communication.Request;
import ch.openchvote.framework.communication.Status;
import ch.openchvote.framework.exceptions.CommunicationException;
import ch.openchvote.framework.party.State;
import ch.openchvote.protocol.phases.Inspection;
import ch.openchvote.protocol.protocols.plain.content.requestresponse.request.RIE1;
import ch.openchvote.protocol.protocols.plain.content.requestresponse.response.REI1;
import ch.openchvote.utilities.tuples.Pair;
import static ch.openchvote.framework.exceptions.CommunicationException.Type.INVALID_CONTENT;
@SuppressWarnings("MissingJavadoc")
@Phase(Inspection.class)
@Notify(Status.Type.READY)
public final class S600 extends State {
public S600(ElectionAuthority electionAuthority, EventContext eventContext) {
super(electionAuthority, eventContext);
this.registerRequestHandler(RIE1.class, this::handleRIE1);
}
private void handleRIE1(Request request) {
// decompose event context
var eventId = this.eventContext.getEventId();
var publicData = this.eventContext.getPublicData();
var securityLevel = this.eventContext.getSecurityLevel();
// select setup parameters
var ES = publicData.get_ES().get();
// get request content
var RIE1 = this.party.getContent(RIE1.class, request);
var v = RIE1.get_v();
try {
// perform task
var pair = TE16.run(v, publicData);
var VP_v = pair.getFirst();
var I_j = pair.getSecond();
// send REI1 to inspection client
var aux = new Pair<>(ES, VP_v);
this.party.sendResponse(eventId, request.getRequestId(), request.getRequesterId(), new REI1(I_j), aux, securityLevel);
} catch (Algorithm.Exception exception) {
// discard request
throw new CommunicationException(INVALID_CONTENT, request, exception);
}
}
@Override
public void handleStop() {
// update state
this.party.updateState(this.eventContext, FINAL.class);
}
}