11/*
2- * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
3030 * @run main/othervm TestGeneral
3131 */
3232
33+ import jtreg .SkippedException ;
34+
3335import java .security .NoSuchAlgorithmException ;
3436import java .security .Provider ;
3537import java .security .SecureRandom ;
38+ import java .util .ArrayList ;
3639import java .util .Arrays ;
40+ import java .util .List ;
3741import javax .crypto .SecretKeyFactory ;
3842import javax .crypto .SecretKey ;
3943import javax .crypto .spec .SecretKeySpec ;
@@ -57,8 +61,11 @@ private void test(String algorithm, SecretKey key, Provider p,
5761 try {
5862 skf = SecretKeyFactory .getInstance (algorithm , p );
5963 } catch (NoSuchAlgorithmException e ) {
60- System .out .println ("Not supported, skipping: " + e );
61- return ;
64+ throw new SkippedException ("[algorithm: " + algorithm +
65+ ", key: " + key .getAlgorithm () + "]" +
66+ ", provider: " + p .getName () + "]" +
67+ ", expectedTestResult: " + expected + "]" +
68+ "Not supported, skipping: " + e );
6269 }
6370 try {
6471 SecretKey key2 = skf .translateKey (key );
@@ -99,21 +106,31 @@ public void main(Provider p) throws Exception {
99106 SecretKey bf_128Key = new SecretKeySpec (rawBytes , 0 , 16 , "Blowfish" );
100107 SecretKey cc20Key = new SecretKeySpec (rawBytes , 0 , 32 , "ChaCha20" );
101108
102- // fixed key length
103- test ("AES" , aes_128Key , p , TestResult .PASS );
104- test ("AES" , aes_256Key , p , TestResult .PASS );
105- test ("AES" , cc20Key , p , TestResult .FAIL );
109+ List <String > skippedList = new ArrayList <>();
110+ try {
111+ // fixed key length
112+ test ("AES" , aes_128Key , p , TestResult .PASS );
113+ test ("AES" , aes_256Key , p , TestResult .PASS );
114+ test ("AES" , cc20Key , p , TestResult .FAIL );
106115
107- test ("ChaCha20" , aes_128Key , p , TestResult .FAIL );
108- test ("ChaCha20" , aes_256Key , p , TestResult .FAIL );
109- test ("ChaCha20" , cc20Key , p , TestResult .PASS );
116+ test ("ChaCha20" , aes_128Key , p , TestResult .FAIL );
117+ test ("ChaCha20" , aes_256Key , p , TestResult .FAIL );
118+ test ("ChaCha20" , cc20Key , p , TestResult .PASS );
110119
111- // variable key length
112- // Different PKCS11 impls may have different ranges
113- // of supported key sizes for variable-key-length
114- // algorithms.
115- test ("Blowfish" , aes_128Key , p , TestResult .FAIL );
116- test ("Blowfish" , cc20Key , p , TestResult .FAIL );
117- test ("Blowfish" , bf_128Key , p , TestResult .PASS );
120+ // variable key length
121+ // Different PKCS11 impls may have different ranges
122+ // of supported key sizes for variable-key-length
123+ // algorithms.
124+ test ("Blowfish" , aes_128Key , p , TestResult .FAIL );
125+ test ("Blowfish" , cc20Key , p , TestResult .FAIL );
126+ test ("Blowfish" , bf_128Key , p , TestResult .PASS );
127+ } catch (SkippedException skippedException ){
128+ skippedException .printStackTrace ();
129+ skippedList .add (skippedException .getMessage ());
130+ }
131+
132+ if (!skippedList .isEmpty ()) {
133+ throw new SkippedException ("One or more tests skipped " + skippedList );
134+ }
118135 }
119136}
0 commit comments