Skip to content

Commit cc279ab

Browse files
committed
Replace 3 assertions w/ explicit checks. Throw IllegalArgumentException on failure.
1 parent 60394ce commit cc279ab

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎src/main/java/org/owasp/esapi/crypto/CryptoHelper.java‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ public class CryptoHelper {
5656
public static SecretKey generateSecretKey(String alg, int keySize)
5757
throws EncryptionException
5858
{
59-
assert alg != null : "Algorithm must not be null."; // NPE if null and assertions disabled.
60-
assert !alg.equals("") : "Algorithm must not be empty"; // NoSuchAlgorithmExeption if empty & assertions disabled.
61-
assert keySize > 0 : "Key size must be positive."; // Usually should be even multiple of 8, but not strictly required by alg.
59+
if ( alg == null || alg.equals("") ) {
60+
throw new IllegalArgumentException("Algorithm must not be null or empty."); // Avoid later possibly ambiguous NPE.
61+
}
62+
if ( keySize <= 0 ) {
63+
throw new IllegalArgumentException("Key size must be positive."); // Usually should be an even multiple of 8, but not strictly required by alg.
64+
}
6265
// Don't use CipherSpec here to get algorithm as this may cause assertion
6366
// to fail (when enabled) if only algorithm name is passed to us.
6467
String[] cipherSpec = alg.split("/");

0 commit comments

Comments
 (0)