Skip to content

Commit c58b784

Browse files
authored
Fixed some sonar issues (#32)
* Fixed some sonar issues
1 parent 3066bc3 commit c58b784

File tree

78 files changed

+355
-570
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+355
-570
lines changed

civitas.base/src/main/java/civitas/common/CommonConstants.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,31 @@ public interface CommonConstants {
44

55
int ELECTION_ID_LENGTH = 32;
66

7-
String BoardClosedContentCommitmentMETA = "boardContents";
7+
String BOARD_CLOSED_CONTENT_COMMITMENT_META = "boardContents";
88

9-
String ElectionDetailsMETA = "electiondetails";
10-
String ElectionEventMETA = "electionevent";
11-
String CiphertextListMETA = "ciphertextList";
9+
String ELECTION_DETAILS_META = "electiondetails";
10+
String ELECTION_EVENT_META = "electionevent";
11+
String CIPHERTEXT_LIST_META = "ciphertextList";
1212

13-
String CondorcetBallotOPENING_TAG = "ballot";
14-
String BallotDesignOPENING_TAG = "ballotDesign";
15-
String VerifiableVoteOPENING_TAG = "verifiableVote";
16-
String TallyStateFinalOPENING_TAG = "tallyState";
13+
String CONDORCET_BALLOT_OPENING_TAG = "ballot";
14+
String BALLOT_DESIGN_OPENING_TAG = "ballotDesign";
15+
String VERIFIABLE_VOTE_OPENING_TAG = "verifiableVote";
16+
String TALLY_STATE_FINAL_OPENING_TAG = "tallyState";
1717

18-
String CapabilityMixMETA = "capabilityMix:";
19-
String ElectionResultsMETA = "electionResults:";
20-
String ElectoralRollCapabilitySharesMETA = "electoralRollCapShares";
21-
String mixConfirmMETA_PREFIX = "mixConfirm:";
22-
String mixConfirmMETA_VOTE_REVELATION = "vote";
23-
String mixConfirmMETA_ER_REVELATION = "elecRoll";
24-
String mixHashRevelationMETA_PREFIX = "mixHashRevelation:";
25-
String mixHashRevelationMETA_VOTE_REVELATION = "vote";
26-
String mixHashRevelationMETA_ER_REVELATION = "elecRoll";
27-
String VoteMixMETA = "voteMix:";
28-
String mixRevelationMETA_PREFIX = "mixRevelation:";
29-
String mixRevelationMETA_VOTE_REVELATION = "vote";
30-
String mixRevelationMETA_ER_REVELATION = "elecRoll";
18+
String ELEC_ROLL = "elecRoll";
19+
String CAPABILITY_MIX_META = "capabilityMix:";
20+
String ELECTION_RESULTS_META = "electionResults:";
21+
String ELECTORAL_ROLL_CAPABILITY_SHARES_META = "electoralRollCapShares";
22+
String MIX_CONFIRM_META_PREFIX = "mixConfirm:";
23+
String MIX_CONFIRM_META_VOTE_REVELATION = "vote";
24+
String MIX_CONFIRM_META_ER_REVELATION = ELEC_ROLL;
25+
String MIX_HASH_REVELATION_META_PREFIX = "mixHashRevelation:";
26+
String MIX_HASH_REVELATION_META_VOTE_REVELATION = "vote";
27+
String MIX_HASH_REVELATION_META_ER_REVELATION = ELEC_ROLL;
28+
String VOTE_MIX_META = "voteMix:";
29+
String MIX_REVELATION_META_PREFIX = "mixRevelation:";
30+
String MIX_REVELATION_META_VOTE_REVELATION = "vote";
31+
String MIX_REVELATION_META_ER_REVELATION = ELEC_ROLL;
3132

3233
String KIND = "condorcet";
3334
String NONE_OF_ABOVE = "none of the above";

civitas.base/src/main/java/civitas/crypto/Constants.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@ public interface Constants {
4343

4444
int AUTHENTICATION_NONCE_LENGTH = 64;
4545

46-
String ElGamalCiphertextOPENING_TAG = "ElGamalCiphertext";
47-
String ElGamalDecryptionShareOPENING_TAG = "elGamalDecryptionShare";
48-
String PETCommitmentOPENING_TAG = "petC";
49-
String PETDecommitmentOPENING_TAG = "petD";
50-
String ElGamalPublicKeyOPENING_TAG = "elGamalPublicKey";
51-
String PublicKeyCiphertextOPENING_TAG = "publicKeyCiphertext";
52-
String PrivateKeyOPENING_TAG = "privateKey";
53-
String PublicKeyOPENING_TAG = "publicKey";
54-
String SharedKeyOPENING_TAG = "sharedKey";
55-
String SharedKeyCiphertextOPENING_TAG = "sharedKeyCiphertext";
56-
String SignatureOPENING_TAG = "signature";
57-
String VoteCapabilityOPENING_TAG = "voteCapability";
58-
String VoteCapabilityShareOPENING_TAG = "voteCapabilityShare";
46+
String EL_GAMAL_CIPHERTEXT_OPENING_TAG = "ElGamalCiphertext";
47+
String EL_GAMAL_DECRYPTION_SHARE_OPENING_TAG = "elGamalDecryptionShare";
48+
String PET_COMMITMENT_OPENING_TAG = "petC";
49+
String PET_DECOMMITMENT_OPENING_TAG = "petD";
50+
String EL_GAMAL_PUBLIC_KEY_OPENING_TAG = "elGamalPublicKey";
51+
String PUBLIC_KEY_CIPHERTEXT_OPENING_TAG = "publicKeyCiphertext";
52+
String PRIVATE_KEY_OPENING_TAG = "privateKey";
53+
String PUBLIC_KEY_OPENING_TAG = "publicKey";
54+
String SHARED_KEY_OPENING_TAG = "sharedKey";
55+
String SHARED_KEY_CIPHERTEXT_OPENING_TAG = "sharedKeyCiphertext";
56+
String SIGNATURE_OPENING_TAG = "signature";
57+
String VOTE_CAPABILITY_OPENING_TAG = "voteCapability";
58+
String VOTE_CAPABILITY_SHARE_OPENING_TAG = "voteCapabilityShare";
5959

6060
Charset CHARSET = StandardCharsets.UTF_8;
6161
}

civitas.base/src/main/java/civitas/util/CivitasBigintegerBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public String toString() {
2828
}
2929

3030
@Override
31-
public boolean equals(final Object o) {
32-
return (o instanceof CivitasBigInteger) && this.i.equals(((CivitasBigInteger) o).i);
31+
public boolean equals(final Object object) {
32+
return object instanceof CivitasBigInteger other && this.i.equals(other.i);
3333
}
3434

3535
@Override

civitas.base/src/main/java/civitas/util/InitialTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package civitas.util;
22

3-
import java.io.UnsupportedEncodingException;
3+
import java.nio.charset.StandardCharsets;
44

55
import org.bouncycastle.jce.provider.BouncyCastleProvider;
66

@@ -17,13 +17,13 @@ public class InitialTests {
1717
}
1818
}
1919

20-
public static void doTests() throws UnsupportedEncodingException {
20+
public static void doTests() {
2121
testUTF8Support();
2222
checkBouncyCastle();
2323
}
2424

25-
public static byte[] testUTF8Support() throws UnsupportedEncodingException {
26-
return "árvíztűrő tükörfúrógép".getBytes("UTF-8");
25+
public static byte[] testUTF8Support() {
26+
return "árvíztűrő tükörfúrógép".getBytes(StandardCharsets.UTF_8);
2727
}
2828

2929
public static void checkBouncyCastle() {

civitas.common.tests/src/main/java/civitas/bboard/server/EndToEndTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void testPost() throws Exception {
103103
public PostDTO createPostDTO() throws CryptoException {
104104
Signature signature =
105105
signWithPublicKey.apply(supervisorPriv, supervisorPub, BOARD_CLOSED_CONTENT_COMMITMENT_XML.getBytes());
106-
return new PostDTO(BoardClosedContentCommitmentMETA, BOARD_CLOSED_CONTENT_COMMITMENT_XML, signature);
106+
return new PostDTO(BOARD_CLOSED_CONTENT_COMMITMENT_META, BOARD_CLOSED_CONTENT_COMMITMENT_XML, signature);
107107
}
108108

109109
public RequestParticipationDTO createRequestParticipationDTO() {

civitas.common.tests/src/main/java/civitas/bboard/server/controllers/CloseBoardControllerTest.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import static org.mockito.Mockito.verifyNoInteractions;
77

88
import java.io.IOException;
9-
import java.security.NoSuchAlgorithmException;
10-
import java.security.spec.InvalidKeySpecException;
119
import java.util.ArrayList;
1210

1311
import org.bouncycastle.crypto.CryptoException;
@@ -36,9 +34,7 @@ class CloseBoardControllerTest extends RandomAwareTestBase
3634
- calculates the BoardClosedContentCommitment for all voter block
3735
- posts the BoardClosedContentCommitment for the election master
3836
""")
39-
void test()
40-
throws InvalidKeySpecException, IOException, NoSuchAlgorithmException, CommunicableException,
41-
CryptoException {
37+
void test() throws CommunicableException, CryptoException {
4238
closeBoardController.apply(BULLETIN_BOARD_ID, ELECTION_ID, NUM_VOTER_BLOCKS, SIGNATURE_OF_AUTH_NONCE_WITH_KEY);
4339
verify(closeBoardController.getBoardForId).apply(BULLETIN_BOARD_ID, true);
4440
verify(closeBoardController.verifyPublicKeySignature)
@@ -54,7 +50,7 @@ void test()
5450

5551
@Test
5652
@DisplayName("if the signature does not verify, does nothing")
57-
void test2() throws InvalidKeySpecException, IOException, NoSuchAlgorithmException, CommunicableException {
53+
void test2() throws CommunicableException {
5854
closeBoardController.apply(BULLETIN_BOARD_ID, ELECTION_ID, NUM_VOTER_BLOCKS, SIGNATURE_OF_AUTH_NONCE_WITH_KEY2);
5955
verify(closeBoardController.boardRepository, times(0)).save(BULLETIN_BOARD);
6056
verifyNoInteractions(closeBoardController.cryptoHash);
@@ -63,7 +59,7 @@ void test2() throws InvalidKeySpecException, IOException, NoSuchAlgorithmExcepti
6359

6460
@Test
6561
@DisplayName("if the election is null, a NullPointerException is thrown")
66-
void test3() throws InvalidKeySpecException, IOException {
62+
void test3() {
6763
assertThrows(
6864
NullPointerException.class,
6965
() -> closeBoardController.apply(
@@ -72,23 +68,23 @@ void test3() throws InvalidKeySpecException, IOException {
7268

7369
@Test
7470
@DisplayName("if the signature is null, a NullPointerException is thrown")
75-
void test4() throws InvalidKeySpecException, IOException {
71+
void test4() {
7672
assertThrows(
7773
NullPointerException.class,
7874
() -> closeBoardController.apply(BULLETIN_BOARD_ID, ELECTION_ID, NUM_VOTER_BLOCKS, null));
7975
}
8076

8177
@Test
8278
@DisplayName("if the number of voter blocks is negative, an IllegalArgumentException is thrown")
83-
void test5() throws InvalidKeySpecException, IOException {
79+
void test5() {
8480
assertThrows(
8581
IllegalArgumentException.class,
8682
() -> closeBoardController.apply(BULLETIN_BOARD_ID, ELECTION_ID, -1, SIGNATURE_OF_AUTH_NONCE_WITH_KEY));
8783
}
8884

8985
@Test
9086
@DisplayName("if the number of voter blocks is zero, the BoardClosedContentCommitment posted has empty hashes")
91-
void test6() throws InvalidKeySpecException, IOException, NoSuchAlgorithmException, CommunicableException {
87+
void test6() throws CommunicableException {
9288
closeBoardController.apply(BULLETIN_BOARD_ID, ELECTION_ID, 0, SIGNATURE_OF_AUTH_NONCE_WITH_KEY);
9389
verify(closeBoardController.getRestTemplate.restTemplate)
9490
.postForObject(
@@ -99,7 +95,7 @@ void test6() throws InvalidKeySpecException, IOException, NoSuchAlgorithmExcepti
9995

10096
@Test
10197
@DisplayName("if the election server is unreachable, an IOException is thrown and the board is not closed")
102-
void test7() throws InvalidKeySpecException, IOException {
98+
void test7() {
10399
given(EnvironmentState.ELECTION_SERVER_IS_UNREACHEABLE);
104100
assertThrows(
105101
IOException.class,

civitas.common.tests/src/main/java/civitas/bboard/server/controllers/PostControllerTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,21 @@ void test() throws CommunicableException, JAXBException, IOException, CryptoExce
4343
postController.apply(
4444
BULLETIN_BOARD_ID,
4545
new PostDTO(
46-
BoardClosedContentCommitmentMETA,
46+
BOARD_CLOSED_CONTENT_COMMITMENT_META,
4747
BOARD_CLOSED_CONTENT_COMMITMENT_XML,
4848
BOARD_CLOSED_CONTENT_COMMITMENT_SIGNATURE)));
4949
verify(postController.checkAccess)
5050
.apply(
5151
Operation.POST,
5252
BOARD_CLOSED_CONTENT_COMMITMENT_SIGNATURE.getSignerPubKey(),
53-
BoardClosedContentCommitmentMETA + BULLETIN_BOARD_ID);
53+
BOARD_CLOSED_CONTENT_COMMITMENT_META + BULLETIN_BOARD_ID);
5454
verify(postController.verifyPublicKeySignature)
5555
.apply(BOARD_CLOSED_CONTENT_COMMITMENT_SIGNATURE, BOARD_CLOSED_CONTENT_COMMITMENT_XML.getBytes());
5656
verify(postController.getBoardForId).apply(BULLETIN_BOARD_ID, true);
5757
verify(postController.updateCache)
5858
.apply(
5959
BULLETIN_BOARD_ID,
60-
BoardClosedContentCommitmentMETA,
60+
BOARD_CLOSED_CONTENT_COMMITMENT_META,
6161
BOARD_CLOSED_CONTENT_COMMITMENT_XML,
6262
CURRENT_TIME);
6363
verify(postController.bBPostRepository).findByBbidOrderBySerialDesc(BULLETIN_BOARD_ID);
@@ -67,7 +67,7 @@ void test() throws CommunicableException, JAXBException, IOException, CryptoExce
6767
BigInteger.valueOf(CURRENT_TIME).toByteArray(),
6868
BOARD_CLOSED_CONTENT_COMMITMENT_SIGNATURE.signatureBytes);
6969
verify(postController.loggerController)
70-
.apply(MarkerFactory.getMarker("bbs_post"), BoardClosedContentCommitmentMETA + BULLETIN_BOARD_ID);
70+
.apply(MarkerFactory.getMarker("bbs_post"), BOARD_CLOSED_CONTENT_COMMITMENT_META + BULLETIN_BOARD_ID);
7171
verify(postController.bBPostRepository).save(NEXT_POST);
7272
}
7373

@@ -79,7 +79,7 @@ void test1() {
7979
() -> postController.apply(
8080
BULLETIN_BOARD_ID,
8181
new PostDTO(
82-
BoardClosedContentCommitmentMETA,
82+
BOARD_CLOSED_CONTENT_COMMITMENT_META,
8383
BOARD_CLOSED_CONTENT_COMMITMENT_XML,
8484
BOARD_CLOSED_CONTENT_COMMITMENT_SIGNATURE_BAD)));
8585
}
@@ -92,7 +92,7 @@ void test2() {
9292
() -> postController.apply(
9393
BULLETIN_BOARD_ID,
9494
new PostDTO(
95-
BoardClosedContentCommitmentMETA,
95+
BOARD_CLOSED_CONTENT_COMMITMENT_META,
9696
BOARD_CLOSED_CONTENT_COMMITMENT_XML,
9797
BOARD_CLOSED_CONTENT_COMMITMENT_SIGNATURE_BAD_ACTOR)));
9898
}
@@ -104,7 +104,7 @@ void test3() throws CommunicableException {
104104
Long actual = postController.apply(
105105
BULLETIN_BOARD_ID,
106106
new PostDTO(
107-
BoardClosedContentCommitmentMETA,
107+
BOARD_CLOSED_CONTENT_COMMITMENT_META,
108108
BOARD_CLOSED_CONTENT_COMMITMENT_XML,
109109
BOARD_CLOSED_CONTENT_COMMITMENT_SIGNATURE));
110110
verify(postController.cryptoHash)

civitas.common.tests/src/main/java/civitas/common/CheckAccessStub.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
import civitas.crypto.signature.SignatureTestData;
1010

1111
public class CheckAccessStub implements BoardClosedContentCommitmentTestData, SignatureTestData, CommonConstants {
12-
public static CheckAccess stub() throws IllegalAccessException {
12+
public static CheckAccess stub() {
1313
CheckAccess mock = mock(CheckAccess.class);
1414
doThrow(new SecurityException()).when(mock).apply(any(), any(), any());
1515
doNothing()
1616
.when(mock)
17-
.apply(Operation.POST, PUBLIC_KEY_BASE64, BoardClosedContentCommitmentMETA + BULLETIN_BOARD_ID);
17+
.apply(Operation.POST, PUBLIC_KEY_BASE64, BOARD_CLOSED_CONTENT_COMMITMENT_META + BULLETIN_BOARD_ID);
1818
doNothing()
1919
.when(mock)
20-
.apply(Operation.POST, PUBLIC_KEY2_BASE64, BoardClosedContentCommitmentMETA + BULLETIN_BOARD_ID);
20+
.apply(Operation.POST, PUBLIC_KEY2_BASE64, BOARD_CLOSED_CONTENT_COMMITMENT_META + BULLETIN_BOARD_ID);
2121
return mock;
2222
}
2323
}

civitas.common.tests/src/main/java/civitas/common/tabteller/ConstructTabTellerKeyShareCommitmentTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
44

5-
import java.io.UnsupportedEncodingException;
6-
75
import org.junit.jupiter.api.Test;
86
import org.mockito.InjectMocks;
97

@@ -18,7 +16,7 @@ class ConstructTabTellerKeyShareCommitmentTest extends RandomAwareTestBase
1816
ConstructTabTellerKeyShareCommitment constructTabTellerKeyShareCommitment;
1917

2018
@Test
21-
void test() throws JAXBException, UnsupportedEncodingException {
19+
void test() throws JAXBException {
2220
assertEquals(TAB_TELLER_KEY_SHARE_COMMITMENT, constructTabTellerKeyShareCommitment.apply(TAB_TELLER_KEY_SHARE));
2321
}
2422
}

civitas.common.tests/src/main/java/civitas/common/votercapabilitysharesandproofs/VerifyVoterCapabilitySharesAndProofTest.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import static org.junit.jupiter.api.Assertions.assertThrows;
55
import static org.junit.jupiter.api.Assertions.assertTrue;
66

7-
import java.io.UnsupportedEncodingException;
8-
97
import org.junit.jupiter.api.DisplayName;
108
import org.junit.jupiter.api.Test;
119
import org.mockito.InjectMocks;
@@ -29,7 +27,7 @@ class VerifyVoterCapabilitySharesAndProofTest extends RandomAwareTestBase
2927
- check that p.e' equals enc(vc, ttKey r)
3028
- check the proof, i.e., that p.e is a reencryption of p.e'
3129
""")
32-
void test() throws UnsupportedEncodingException {
30+
void test() {
3331
assertTrue(verifyVoterCapabilitySharesAndProof.apply(
3432
VOTER_CAPABILITIES_AND_PROOFS,
3533
POSTED_CAPABILITIES,
@@ -41,7 +39,7 @@ void test() throws UnsupportedEncodingException {
4139

4240
@Test
4341
@DisplayName("if the proof does not verify, the check fails")
44-
void test1() throws UnsupportedEncodingException {
42+
void test1() {
4543
assertFalse(verifyVoterCapabilitySharesAndProof.apply(
4644
VOTER_CAPABILITIES_AND_PROOFS,
4745
POSTED_CAPABILITIES,
@@ -53,7 +51,7 @@ void test1() throws UnsupportedEncodingException {
5351

5452
@Test
5553
@DisplayName("if p.e' != enc(vc, ttKey r), the check fails")
56-
void test2() throws UnsupportedEncodingException {
54+
void test2() {
5755
assertFalse(verifyVoterCapabilitySharesAndProof.apply(
5856
VOTER_CAPABILITIES_AND_PROOFS,
5957
POSTED_CAPABILITIES,
@@ -65,7 +63,7 @@ void test2() throws UnsupportedEncodingException {
6563

6664
@Test
6765
@DisplayName("if the posted capability does not verify, the check fails")
68-
void test3() throws UnsupportedEncodingException {
66+
void test3() {
6967
assertFalse(verifyVoterCapabilitySharesAndProof.apply(
7068
VOTER_CAPABILITIES_AND_PROOFS_CAP_NONVERIFY,
7169
POSTED_CAPABILITIES_NONVERIFY,
@@ -77,7 +75,7 @@ void test3() throws UnsupportedEncodingException {
7775

7876
@Test
7977
@DisplayName("if p.e != the posted capability, the check fails")
80-
void test4() throws UnsupportedEncodingException {
78+
void test4() {
8179
assertFalse(verifyVoterCapabilitySharesAndProof.apply(
8280
VOTER_CAPABILITIES_AND_PROOFS,
8381
POSTED_CAPABILITIES_NONVERIFY,
@@ -118,7 +116,7 @@ void test6() {
118116
@Test
119117
@DisplayName(
120118
"if the length of posted capabilities and the capabilities in the VoterCapabilitySharesAndProof are different, the check fails")
121-
void test7() throws UnsupportedEncodingException {
119+
void test7() {
122120
assertFalse(verifyVoterCapabilitySharesAndProof.apply(
123121
VOTER_CAPABILITIES_AND_PROOFS,
124122
new ElGamalSignedCiphertext[1],
@@ -131,7 +129,7 @@ void test7() throws UnsupportedEncodingException {
131129
@Test
132130
@DisplayName(
133131
"if the length of capabilities and reencrypt factors in the VoterCapabilitySharesAndProof are different, the check fails")
134-
void test8() throws UnsupportedEncodingException {
132+
void test8() {
135133
assertFalse(verifyVoterCapabilitySharesAndProof.apply(
136134
VOTER_CAPABILITIES_AND_PROOFS_BAD_FACTOR_COUNTS,
137135
POSTED_CAPABILITIES,
@@ -144,7 +142,7 @@ void test8() throws UnsupportedEncodingException {
144142
@Test
145143
@DisplayName(
146144
"if the length of capabilities and reencrypt factors in the VoterCapabilitySharesAndProof are different, the check fails")
147-
void test9() throws UnsupportedEncodingException {
145+
void test9() {
148146
assertFalse(verifyVoterCapabilitySharesAndProof.apply(
149147
VOTER_CAPABILITIES_AND_PROOFS_BAD_PROOF_COUNT,
150148
POSTED_CAPABILITIES,

0 commit comments

Comments
 (0)