View Javadoc
1   package civitas.common.mix.elementrevelation;
2   
3   import org.springframework.beans.factory.annotation.Autowired;
4   import org.springframework.stereotype.Controller;
5   
6   import civitas.common.mix.VoterMix;
7   import civitas.common.mix.capabilityelementrevelation.MixCapabilityElementRevelation;
8   import civitas.common.mix.capabilityelementrevelation.VerifyMixCapabilityElementRevelation;
9   import civitas.common.mix.capabilitymix.CapabilityMix;
10  import civitas.common.mix.voteelementrevelation.MixVoteElementRevelation;
11  import civitas.common.mix.voteelementrevelation.VerifyMixVoteElementRevelation;
12  import civitas.crypto.ciphertext.ElGamalReencrypt;
13  import civitas.crypto.publickey.ElGamalPublicKey;
14  import jakarta.annotation.Nonnull;
15  
16  @Controller
17  public class VerifyMixElementRevelation {
18  
19  	@Autowired
20  	ElGamalReencrypt elGamalReencrypt;
21  
22  	@Autowired
23  	VerifyMixCapabilityElementRevelation verifyMixCapabilityElementRevelation;
24  
25  	@Autowired
26  	VerifyMixVoteElementRevelation verifyMixVoteElementRevelation;
27  
28  	public boolean apply(
29  			@Nonnull final MixElementRevelation that,
30  			@Nonnull final ElGamalPublicKey key,
31  			final int fromIndex,
32  			final int toIndex,
33  			@Nonnull final VoterMix fromMix,
34  			@Nonnull final VoterMix toMix) {
35  		if (key == null || fromMix == null || toMix == null) {
36  			throw new NullPointerException();
37  		}
38  		if (that.getClass().equals(MixCapabilityElementRevelation.class)) {
39  			return verifyMixCapabilityElementRevelation.apply(
40  					(MixCapabilityElementRevelation) that,
41  					key,
42  					fromIndex,
43  					toIndex,
44  					(CapabilityMix) fromMix,
45  					(CapabilityMix) toMix);
46  		}
47  		if (that.getClass().equals(MixVoteElementRevelation.class)) {
48  			return verifyMixVoteElementRevelation.apply(
49  					(MixVoteElementRevelation) that, key, fromIndex, toIndex, fromMix, toMix);
50  		}
51  		throw new IllegalArgumentException("I do not know this type of revelation");
52  	}
53  }