Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate older junit dependency #435

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,9 @@
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>3.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
87 changes: 37 additions & 50 deletions src/test/java/ibm/jceplus/junit/base/BaseTestAES.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

public class BaseTestAES extends BaseTestCipher {

Expand Down Expand Up @@ -795,29 +795,27 @@ protected void encryptDecryptDoFinal(String algorithm, boolean requireLengthMult
AlgorithmParameters params = cp.getParameters();

if (requireLengthMultipleBlockSize) {
assertTrue(
assertTrue(((blockSize > 0) && (message.length % blockSize) == 0),
"Did not get expected IllegalBlockSizeException, blockSize=" + blockSize
+ ", msglen=" + message.length,
((blockSize > 0) && (message.length % blockSize) == 0));
+ ", msglen=" + message.length);
}

// Verify the text
cp.init(Cipher.DECRYPT_MODE, key, params);
byte[] newPlainText = cp.doFinal(cipherText);

boolean success = Arrays.equals(newPlainText, message);
assertTrue("Decrypted text does not match expected, msglen=" + message.length, success);
assertTrue(success, "Decrypted text does not match expected, msglen=" + message.length);

// Verify the text again
cp.init(Cipher.DECRYPT_MODE, key, params);
byte[] newPlainText2 = cp.doFinal(cipherText, 0, cipherText.length);
success = Arrays.equals(newPlainText2, message);
assertTrue("Decrypted text does not match expected, msglen=" + message.length, success);
assertTrue(success, "Decrypted text does not match expected, msglen=" + message.length);
} catch (IllegalBlockSizeException e) {
assertTrue(
assertTrue((!requireLengthMultipleBlockSize || (message.length % blockSize) != 0),
"Unexpected IllegalBlockSizeException, blockSize=" + blockSize + ", msglen="
+ message.length,
(!requireLengthMultipleBlockSize || (message.length % blockSize) != 0));
+ message.length);
}
}

Expand All @@ -839,10 +837,9 @@ protected void encryptDecryptUpdate(String algorithm, boolean requireLengthMulti
AlgorithmParameters params = cp.getParameters();

if (requireLengthMultipleBlockSize) {
assertTrue(
assertTrue(((message.length % blockSize) == 0),
"Did not get expected IllegalBlockSizeException, blockSize=" + blockSize
+ ", msglen=" + message.length,
((message.length % blockSize) == 0));
+ ", msglen=" + message.length);
}

// Verify the text
Expand All @@ -859,12 +856,11 @@ protected void encryptDecryptUpdate(String algorithm, boolean requireLengthMulti
System.arraycopy(newPlainText2, 0, newPlainText, l, newPlainText2.length);

boolean success = Arrays.equals(newPlainText, message);
assertTrue("Decrypted text does not match expected, msglen=" + message.length, success);
assertTrue(success, "Decrypted text does not match expected, msglen=" + message.length);
} catch (IllegalBlockSizeException e) {
assertTrue(
assertTrue((!requireLengthMultipleBlockSize || (message.length % blockSize) != 0),
"Unexpected IllegalBlockSizeException, blockSize=" + blockSize + ", msglen="
+ message.length,
(!requireLengthMultipleBlockSize || (message.length % blockSize) != 0));
+ message.length);
}
}

Expand All @@ -888,10 +884,9 @@ protected void encryptDecryptPartialUpdate(String algorithm,
AlgorithmParameters params = cp.getParameters();

if (requireLengthMultipleBlockSize) {
assertTrue(
assertTrue(((message.length % blockSize) == 0),
"Did not get expected IllegalBlockSizeException, blockSize=" + blockSize
+ ", msglen=" + message.length,
((message.length % blockSize) == 0));
+ ", msglen=" + message.length);
}

// Verify the text
Expand All @@ -908,13 +903,11 @@ protected void encryptDecryptPartialUpdate(String algorithm,
System.arraycopy(newPlainText2, 0, newPlainText, l, newPlainText2.length);

boolean success = Arrays.equals(newPlainText, message);
assertTrue("Decrypted text does not match expected, partial msglen=" + message.length,
success);
assertTrue(success, "Decrypted text does not match expected, partial msglen=" + message.length);
} catch (IllegalBlockSizeException e) {
assertTrue(
assertTrue((!requireLengthMultipleBlockSize || (message.length % blockSize) != 0),
"Unexpected IllegalBlockSizeException, blockSize=" + blockSize + ", msglen="
+ message.length,
(!requireLengthMultipleBlockSize || (message.length % blockSize) != 0));
+ message.length);
}
}

