Skip to content

Commit

Permalink
Add test case from #208
Browse files Browse the repository at this point in the history
  • Loading branch information
smeyer198 committed Jul 4, 2024
1 parent 0b205b1 commit abca07b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public void reportedIssues() {
HeadlessCryptoScanner scanner = createScanner(mavenProject);

setErrorsCount("<issueseeds.Main: void main(java.lang.String[])>", RequiredPredicateError.class, 1);

setErrorsCount("<issue208.Issue208WithSingleEntryPoint: void encryptImpl()>", RequiredPredicateError.class, 0);
setErrorsCount("<issue208.Issue208WithMultipleEntryPoints: void encryptImpl()>", RequiredPredicateError.class, 1);

setErrorsCount("<issue81.Encryption: byte[] encrypt(byte[],javax.crypto.SecretKey)>", ConstraintError.class, 1);
setErrorsCount("<issue81.Encryption: byte[] encrypt(byte[],javax.crypto.SecretKey)>", RequiredPredicateError.class, 1);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package issue208;

import javax.crypto.spec.IvParameterSpec;
import java.security.SecureRandom;

public class Issue208WithMultipleEntryPoints {

private final SecureRandom secureRandom = new SecureRandom();

private static final int IV_LENGTH = 32;

private void encryptImpl() {
byte[] iv = new byte[IV_LENGTH];
secureRandom.nextBytes(iv);

// iv has to ensure 'randomized'
IvParameterSpec ivParameterSpec = new IvParameterSpec(iv);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package issue208;

import javax.crypto.spec.IvParameterSpec;
import java.security.SecureRandom;

public class Issue208WithSingleEntryPoint {

private final SecureRandom secureRandom = new SecureRandom();

private static final int IV_LENGTH = 32;

private void encryptImpl() {
byte[] iv = new byte[IV_LENGTH];
secureRandom.nextBytes(iv);

IvParameterSpec ivParameterSpec = new IvParameterSpec(iv);
}

public static void main(String[] args) {
// Method 'main' is the single entry point -> Instantiate SecureRandom seed and
// use it in 'encryptImpl'
Issue208WithSingleEntryPoint issue208 = new Issue208WithSingleEntryPoint();
issue208.encryptImpl();
}
}

0 comments on commit abca07b

Please sign in to comment.