ch.openchvote.electionauthority.writein.states.S100 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.states;
import ch.openchvote.electionauthority.ElectionAuthority;
import ch.openchvote.electionauthority.writein.EventContext;
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.CommunicationException;
import ch.openchvote.framework.party.State;
import ch.openchvote.framework.protocol.Protocol;
import ch.openchvote.protocol.phases.Initialization;
import ch.openchvote.protocol.protocols.writein.content.message.MAE1;
import static ch.openchvote.framework.exceptions.CommunicationException.Type.INCONSISTENT_EVENT_SETUP;
@SuppressWarnings("MissingJavadoc")
@Phase(Initialization.class)
@Notify(Status.Type.READY)
public final class S100 extends State {
public S100(ElectionAuthority electionAuthority, EventContext eventContext) {
super(electionAuthority, eventContext);
this.registerMessageHandler(MAE1.class, this::handleMAE1);
}
private void handleMAE1(Message message) {
// decompose event context
var eventId = this.eventContext.getEventId();
var publicData = this.eventContext.getPublicData();
var protocolId = this.eventContext.getProtocolId();
var protocolVersion = Protocol.getPrintName(protocolId);
var securityLevel = this.eventContext.getSecurityLevel();
// get and check message content (no auxiliary data)
var MAE1 = this.party.getAndCheckContent(MAE1.class, message, null, securityLevel);
// check election setup consistency
if (!MAE1.get_ES().checkConsistency(eventId, protocolVersion, securityLevel)) {
throw new CommunicationException(INCONSISTENT_EVENT_SETUP, message);
}
// update public data
publicData.setContent(MAE1);
// update state
this.party.updateState(this.eventContext, S200.class);
}
}