6969import org .bouncycastle .pkcs .PKCSException ;
7070import org .bouncycastle .pkcs .bc .BcPKCS12MacCalculatorBuilder ;
7171import org .bouncycastle .pkcs .bc .BcPKCS12MacCalculatorBuilderProvider ;
72- import org .bouncycastle .pkcs .bc .BcPKCS12PBMac1CalculatorBuilderProvider ;
7372import org .bouncycastle .pkcs .bc .BcPKCS12PBEInputDecryptorProviderBuilder ;
7473import org .bouncycastle .pkcs .bc .BcPKCS12PBEOutputEncryptorBuilder ;
74+ import org .bouncycastle .pkcs .bc .BcPKCS12PBMac1CalculatorBuilderProvider ;
7575import org .bouncycastle .pkcs .jcajce .JcaPKCS12SafeBagBuilder ;
7676import org .bouncycastle .pkcs .jcajce .JcaPKCS8EncryptedPrivateKeyInfoBuilder ;
7777import org .bouncycastle .pkcs .jcajce .JcePKCS12MacCalculatorBuilder ;
8080import org .bouncycastle .pkcs .jcajce .JcePKCSPBEOutputEncryptorBuilder ;
8181import org .bouncycastle .util .Arrays ;
8282import org .bouncycastle .util .encoders .Base64 ;
83+ import org .junit .function .ThrowingRunnable ;
8384
8485import static org .junit .Assert .assertThrows ;
8586
@@ -1138,7 +1139,7 @@ public void testPfxPduMac()
11381139 public void testPfxPduPBMac1PBKdf2 ()
11391140 throws Exception
11401141 {
1141- char [] password = "1234" .toCharArray ();
1142+ final char [] password = "1234" .toCharArray ();
11421143 // valid test vectors
11431144 for (byte [] test_vector : new byte [][]{pkcs12WithPBMac1PBKdf2_a1 , pkcs12WithPBMac1PBKdf2_a2 , pkcs12WithPBMac1PBKdf2_a3 })
11441145 {
@@ -1160,9 +1161,17 @@ public void testPfxPduPBMac1PBKdf2()
11601161 }
11611162
11621163 // invalid test vector that throws exception
1163- PKCS12PfxPdu pfx = new PKCS12PfxPdu (pkcs12WithPBMac1PBKdf2_a6 );
1164+ final PKCS12PfxPdu pfx = new PKCS12PfxPdu (pkcs12WithPBMac1PBKdf2_a6 );
11641165 assertTrue (pfx .hasMac ());
1165- PKCSException thrown = assertThrows (PKCSException .class , () -> pfx .isMacValid (new BcPKCS12PBMac1CalculatorBuilderProvider (), password ));
1166+ PKCSException thrown = assertThrows (PKCSException .class , new ThrowingRunnable ()
1167+ {
1168+ @ Override
1169+ public void run ()
1170+ throws Throwable
1171+ {
1172+ pfx .isMacValid (new BcPKCS12PBMac1CalculatorBuilderProvider (), password );
1173+ }
1174+ });
11661175 assertTrue (thrown .getMessage ().contains ("Key length must be present when using PBMAC1." ));
11671176 }
11681177
0 commit comments