-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8357466: Create test for Ciphers that are using ByteBuffers backed by MemorySegments #26967
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
base: master
Are you sure you want to change the base?
Conversation
👋 Welcome back mdonovan! A progress list of the required criteria for merging this PR into |
❗ This change is not yet ready to be integrated. |
|
||
System.out.println("All Tests Passed"); | ||
} finally { | ||
arena.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to initialize arena
in a try-with-resources, so you can get rid of the explicit .close()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered that for a while but I couldn't see a way to make it work without completely refactoring the whole test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it work if you pass arena as a param to the prepareBuffers. This way you can call try-with-resources for each test and get rid of arena.close()
.
Also, it's only case MEMORY_SEGMENT:
which needs arena at all, so you can just pass null to all others and only for test#3
// Test#3: against ByteBuffer backed by MemorySegment
try (Arena arena = Arena.ofConfined()) {
prepareBuffers(BufferType.MEMORY_SEGMENT, useRO, buf.length,
buf, 0, PLAINTEXT_SIZE, offset, arena);
runTest(offset, expectedPT, expectedCT);
System.out.println("\tMEMSEGMENT: passed");
}
all others will look like this prepareBuffers(BufferType.ALLOCATE, useRO, buf.length, buf, 0, PLAINTEXT_SIZE, offset, null);
, making it a minor refactor, as this method is only used here.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just one comment and a few nitpicks. IMO nits are not worth doing unless there is another commit.
debugBuf.setLength(0); | ||
} | ||
|
||
private static void execTest(Cipher cipher, byte[]answer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
private static void execTest(Cipher cipher, byte[]answer, | |
private static void execTest(Cipher cipher, byte[] answer, | |
@@ -68,6 +69,13 @@ public static void main(String[] args) throws Exception { | |||
updateAADFail((ByteBuffer) null); | |||
updateAADPass(bb); | |||
|
|||
try(Arena arena = Arena.ofConfined()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
try(Arena arena = Arena.ofConfined()) { | |
try (Arena arena = Arena.ofConfined()) { |
The same for:
test/jdk/javax/crypto/Mac/ByteBuffers.java
test/jdk/javax/crypto/CipherSpi/DirectBBRemaining.java
test/jdk/javax/crypto/Cipher/ByteBuffers.java
test/jdk/java/security/MessageDigest/ByteBuffers.java
test/jdk/sun/security/pkcs11/Signature/ByteBuffers.java
test/jdk/sun/security/pkcs11/Cipher/TestPaddingOOB.java
test/jdk/sun/security/pkcs11/Cipher/TestSymmCiphers.java
test/jdk/sun/security/pkcs11/MessageDigest/ByteBuffers.java
|
||
System.out.println("All Tests Passed"); | ||
} finally { | ||
arena.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it work if you pass arena as a param to the prepareBuffers. This way you can call try-with-resources for each test and get rid of arena.close()
.
Also, it's only case MEMORY_SEGMENT:
which needs arena at all, so you can just pass null to all others and only for test#3
// Test#3: against ByteBuffer backed by MemorySegment
try (Arena arena = Arena.ofConfined()) {
prepareBuffers(BufferType.MEMORY_SEGMENT, useRO, buf.length,
buf, 0, PLAINTEXT_SIZE, offset, arena);
runTest(offset, expectedPT, expectedCT);
System.out.println("\tMEMSEGMENT: passed");
}
all others will look like this prepareBuffers(BufferType.ALLOCATE, useRO, buf.length, buf, 0, PLAINTEXT_SIZE, offset, null);
, making it a minor refactor, as this method is only used here.
What do you think?
@@ -30,6 +30,7 @@ | |||
|
|||
import javax.crypto.*; | |||
import javax.crypto.spec.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Could you please remove the wildcard import here and from other files touched?
Can we also add some negative tests? (This could be done in a different PR). For example, trying to use a read-only ByteBuffer for output, or trying to use a ByteBuffer after the arena has been closed. |
Created JDK-8366912 for negative tests. |
There is a recent bug fix at #27081 when a slice of an array-based buffer is used. Can you investigate why it has not been caught by this test? Should it be enhanced? Thanks. |
There are a lot of tests under |
This PR extends security tests to use ByteBuffers backed by MemorySegments. Tests in the areas of Signature, Cipher, MessageDigest, and Mac are updated.
Progress
Issue
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26967/head:pull/26967
$ git checkout pull/26967
Update a local copy of the PR:
$ git checkout pull/26967
$ git pull https://git.openjdk.org/jdk.git pull/26967/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 26967
View PR using the GUI difftool:
$ git pr show -t 26967
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26967.diff
Using Webrev
Link to Webrev Comment