View Javadoc
1   package civitas.common.encryptedchoice;
2   
3   import static org.junit.jupiter.api.Assertions.assertEquals;
4   import static org.mockito.Mockito.verify;
5   
6   import org.junit.jupiter.api.DisplayName;
7   import org.junit.jupiter.api.Test;
8   import org.mockito.InjectMocks;
9   
10  import civitas.common.RandomAwareTestBase;
11  import civitas.common.ballot.BallotTestData;
12  import civitas.crypto.ciphertextlist.ElGamalCiphertextListTestData;
13  import civitas.crypto.oneoflreencryption.ElGamal1OfLReencryptionTestData;
14  
15  class EncryptChoiceTest extends RandomAwareTestBase
16  		implements ElGamalCiphertextListTestData, BallotTestData, ElGamal1OfLReencryptionTestData {
17  
18  	@InjectMocks
19  	EncryptChoice encryptChoice;
20  
21  	@DisplayName(
22  			"""
23  			encrypts the choice for the ballot
24  			- generates a random reencryption factor
25  			- constructs an 1 of L reeencryption using the choice in the ballot and the factor
26  			""")
27  	@Test
28  	void test() {
29  		EncryptedChoice actual = encryptChoice.apply(EL_GAMAL_PUBLIC_KEY_E, CIPHERTEXT_LIST, BALLOT.matrix, 0);
30  
31  		assertEquals(
32  				new EncryptedChoice(
33  						ELGAMAL_REENCRYPT_FACTOR_EPRIME, EL_GAMAL_1_OF_L_REENCRYPTION_MAP.get(BALLOT.matrix[0])),
34  				actual);
35  
36  		verify(encryptChoice.generateElGamalReencryptFactor).apply(EL_GAMAL_PARAMETERS);
37  		verify(encryptChoice.constructElGamal1OfLReencryption)
38  				.apply(
39  						EL_GAMAL_PUBLIC_KEY_E,
40  						CIPHERTEXT_LIST,
41  						BALLOT.matrix[0].ordinal(),
42  						ELGAMAL_REENCRYPT_FACTOR_EPRIME);
43  	}
44  }