Skip to content

Commit

Permalink
sonar fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
firaja committed Mar 11, 2020
1 parent 141fb3a commit 41e7ef7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
</exclusion>
</exclusions>
</dependency>

</dependencies>
Expand Down
28 changes: 17 additions & 11 deletions src/main/java/com/password4j/BCryptFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -539,20 +539,10 @@ private String hashPw(byte[] passwordb, String salt)
int off;
StringBuilder rs = new StringBuilder();

if (salt == null)
{
throw new BadParametersException("salt cannot be null");
}
internalChecks(salt);

int saltLength = salt.length();

if (saltLength < 28)
{
throw new BadParametersException("Invalid salt");
}

if (salt.charAt(0) != '$' || salt.charAt(1) != '2')
throw new BadParametersException("Invalid salt version");
if (salt.charAt(2) == '$')
off = 3;
else
Expand Down Expand Up @@ -594,6 +584,22 @@ private String hashPw(byte[] passwordb, String salt)
return rs.toString();
}

private static void internalChecks(String salt)
{
if (salt == null)
{
throw new BadParametersException("salt cannot be null");
}
else if (salt.length() < 28)
{
throw new BadParametersException("Invalid salt");
}
else if (salt.charAt(0) != '$' || salt.charAt(1) != '2')
{
throw new BadParametersException("Invalid salt version");
}
}

private static String generateSalt(String prefix, int logRounds)
{
StringBuilder rs = new StringBuilder();
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/password4j/SystemChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Scanner;

public class SystemChecker
{
Expand All @@ -34,8 +33,6 @@ public class SystemChecker

private static final int WARMUP_ROUNDS = 20;

private static final Scanner SCANNER = new Scanner(System.in);

private SystemChecker()
{
//
Expand Down
6 changes: 3 additions & 3 deletions src/test/com/password4j/BCryptFunctionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@ private static String encodeBase64(byte[] d, int len)
@Test
public void testBase64EncodeSimpleByteArrays()
{
Assert.assertEquals(encodeBase64(new byte[]{0}, 1), "..");
Assert.assertEquals(encodeBase64(new byte[]{0, 0}, 2), "...");
Assert.assertEquals(encodeBase64(new byte[]{0, 0, 0}, 3), "....");
Assert.assertEquals("..", encodeBase64(new byte[]{0}, 1));
Assert.assertEquals("...", encodeBase64(new byte[]{0, 0}, 2));
Assert.assertEquals("....", encodeBase64(new byte[]{0, 0, 0}, 3));
}

@Test
Expand Down

0 comments on commit 41e7ef7

Please sign in to comment.