1 package civitas.crypto.oneoflreencryption.tests;
2
3 import static org.junit.jupiter.api.Assertions.assertEquals;
4 import static org.junit.jupiter.api.Assertions.assertNull;
5
6 import org.junit.jupiter.api.DisplayName;
7 import org.junit.jupiter.api.Test;
8 import org.mockito.InjectMocks;
9
10 import civitas.crypto.ciphertextlist.tests.ElGamalCiphertextListTestData;
11 import civitas.crypto.oneoflreencryption.ConstructElGamal1OfLReencryption;
12 import civitas.crypto.oneoflreencryption.ElGamal1OfLReencryption;
13 import civitas.crypto.reencryptfactor.tests.ElGamalReencryptFactorTestData;
14 import io.github.magwas.konveyor.testing.TestBase;
15
16 class ConstructElGamal1OfLReencryptionTest extends TestBase
17 implements ElGamal1OfLReencryptionTestData, ElGamalCiphertextListTestData, ElGamalReencryptFactorTestData {
18
19 @InjectMocks
20 ConstructElGamal1OfLReencryption constructElGamal1OfLReencryption;
21
22 @Test
23 @DisplayName("constructs an encrypted choice," + "containing the reencryption of the choosen vote and its proof ")
24 void test() {
25 ElGamal1OfLReencryption encChoice = constructElGamal1OfLReencryption.apply(
26 EL_GAMAL_PUBLIC_KEY_E, CIPHERTEXT_LIST, MY_CHOICE.ordinal(), ELGAMAL_REENCRYPT_FACTOR_E);
27 assertEquals(EL_GAMAL_PROOF_1_OF_L, encChoice.proof());
28 assertEquals(REENCRYPTED_WELL_KNOWN_CHOICE, encChoice.m());
29 }
30
31 @Test
32 @DisplayName("if choice > number of ciphertexts, a null is returned")
33 void test1() {
34 ElGamal1OfLReencryption encChoice = constructElGamal1OfLReencryption.apply(
35 EL_GAMAL_PUBLIC_KEY_E, CIPHERTEXT_LIST, CIPHERTEXT_LIST.size(), ELGAMAL_REENCRYPT_FACTOR_E);
36 assertNull(encChoice);
37 }
38
39 @Test
40 @DisplayName("if ciphertexts is null, a null is returned")
41 void test2() {
42 ElGamal1OfLReencryption encChoice = constructElGamal1OfLReencryption.apply(
43 EL_GAMAL_PUBLIC_KEY_E, null, MY_CHOICE.ordinal(), ELGAMAL_REENCRYPT_FACTOR_E);
44 assertNull(encChoice);
45 }
46 }