Expand All @@ -938,32 +931,30 @@ protected void encryptDecryptReuseObject(String algorithm,
AlgorithmParameters params = cp.getParameters();

if (requireLengthMultipleBlockSize) {
assertTrue(
assertTrue(((blockSize > 0) && (message.length % blockSize) == 0),
"Did not get expected IllegalBlockSizeException, blockSize=" + blockSize
+ ", msglen=" + message.length,
((blockSize > 0) && (message.length % blockSize) == 0));
+ ", msglen=" + message.length);
}

// Verify that the cipher object can be used to encrypt again without re-init
byte[] cipherText2 = cp.doFinal(message);
boolean success = Arrays.equals(cipherText2, cipherText);
assertTrue("Re-encrypted text does not match", success);
assertTrue(success, "Re-encrypted text does not match");

// Verify the text
cp.init(Cipher.DECRYPT_MODE, key, params);
byte[] newPlainText = cp.doFinal(cipherText);
success = Arrays.equals(newPlainText, message);
assertTrue("Decrypted text does not match expected, msglen=" + message.length, success);
assertTrue(success, "Decrypted text does not match expected, msglen=" + message.length);

// Verify that the cipher object can be used to decrypt again without re-init
byte[] newPlainText2 = cp.doFinal(cipherText, 0, cipherText.length);
success = Arrays.equals(newPlainText2, newPlainText);
assertTrue("Re-decrypted text does not match", success);
assertTrue(success, "Re-decrypted text does not match");
} catch (IllegalBlockSizeException e) {
assertTrue(
assertTrue((!requireLengthMultipleBlockSize || (message.length % blockSize) != 0),
"Unexpected IllegalBlockSizeException, blockSize=" + blockSize + ", msglen="
+ message.length,
(!requireLengthMultipleBlockSize || (message.length % blockSize) != 0));
+ message.length);
}
}

Expand Down Expand Up @@ -992,14 +983,13 @@ protected void encryptDecryptDoFinalCopySafe(String algorithm,
AlgorithmParameters params = cp.getParameters();

if (requireLengthMultipleBlockSize) {
assertTrue(
assertTrue(((blockSize > 0) && (message.length % blockSize) == 0),
"Did not get expected IllegalBlockSizeException, blockSize=" + blockSize
+ ", msglen=" + message.length,
((blockSize > 0) && (message.length % blockSize) == 0));
+ ", msglen=" + message.length);
}

boolean success = Arrays.equals(cipherText, cipherText0);
assertTrue("Encrypted text does not match expected result", success);
assertTrue(success, "Encrypted text does not match expected result");

// Verify the text
cp.init(Cipher.DECRYPT_MODE, key, params);
Expand All @@ -1008,12 +998,11 @@ protected void encryptDecryptDoFinalCopySafe(String algorithm,
byte[] newPlainText = Arrays.copyOf(resultBuffer, resultLen);

success = Arrays.equals(newPlainText, message);
assertTrue("Decrypted text does not match expected, msglen=" + message.length, success);
assertTrue(success, "Decrypted text does not match expected, msglen=" + message.length);
} catch (IllegalBlockSizeException e) {
assertTrue(
assertTrue((!requireLengthMultipleBlockSize || (message.length % blockSize) != 0),
"Unexpected IllegalBlockSizeException, blockSize=" + blockSize + ", msglen="
+ message.length,
(!requireLengthMultipleBlockSize || (message.length % blockSize) != 0));
+ message.length);
}
}

Expand Down Expand Up @@ -1045,14 +1034,13 @@ protected void encryptDecryptUpdateCopySafe(String algorithm,
AlgorithmParameters params = cp.getParameters();

if (requireLengthMultipleBlockSize) {
assertTrue(
assertTrue(((blockSize > 0) && (message.length % blockSize) == 0),
"Did not get expected IllegalBlockSizeException, blockSize=" + blockSize
+ ", msglen=" + message.length,
((blockSize > 0) && (message.length % blockSize) == 0));
+ ", msglen=" + message.length);
}

boolean success = Arrays.equals(cipherText, cipherText0);
assertTrue("Encrypted text does not match expected result", success);
assertTrue(success, "Encrypted text does not match expected result");

// Verify the text
cp.init(Cipher.DECRYPT_MODE, key, params);
Expand All @@ -1065,12 +1053,11 @@ protected void encryptDecryptUpdateCopySafe(String algorithm,
System.arraycopy(plainText2, 0, newPlainText, plainText1Len, plainText2.length);

success = Arrays.equals(newPlainText, message);
assertTrue("Decrypted text does not match expected, msglen=" + message.length, success);
assertTrue(success, "Decrypted text does not match expected, msglen=" + message.length);
} catch (IllegalBlockSizeException e) {
assertTrue(
assertTrue((!requireLengthMultipleBlockSize || (message.length % blockSize) != 0),
"Unexpected IllegalBlockSizeException, blockSize=" + blockSize + ", msglen="
+ message.length,
(!requireLengthMultipleBlockSize || (message.length % blockSize) != 0));
+ message.length);
}
}

Expand Down
Loading