Skip to content

Commit 3f0cf71

Browse files
author
Nanne Baars
committed
Fix more Sonar issues
1 parent fbd9531 commit 3f0cf71

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
package org.paseto4j.commons;
22

33
public class Pair<T> {
4-
5-
public T first;
6-
public T second;
4+
private T first;
5+
private T second;
76

87
public Pair(T first, T second) {
98
this.first = first;
109
this.second = second;
1110
}
11+
12+
public T getFirst() {
13+
return first;
14+
}
15+
16+
public T getSecond() {
17+
return second;
18+
}
1219
}

commons/src/test/java/org/paseto4j/commons/ByteUtilsTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ void splitEqual() {
6262

6363
var result = ByteUtils.split(b, 1);
6464

65-
Assertions.assertArrayEquals(new byte[] {'a'}, result.first);
66-
Assertions.assertArrayEquals(new byte[] {'b'}, result.second);
65+
Assertions.assertArrayEquals(new byte[] {'a'}, result.getFirst());
66+
Assertions.assertArrayEquals(new byte[] {'b'}, result.getSecond());
6767
}
6868

6969
@Test
@@ -72,7 +72,7 @@ void splitEmpty() {
7272

7373
var result = ByteUtils.split(b, 1);
7474

75-
Assertions.assertEquals(0, result.first.length);
76-
Assertions.assertEquals(0, result.first.length);
75+
Assertions.assertEquals(0, result.getFirst().length);
76+
Assertions.assertEquals(0, result.getSecond().length);
7777
}
7878
}

version2/src/test/java/org/paseto4j/version2/PasetoPublicTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ void signTokenWithSeed() {
159159

160160
@Test
161161
void keyTooSmall() {
162+
PrivateKey privateKey = new PrivateKey(new byte[] {'0'}, V2);
162163
Assertions.assertThrows(
163-
PasetoException.class,
164-
() -> PasetoPublic.sign(new PrivateKey(new byte[] {'0'}, V2), " test", "test"));
164+
PasetoException.class, () -> PasetoPublic.sign(privateKey, " test", "test"));
165165
}
166166

167167
@Test

version3/src/main/java/org/paseto4j/version3/CryptoFunctions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ public static boolean verify(PublicKey publicKey, byte[] msg, byte[] signature)
180180
DERSequence seq =
181181
new DERSequence(
182182
new ASN1Integer[] {
183-
new ASN1Integer(new BigInteger(1, pair.first)),
184-
new ASN1Integer(new BigInteger(1, pair.second))
183+
new ASN1Integer(new BigInteger(1, pair.getFirst())),
184+
new ASN1Integer(new BigInteger(1, pair.getSecond()))
185185
});
186186

187187
return verifier.verify(seq.getEncoded());

version3/src/main/java/org/paseto4j/version3/PasetoLocal.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ static String encrypt(
7575
// 4
7676
byte[] tmp = encryptionKey(key, nonce);
7777
Pair<byte[]> split = ByteUtils.split(tmp, 32);
78-
byte[] ek = split.first;
79-
byte[] n2 = split.second;
78+
byte[] ek = split.getFirst();
79+
byte[] n2 = split.getSecond();
8080
byte[] ak = authenticationKey(key, nonce);
8181

8282
// 5
@@ -135,8 +135,8 @@ static String decrypt(SecretKey key, String token, String footer, String implici
135135
// 5
136136
byte[] tmp = encryptionKey(key, nonce);
137137
Pair<byte[]> split = ByteUtils.split(tmp, 32);
138-
byte[] ek = split.first;
139-
byte[] n2 = split.second;
138+
byte[] ek = split.getFirst();
139+
byte[] n2 = split.getSecond();
140140
byte[] ak = authenticationKey(key, nonce);
141141

142142
// 6

0 commit comments

Comments
 (0)