Skip to content

Commit

Permalink
Fix more Sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Nanne Baars committed Mar 24, 2023
1 parent fbd9531 commit 3f0cf71
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
13 changes: 10 additions & 3 deletions commons/src/main/java/org/paseto4j/commons/Pair.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package org.paseto4j.commons;

public class Pair<T> {

public T first;
public T second;
private T first;
private T second;

public Pair(T first, T second) {
this.first = first;
this.second = second;
}

public T getFirst() {
return first;
}

public T getSecond() {
return second;
}
}
8 changes: 4 additions & 4 deletions commons/src/test/java/org/paseto4j/commons/ByteUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ void splitEqual() {

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

Assertions.assertArrayEquals(new byte[] {'a'}, result.first);
Assertions.assertArrayEquals(new byte[] {'b'}, result.second);
Assertions.assertArrayEquals(new byte[] {'a'}, result.getFirst());
Assertions.assertArrayEquals(new byte[] {'b'}, result.getSecond());
}

@Test
Expand All @@ -72,7 +72,7 @@ void splitEmpty() {

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

Assertions.assertEquals(0, result.first.length);
Assertions.assertEquals(0, result.first.length);
Assertions.assertEquals(0, result.getFirst().length);
Assertions.assertEquals(0, result.getSecond().length);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ void signTokenWithSeed() {

@Test
void keyTooSmall() {
PrivateKey privateKey = new PrivateKey(new byte[] {'0'}, V2);
Assertions.assertThrows(
PasetoException.class,
() -> PasetoPublic.sign(new PrivateKey(new byte[] {'0'}, V2), " test", "test"));
PasetoException.class, () -> PasetoPublic.sign(privateKey, " test", "test"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ public static boolean verify(PublicKey publicKey, byte[] msg, byte[] signature)
DERSequence seq =
new DERSequence(
new ASN1Integer[] {
new ASN1Integer(new BigInteger(1, pair.first)),
new ASN1Integer(new BigInteger(1, pair.second))
new ASN1Integer(new BigInteger(1, pair.getFirst())),
new ASN1Integer(new BigInteger(1, pair.getSecond()))
});

return verifier.verify(seq.getEncoded());
Expand Down
8 changes: 4 additions & 4 deletions version3/src/main/java/org/paseto4j/version3/PasetoLocal.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ static String encrypt(
// 4
byte[] tmp = encryptionKey(key, nonce);
Pair<byte[]> split = ByteUtils.split(tmp, 32);
byte[] ek = split.first;
byte[] n2 = split.second;
byte[] ek = split.getFirst();
byte[] n2 = split.getSecond();
byte[] ak = authenticationKey(key, nonce);

// 5
Expand Down Expand Up @@ -135,8 +135,8 @@ static String decrypt(SecretKey key, String token, String footer, String implici
// 5
byte[] tmp = encryptionKey(key, nonce);
Pair<byte[]> split = ByteUtils.split(tmp, 32);
byte[] ek = split.first;
byte[] n2 = split.second;
byte[] ek = split.getFirst();
byte[] n2 = split.getSecond();
byte[] ak = authenticationKey(key, nonce);

// 6
Expand Down

0 comments on commit 3f0cf71

Please sign in to comment.