Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
Add nextInt to SecureRandomProvider interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
moxie0 committed Feb 10, 2015
1 parent 98860d4 commit 43bb26c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

public interface SecureRandomProvider {
public void nextBytes(byte[] output);
public int nextInt(int maxValue);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ public class NullSecureRandomProvider implements SecureRandomProvider {
public void nextBytes(byte[] output) {
throw new IllegalArgumentException("No default J2ME Secure Random provider available!");
}

// @Override
public int nextInt(int maxValue) {
throw new IllegalArgumentException("No default J2ME Secure Random provider available!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,14 @@ public void nextBytes(byte[] output) {
throw new AssertionError(e);
}
}

@Override
public int nextInt(int maxValue) {
try {
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
return secureRandom.nextInt(maxValue);
} catch (NoSuchAlgorithmException e) {
throw new AssertionError(e);
}
}
}

0 comments on commit 43bb26c

Please sign in to comment.