1 package civitas.common.mix.votemix;
2
3 import org.springframework.beans.factory.annotation.Autowired;
4 import org.springframework.stereotype.Controller;
5
6 import civitas.common.EncryptedVote;
7 import civitas.crypto.ciphertext.ElGamalReencrypt;
8 import civitas.crypto.publickey.ElGamalPublicKey;
9 import civitas.crypto.reencryptfactor.ElGamalReencryptFactor;
10 import jakarta.annotation.Nonnull;
11
12 @Controller
13 public class GetReencryptedVoteFromMix {
14
15 @Autowired
16 ElGamalReencrypt elGamalReencrypt;
17
18 public EncryptedVote apply(
19 @Nonnull final VoteMix that,
20 final int i,
21 @Nonnull final ElGamalReencryptFactor choiceFactor,
22 @Nonnull final ElGamalReencryptFactor capabilityFactor,
23 @Nonnull final ElGamalPublicKey key) {
24 if (null == choiceFactor || null == capabilityFactor || null == key) {
25 throw new NullPointerException();
26 }
27 EncryptedVote v = that.votes[i];
28 return new EncryptedVote(
29 v.context(),
30 elGamalReencrypt.apply(key, v.encChoice(), choiceFactor),
31 elGamalReencrypt.apply(key, v.encCapability(), capabilityFactor));
32 }
33 }