/luni/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/EncryptedPrivateKeyInfoTest.java
Java | 1232 lines | 674 code | 105 blank | 453 comment | 24 complexity | 2db02a78fe1d3e6c328ef1b1442ff48c MD5 | raw file
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/**
19* @author Vladimir N. Molotkov
20* @version $Revision$
21*/
22
23package org.apache.harmony.crypto.tests.javax.crypto;
24
25import dalvik.annotation.TestTargetClass;
26import dalvik.annotation.TestLevel;
27import dalvik.annotation.TestTargetNew;
28
29import java.io.IOException;
30import java.security.AlgorithmParameters;
31import java.security.AlgorithmParametersSpi;
32import java.security.InvalidAlgorithmParameterException;
33import java.security.InvalidKeyException;
34import java.security.Key;
35import java.security.KeyPair;
36import java.security.KeyPairGenerator;
37import java.security.NoSuchAlgorithmException;
38import java.security.NoSuchProviderException;
39import java.security.Provider;
40import java.security.Security;
41import java.security.spec.InvalidKeySpecException;
42import java.security.spec.InvalidParameterSpecException;
43import java.security.spec.PKCS8EncodedKeySpec;
44import java.util.Arrays;
45
46import javax.crypto.BadPaddingException;
47import javax.crypto.Cipher;
48import javax.crypto.EncryptedPrivateKeyInfo;
49import javax.crypto.IllegalBlockSizeException;
50import javax.crypto.KeyGenerator;
51import javax.crypto.NoSuchPaddingException;
52import javax.crypto.SecretKeyFactory;
53import javax.crypto.spec.PBEKeySpec;
54import javax.crypto.spec.PBEParameterSpec;
55
56import org.apache.harmony.crypto.tests.support.EncryptedPrivateKeyInfoData;
57
58import junit.framework.TestCase;
59
60@TestTargetClass(EncryptedPrivateKeyInfo.class)
61/**
62 * Test for EncryptedPrivateKeyInfo class.
63 *
64 * All binary data for this test were generated using BEA JRockit j2sdk1.4.2_04
65 * (http://www.bea.com) with security providers list extended by Bouncy Castle's
66 * one (http://www.bouncycastle.org)
67 */
68public class EncryptedPrivateKeyInfoTest extends TestCase {
69
70 private static final Provider[] provider = Security.getProviders();
71
72 /**
73 * Algorithm names/transformations used in roundtrip tests of
74 * getKeySpec(...) methods
75 */
76 private static final String[][] algName = {
77 // AES
78 { "AES", null},
79 // {"AES", "AES/ECB/PKCS5Padding"},
80 // {"AES", "AES/CBC/PKCS5Padding"},
81 // {"AES", "AES/OFB/PKCS5Padding"},
82 // {"AES", "AES/CFB/PKCS5Padding"},
83 // {"2.16.840.1.101.3.4.1.1", null},
84 // {"2.16.840.1.101.3.4.1.2", null},
85 // {"2.16.840.1.101.3.4.1.3", null},
86 // {"2.16.840.1.101.3.4.1.4", null},
87 // {"2.16.840.1.101.3.4.1.5", null},
88 // {"2.16.840.1.101.3.4.1.21", null},
89 // {"2.16.840.1.101.3.4.1.22", null},
90 // {"2.16.840.1.101.3.4.1.23", null},
91 // {"2.16.840.1.101.3.4.1.24", null},
92 // {"2.16.840.1.101.3.4.1.25", null},
93 // {"2.16.840.1.101.3.4.1.41", null},
94 // {"2.16.840.1.101.3.4.1.42", null},
95 // {"2.16.840.1.101.3.4.1.43", null},
96 // {"2.16.840.1.101.3.4.1.44", null},
97 // {"2.16.840.1.101.3.4.1.45", null},
98
99 // Blowfish
100 // NO OIDs for Blowfish defined (?)
101 { "Blowfish", null },
102 // {"Blowfish","Blowfish/CBC/PKCS5Padding"},
103 // {"Blowfish","Blowfish/CFB/PKCS5Padding"},
104 // {"Blowfish","Blowfish/OFB/PKCS5Padding"},
105 // {"Blowfish","Blowfish/PCBC/PKCS5Padding"},
106
107 // DES: OIW OIDs only
108 // {iso(1) identified-organization(3) oiw(14) secsig(3)
109 // algorithms(2) desECB(6)}
110 // 1.3.14.3.2.6
111 // 1.3.14.3.2.7
112 // 1.3.14.3.2.8
113 // 1.3.14.3.2.9
114 { "DES", null },
115 // {"DES", "DES/CBC/PKCS5Padding"},
116 // {"DES","DES/CFB/PKCS5Padding"},
117 // {"DES","DES/OFB/PKCS5Padding"},
118 // {"DES","DES/PCBC/PKCS5Padding"},
119
120 // DESede (=TripleDes)
121 //{iso(1) identified-organization(3) oiw(14) secsig(3)
122 // algorithms(2) desEDE(17)}
123 // 1.3.14.3.2.17
124 // {"DESede",null},
125 // {"DESede","DESede/CBC/PKCS5Padding"},
126 // {"DESede","DESede/CFB/PKCS5Padding"},
127 // {"DESede","DESede/OFB/PKCS5Padding"},
128 // {"DESede","DESede/PCBC/PKCS5Padding"},
129 { "TripleDES", null },
130 // {"TripleDES","TripleDES/CBC/PKCS5Padding"},
131 // {"TripleDES","TripleDES/CFB/PKCS5Padding"},
132 // {"TripleDES","TripleDES/OFB/PKCS5Padding"},
133 // {"TripleDES","TripleDES/PCBC/PKCS5Padding"},
134
135 // PBEWith<digest>And<encryption>
136 { "PBEWithMD5AndTripleDES", null },
137 // {iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs-5(5)
138 // pbeWithMD5AndDES-CBC(3)}
139 { "PBEWithMD5AndDES", "PBEWithMD5AndDES/CBC/PKCS5Padding", "PBEWithMD5AndDES"},
140 { "PBEWithMD5AndDES", null, "PBEWithMD5AndDES"}, { "PBEWithHmacSHA1AndDESede", null },
141 // more oids:
142 // {iso(1) member-body(2) us(840) nortelnetworks(113533) entrust(7)
143 // algorithms(66) pbeWithMD5AndCAST5-CBC(12)}
144 //
145 // also named pbeWithSHAAnd128BitRC4, pbeWithSHA1And128BitRC4:
146 // {iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs-12(12)
147 // pkcs-12-PbeIds(1) pkcs-12-OfflineTransportMode(1)}
148 //
149 // {iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs-12(12)
150 // pkcs-12-PbeIds(1)} +
151 // pbeWithSHAAnd40BitRC4(2) pbeWithSHAAnd3-KeyTripleDES-CBC(3)
152 // pbeWithSHAAnd2-KeyTripleDES-CBC(4) pbeWithSHAAnd128BitRC2-CBC(5)
153 // pbeWithSHAAnd40BitRC2-CBC(6)
154
155 // DiffieHellman
156 { "DiffieHellman", null }, // 1.2.840.10046.2.1
157 // {"DH",null}, // 1.2.840.10046.2.1
158 // {"1.2.840.113549.1.3.1", null},
159
160 { "DSA", null }, // 1.2.840.10040.4.1
161
162 { "RC2", null },
163
164 { "RC4", null },
165
166 { "RC5", null },
167
168 // {"1.2.840.113549.1.12.1.1",null},
169 // {"1.2.840.113549.1.12.1.2",null},
170 //{ "1.2.840.113549.1.12.1.3", null, "PBEWithSHA1AndDESede"},
171 //{ "PBEWithSHA1AndDESede", null, "PBEWithSHA1AndDESede"},
172 // {"1.2.840.113549.1.12.1.4",null},
173 // {"1.2.840.113549.1.12.1.5",null},
174 // {"1.2.840.113549.1.12.1.6",null},
175 // {"ELGAMAL/PKCS1", "ELGAMAL/ECB/PKCS1PADDING"},
176 // {"ELGAMAL/PKCS1","ELGAMAL/NONE/PKCS1PADDING"},
177 // {"PBEWITHSHAAND3-KEYTRIPLEDES-CBC", null},
178 // {"PBEWITHSHA1ANDDESEDE", null},
179 // {"PBEWithSHAAnd3KeyTripleDES",null},
180 // {"PBEWITHSHAAND3-KEYTRIPLEDES-CBC",null},
181 //
182 // {"RC5-32",null},
183 //
184 // {"RSA/1", "RSA/1/PKCS1PADDING"},
185 // {"RSA/2", "RSA/2/PKCS1PADDING"},
186 // {"RSA/ISO9796-1", "RSA/ECB/ISO9796-1PADDING"},
187 // {"RSA", "RSA/ECB/NOPADDING"},
188 // {"RSA/OAEP", "RSA/ECB/OAEPPADDING"},
189 // {"RSA/PKCS1", "RSA/ECB/PKCS1PADDING"},
190 // {"RSA/ISO9796-1", "RSA/NONE/ISO9796-1PADDING"},
191 // {"RSA", "RSA/NONE/NOPADDING"},
192 // {"RSA/OAEP", "RSA/NONE/OAEPPADDING"},
193 // {"RSA/PKCS1", "RSA/NONE/PKCS1PADDING"},
194 // {"RSA",null}, // 1.2.840.113549.1.1.1
195 // {"1.2.840.113549.1.1.1", null},
196 };
197
198 @Override protected void setUp() throws Exception {
199 super.setUp();
200 }
201
202 @TestTargetNew(
203 level = TestLevel.COMPLETE,
204 notes = "",
205 method = "getAlgName",
206 args = {}
207 )
208 public void test_getAlgName () {
209 boolean performed = false;
210 for (int i = 0; i < algName.length; i++) {
211 try {
212 // generate test data
213 TestDataGenerator g = new TestDataGenerator(algName[i][0],
214 algName[i][1], privateKeyInfoDamaged, null);
215
216 // create test object
217 EncryptedPrivateKeyInfo epki;
218 if (g.ap() == null) {
219 epki = new EncryptedPrivateKeyInfo(algName[i][0], g.ct());
220 } else {
221 epki = new EncryptedPrivateKeyInfo(g.ap(), g.ct());
222 }
223
224 // call methods under test
225 if (algName[i].length == 3) {
226 assertEquals(algName[i][2], epki.getAlgName());
227 }
228
229 performed = true;
230 } catch (TestDataGenerator.AllowedFailure allowedFailure) {
231 } catch (NoSuchAlgorithmException allowedFailure) {
232 }
233 }
234 assertTrue("Test not performed", performed);
235 }
236
237 /**
238 * Test #1 for <code>EncryptedPrivateKeyInfo(byte[])</code> constructor
239 * <br>
240 * Assertion: creates <code>EncryptedPrivateKeyInfo</code> instance <br>
241 * Test preconditions: valid parameters passed <br>
242 * Expected: must pass without any exceptions
243 *
244 * @throws IOException
245 * @throws NoSuchAlgorithmException
246 */
247 @TestTargetNew(
248 level = TestLevel.PARTIAL_COMPLETE,
249 notes = "This is a complete subset of tests for EncryptedPrivateKeyInfo(byte[]) constructor.",
250 method = "EncryptedPrivateKeyInfo",
251 args = {byte[].class}
252 )
253 public final void testEncryptedPrivateKeyInfobyteArray1() throws Exception {
254 new EncryptedPrivateKeyInfo(EncryptedPrivateKeyInfoData
255 .getValidEncryptedPrivateKeyInfoEncoding("DH"));
256 }
257
258 /**
259 * Test #2 for <code>EncryptedPrivateKeyInfo(byte[])</code> constructor
260 * <br>
261 * Assertion: <code>NullPointerException</code> if encoding is
262 * <code>null</code><br>
263 * Test preconditions: <code>null</code> passed as a parameter <br>
264 * Expected: <code>NullPointerException</code>
265 *
266 * @throws IOException
267 */
268 @TestTargetNew(
269 level = TestLevel.PARTIAL_COMPLETE,
270 notes = "This is a complete subset of tests for EncryptedPrivateKeyInfo(byte[]) constructor.",
271 method = "EncryptedPrivateKeyInfo",
272 args = {byte[].class}
273 )
274 public final void testEncryptedPrivateKeyInfobyteArray2()
275 throws IOException {
276 try {
277 new EncryptedPrivateKeyInfo(null);
278 fail(getName() + ": NullPointerException has not been thrown");
279 } catch (NullPointerException ok) {
280 }
281 }
282
283 /**
284 * Test #3 for <code>EncryptedPrivateKeyInfo(byte[])</code> constructor
285 * <br>
286 * Assertion: <code>IOException</code> if encoding is wrong <br>
287 * Test preconditions: wrong encoding passed as a parameter <br>
288 * Expected: <code>IOException</code>
289 */
290 @TestTargetNew(
291 level = TestLevel.PARTIAL_COMPLETE,
292 notes = "This is a complete subset of tests for EncryptedPrivateKeyInfo(byte[]) constructor.",
293 method = "EncryptedPrivateKeyInfo",
294 args = {byte[].class}
295 )
296 public final void testEncryptedPrivateKeyInfobyteArray3() {
297 try {
298 new EncryptedPrivateKeyInfo(new byte[0]);
299 fail(getName() + ": IOException has not been thrown");
300 } catch (IOException ok) {
301 }
302 }
303
304 /**
305 * Test #4 for <code>EncryptedPrivateKeyInfo(byte[])</code> constructor
306 * <br>
307 * Assertion: <code>IOException</code> if encoding is wrong <br>
308 * Test preconditions: wrong encoding passed as a parameter <br>
309 * Expected: <code>IOException</code>
310 */
311 @TestTargetNew(
312 level = TestLevel.PARTIAL_COMPLETE,
313 notes = "This is a complete subset of tests for EncryptedPrivateKeyInfo(byte[]) constructor.",
314 method = "EncryptedPrivateKeyInfo",
315 args = {byte[].class}
316 )
317 public final void testEncryptedPrivateKeyInfobyteArray4() {
318 try {
319 new EncryptedPrivateKeyInfo(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9,
320 10 });
321 fail(getName() + ": IOException has not been thrown");
322 } catch (IOException ok) {
323 }
324 }
325
326 /**
327 * Test #5 for <code>EncryptedPrivateKeyInfo(byte[])</code> constructor
328 * <br>
329 * Assertion: <code>IOException</code> if encoding is wrong <br>
330 * Test preconditions: wrong encoding passed as a parameter <br>
331 * Expected: <code>IOException</code>
332 */
333 @TestTargetNew(
334 level = TestLevel.PARTIAL_COMPLETE,
335 notes = "This is a complete subset of tests for EncryptedPrivateKeyInfo(byte[]) constructor.",
336 method = "EncryptedPrivateKeyInfo",
337 args = {byte[].class}
338 )
339 public final void testEncryptedPrivateKeyInfobyteArray5() throws Exception {
340 byte[] enc = null;
341 try {
342 // 1: get valid encoding
343 enc = EncryptedPrivateKeyInfoData
344 .getValidEncryptedPrivateKeyInfoEncoding("DSA");
345
346 // ... and corrupt it (set wrong alg OID length)
347 enc[9] = (byte) 6;
348
349 new EncryptedPrivateKeyInfo(enc);
350 fail(getName() + "(1): IOException has not been thrown");
351 } catch (IOException ok) {
352 }
353
354 try {
355 // 2: get valid encoding
356 enc = EncryptedPrivateKeyInfoData
357 .getValidEncryptedPrivateKeyInfoEncoding("DSA");
358 // ... and corrupt it (set wrong encrypted data tag)
359 enc[307] = (byte) 6;
360 new EncryptedPrivateKeyInfo(enc);
361 fail(getName() + "(2): IOException has not been thrown");
362 } catch (IOException ok) {
363 }
364
365 try {
366 // 3: get valid encoding
367 enc = EncryptedPrivateKeyInfoData
368 .getValidEncryptedPrivateKeyInfoEncoding("DSA");
369 // ... and corrupt it (set wrong encrypted data length)
370 enc[310] = (byte) 1;
371 new EncryptedPrivateKeyInfo(enc);
372 fail(getName() + "(3): IOException has not been thrown");
373 } catch (IOException ok) {
374 }
375
376 try {
377 // 4: get valid encoding
378 enc = EncryptedPrivateKeyInfoData
379 .getValidEncryptedPrivateKeyInfoEncoding("DSA");
380 // ... and corrupt it (set wrong tag for alg params sequence)
381 enc[17] = (byte) 0x29;
382 EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(enc);
383
384 if (epki.getAlgParameters() == null) {
385 // This kind of encoding corruption can
386 // be only determined while AlgorithmParameters
387 // initialization BUT No AlgorithmParameters instance
388 // available for algName0[i][0].
389 // So just skip this sub test
390 } else {
391 fail(getName() + "(4): IOException has not been thrown");
392 }
393
394 } catch (IOException ok) {
395 }
396
397 try {
398 // 5: get valid encoding
399 enc = EncryptedPrivateKeyInfoData
400 .getValidEncryptedPrivateKeyInfoEncoding("DSA");
401 // ... and corrupt it (set wrong length for alg params sequence)
402 enc[20] = (byte) 0x1d;
403 new EncryptedPrivateKeyInfo(enc);
404 fail(getName() + "(5): IOException has not been thrown");
405 } catch (IOException ok) {
406 }
407
408 try {
409 // 6: get valid encoding
410 enc = EncryptedPrivateKeyInfoData
411 .getValidEncryptedPrivateKeyInfoEncoding("DSA");
412 // ... and corrupt it (set wrong length for alg params sequence)
413 enc[20] = (byte) 0x1f;
414 new EncryptedPrivateKeyInfo(enc);
415 fail(getName() + "(6): IOException has not been thrown");
416 } catch (IOException ok) {
417 }
418 }
419
420 /**
421 * Test #6 for <code>EncryptedPrivateKeyInfo(byte[])</code> constructor
422 * <br>
423 * Assertion: byte array is copied to prevent subsequent modification <br>
424 * Test preconditions: valid array passed then modified <br>
425 * Expected: getEncoded(), invoked after above modification, must return
426 * array as it was before the modification
427 *
428 * @throws IOException
429 */
430 @TestTargetNew(
431 level = TestLevel.PARTIAL_COMPLETE,
432 notes = "This is a complete subset of tests for EncryptedPrivateKeyInfo(byte[]) constructor.",
433 method = "EncryptedPrivateKeyInfo",
434 args = {byte[].class}
435 )
436 public final void testEncryptedPrivateKeyInfobyteArray6() throws Exception {
437 byte[] encoded = EncryptedPrivateKeyInfoData
438 .getValidEncryptedPrivateKeyInfoEncoding("DSA");
439 byte[] encodedCopy = encoded.clone();
440 // pass valid array
441 EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(encodedCopy);
442 // modify array passed
443 encodedCopy[9] = (byte) 6;
444 // check that internal state has not been affected
445 assertTrue(Arrays.equals(encoded, epki.getEncoded()));
446 }
447
448 /**
449 * Test #1 for <code>EncryptedPrivateKeyInfo(String, byte[])</code>
450 * constructor <br>
451 * Assertion: creates <code>EncryptedPrivateKeyInfo</code> instance <br>
452 * Test preconditions: valid parameters passed <br>
453 * Expected: must pass without any exceptions
454 */
455 @TestTargetNew(
456 level = TestLevel.PARTIAL_COMPLETE,
457 notes = "This is a complete subset of tests for EncryptedPrivateKeyInfo(String, byte[]) constructor.",
458 method = "EncryptedPrivateKeyInfo",
459 args = {java.lang.String.class, byte[].class}
460 )
461 public final void testEncryptedPrivateKeyInfoStringbyteArray1() {
462 boolean performed = false;
463
464 for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) {
465 try {
466 new EncryptedPrivateKeyInfo(
467 EncryptedPrivateKeyInfoData.algName0[i][0],
468 EncryptedPrivateKeyInfoData.encryptedData);
469 performed = true;
470 } catch (NoSuchAlgorithmException allowed) {
471 }
472 }
473
474 assertTrue("Test not performed", performed);
475 }
476
477 /**
478 * Test #2 for <code>EncryptedPrivateKeyInfo(String, byte[])</code>
479 * constructor <br>
480 * Assertion: <code>NoSuchAlgorithmException</code>- if the specified
481 * algorithm is not supported <br>
482 * Test preconditions: pass nonexistent algorithm name <br>
483 * Expected: <code>NoSuchAlgorithmException</code>
484 */
485 @TestTargetNew(
486 level = TestLevel.PARTIAL_COMPLETE,
487 notes = "This is a complete subset of tests for EncryptedPrivateKeyInfo(String, byte[]) constructor.",
488 method = "EncryptedPrivateKeyInfo",
489 args = {java.lang.String.class, byte[].class}
490 )
491 public final void testEncryptedPrivateKeyInfoStringbyteArray2() {
492 try {
493 new EncryptedPrivateKeyInfo("bla-bla",
494 EncryptedPrivateKeyInfoData.encryptedData);
495 fail(getName() + ": NoSuchAlgorithmException has not been thrown");
496 } catch (NoSuchAlgorithmException ok) {
497 }
498
499 try {
500 new EncryptedPrivateKeyInfo("",
501 EncryptedPrivateKeyInfoData.encryptedData);
502 fail(getName() + ": NoSuchAlgorithmException has not been thrown");
503 } catch (NoSuchAlgorithmException ok) {
504 }
505 }
506
507 /**
508 * Test #3 for <code>EncryptedPrivateKeyInfo(String, byte[])</code>
509 * constructor <br>
510 * Assertion: <code>NullPointerException</code>- if the specified
511 * algorithm or encrypted data is <code>null</code><br>
512 * Test preconditions: pass <code>null</code> as algorithm name then as
513 * encrypted data <br>
514 * Expected: <code>NullPointerException</code> in both cases
515 *
516 * @throws NoSuchAlgorithmException
517 */
518 @TestTargetNew(
519 level = TestLevel.PARTIAL_COMPLETE,
520 notes = "This is a complete subset of tests for EncryptedPrivateKeyInfo(String, byte[]) constructor.",
521 method = "EncryptedPrivateKeyInfo",
522 args = {java.lang.String.class, byte[].class}
523 )
524 public final void testEncryptedPrivateKeyInfoStringbyteArray3()
525 throws NoSuchAlgorithmException {
526 // pass null as name
527 try {
528 new EncryptedPrivateKeyInfo((String) null,
529 EncryptedPrivateKeyInfoData.encryptedData);
530 fail(getName() + ": NullPointerException has not been thrown");
531 } catch (NullPointerException ok) {
532 }
533
534 // pass null as encrypted data
535 try {
536 new EncryptedPrivateKeyInfo("DSA", null);
537 fail(getName() + ": NullPointerException has not been thrown");
538 } catch (NullPointerException ok) {
539 }
540 }
541
542 /**
543 * Test #4 for <code>EncryptedPrivateKeyInfo(String, byte[])</code>
544 * constructor <br>
545 * Assertion: <code>IllegalArgumentException</code>- if encrypted data is
546 * empty, i.e. 0-length <br>
547 * Test preconditions: pass empty encrypted data <br>
548 * Expected: <code>IllegalArgumentException</code>
549 */
550 @TestTargetNew(
551 level = TestLevel.PARTIAL_COMPLETE,
552 notes = "This is a complete subset of tests for EncryptedPrivateKeyInfo(String, byte[]) constructor.",
553 method = "EncryptedPrivateKeyInfo",
554 args = {java.lang.String.class, byte[].class}
555 )
556 public final void testEncryptedPrivateKeyInfoStringbyteArray4()
557 throws Exception {
558 try {
559 new EncryptedPrivateKeyInfo("DSA", new byte[] {});
560 fail(getName() + ": IllegalArgumentException has not been thrown");
561 } catch (IllegalArgumentException ok) {
562 }
563 }
564
565 /**
566 * Test #5 for <code>EncryptedPrivateKeyInfo(String, byte[])</code>
567 * constructor <br>
568 * Assertion: byte array is copied to prevent subsequent modification <br>
569 * Test preconditions: valid array passed then modified <br>
570 * Expected: getEncryptedData(), invoked after above modification, must
571 * return array as it was before the modification
572 *
573 * @throws IOException
574 */
575 @TestTargetNew(
576 level = TestLevel.PARTIAL_COMPLETE,
577 notes = "This is a complete subset of tests for EncryptedPrivateKeyInfo(String, byte[]) constructor.",
578 method = "EncryptedPrivateKeyInfo",
579 args = {java.lang.String.class, byte[].class}
580 )
581 public final void testEncryptedPrivateKeyInfoStringbyteArray5()
582 throws Exception {
583 byte[] encryptedDataCopy = EncryptedPrivateKeyInfoData.encryptedData
584 .clone();
585 // pass valid array
586 EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo("DSA",
587 encryptedDataCopy);
588 // modify array passed
589 encryptedDataCopy[0] = (byte) 6;
590 // check that internal state has not been affected
591 assertTrue(Arrays.equals(EncryptedPrivateKeyInfoData.encryptedData,
592 epki.getEncryptedData()));
593 }
594
595 /**
596 * @tests javax/crypto/EncryptedPrivateKeyInfo(String, byte[])
597 * Checks exception order
598 */
599 @TestTargetNew(
600 level = TestLevel.PARTIAL_COMPLETE,
601 notes = "This is a complete subset of tests for EncryptedPrivateKeyInfo(String, byte[]) constructor.",
602 method = "EncryptedPrivateKeyInfo",
603 args = {java.lang.String.class, byte[].class}
604 )
605 public final void testEncryptedPrivateKeyInfoStringbyteArray6() {
606 //Regression for HARMONY-768
607 try {
608 new EncryptedPrivateKeyInfo("0", new byte[] {});
609 fail("NoSuchAlgorithmException expected");
610 } catch (NoSuchAlgorithmException e) {
611 //expected
612 }
613 }
614
615 class Mock_AlgorithmParameters extends AlgorithmParameters {
616 protected Mock_AlgorithmParameters(AlgorithmParametersSpi paramSpi, Provider provider, String algorithm) {
617 super(paramSpi, provider, algorithm);
618 }
619 }
620
621/**
622 * Test #1 for
623 * <code>EncryptedPrivateKeyInfo(java.security.AlgorithmParameters, byte[])
624 * </code>
625 * constructor <br>
626 * Assertion: creates <code>EncryptedPrivateKeyInfo</code> instance <br>
627 * Test preconditions: valid parameters passed <br>
628 * Expected: must pass without any exceptions
629 *
630 * @throws IOException
631 * @throws NoSuchAlgorithmException
632 */
633 @TestTargetNew(
634 level = TestLevel.PARTIAL_COMPLETE,
635 notes = "Functionality checked. NoSuchAlgorithmException should be tested for complete tests subset.",
636 method = "EncryptedPrivateKeyInfo",
637 args = {java.security.AlgorithmParameters.class, byte[].class}
638 )
639 public final void testEncryptedPrivateKeyInfoAlgorithmParametersbyteArray1()
640 throws IOException, NoSuchAlgorithmException {
641 AlgorithmParameters ap = null;
642
643 boolean performed = false;
644 for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) {
645 try {
646 ap = AlgorithmParameters
647 .getInstance(EncryptedPrivateKeyInfoData.algName0[i][0]);
648 // use pregenerated AlgorithmParameters encodings
649 ap.init(EncryptedPrivateKeyInfoData.getParametersEncoding(
650 EncryptedPrivateKeyInfoData.algName0[i][0]));
651
652 new EncryptedPrivateKeyInfo(ap,
653 EncryptedPrivateKeyInfoData.encryptedData);
654
655 performed = true;
656 } catch (NoSuchAlgorithmException allowedFailure) {
657 }
658 }
659 assertTrue("Test not performed", performed);
660
661 ap = new Mock_AlgorithmParameters(null, null, "Wrong alg name");
662
663 try {
664 new EncryptedPrivateKeyInfo(ap,
665 EncryptedPrivateKeyInfoData.encryptedData);
666 fail("NoSuchAlgorithmException expected");
667 } catch (NoSuchAlgorithmException e) {
668 //expected
669 }
670 }
671
672 /**
673 * Test #2 for
674 * <code>EncryptedPrivateKeyInfo(java.security.AlgorithmParameters, byte[])
675 * </code>
676 * constructor <br>
677 * Assertion: <code>NullPointerException</code>- if the specified
678 * algorithm parameters or encrypted data is <code>null</code><br>
679 * Test preconditions: pass <code>null</code> as algorithm parameters then
680 * as encrypted data <br>
681 * Expected: <code>NullPointerException</code> in both cases
682 *
683 * @throws NoSuchAlgorithmException
684 * @throws IOException
685 */
686 @TestTargetNew(
687 level = TestLevel.PARTIAL_COMPLETE,
688 notes = "NullPointerException checked.",
689 method = "EncryptedPrivateKeyInfo",
690 args = {java.security.AlgorithmParameters.class, byte[].class}
691 )
692 public final void testEncryptedPrivateKeyInfoAlgorithmParametersbyteArray2()
693 throws NoSuchAlgorithmException, IOException {
694 // 1: pass null as AlgorithmParameters
695 try {
696 new EncryptedPrivateKeyInfo((AlgorithmParameters) null,
697 EncryptedPrivateKeyInfoData.encryptedData);
698 fail(getName() + ": NullPointerException has not been thrown");
699 } catch (NullPointerException ok) {
700 }
701
702 // 2: pass null as encrypted data
703 try {
704 AlgorithmParameters ap = AlgorithmParameters.getInstance("DSA");
705 // use pregenerated AlgorithmParameters encodings
706 ap.init(EncryptedPrivateKeyInfoData.getParametersEncoding("DSA"));
707 new EncryptedPrivateKeyInfo(ap, null);
708 fail(getName() + ": NullPointerException has not been thrown");
709 } catch (NullPointerException ok) {
710 }
711 }
712
713 /**
714 * Test #3 for
715 * <code>EncryptedPrivateKeyInfo(java.security.AlgorithmParameters, byte[])
716 * </code>
717 * constructor <br>
718 * Assertion: <code>IllegalArgumentException</code>- if encrypted data is
719 * empty, i.e. 0-length <br>
720 * Test preconditions: pass empty encrypted data <br>
721 * Expected: <code>IllegalArgumentException</code>
722 *
723 * @throws NoSuchAlgorithmException
724 * @throws IOException
725 */
726 @TestTargetNew(
727 level = TestLevel.PARTIAL_COMPLETE,
728 notes = "IllegalArgumentException checked.",
729 method = "EncryptedPrivateKeyInfo",
730 args = {java.security.AlgorithmParameters.class, byte[].class}
731 )
732 public final void testEncryptedPrivateKeyInfoAlgorithmParametersbyteArray3()
733 throws Exception {
734 try {
735 AlgorithmParameters ap = AlgorithmParameters.getInstance("DSA");
736 // use pregenerated AlgorithmParameters encodings
737 ap.init(EncryptedPrivateKeyInfoData.getParametersEncoding("DSA"));
738
739 new EncryptedPrivateKeyInfo(ap, new byte[] {});
740 fail(getName() + ": IllegalArgumentException has not been thrown");
741
742 } catch (IllegalArgumentException ok) {
743 }
744 }
745
746 /**
747 * Test #4 for
748 * <code>EncryptedPrivateKeyInfo(java.security.AlgorithmParameters, byte[])
749 * </code>
750 * constructor <br>
751 * Assertion: byte array is copied to prevent subsequent modification <br>
752 * Test preconditions: valid array passed then modified <br>
753 * Expected: getEncryptedData(), invoked after above modification, must
754 * return array as it was before the modification
755 *
756 * @throws IOException
757 */
758 @TestTargetNew(
759 level = TestLevel.PARTIAL_COMPLETE,
760 notes = "Functionality checked.",
761 method = "EncryptedPrivateKeyInfo",
762 args = {java.security.AlgorithmParameters.class, byte[].class}
763 )
764 public final void testEncryptedPrivateKeyInfoAlgorithmParametersbyteArray4()
765 throws Exception {
766 AlgorithmParameters ap = AlgorithmParameters.getInstance("DSA");
767 // use pregenerated AlgorithmParameters encodings
768 ap.init(EncryptedPrivateKeyInfoData.getParametersEncoding("DSA"));
769
770 byte[] encryptedDataCopy = EncryptedPrivateKeyInfoData.encryptedData.clone();
771 // pass valid array
772 EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(ap,
773 encryptedDataCopy);
774
775 // modify array passed
776 encryptedDataCopy[0] = (byte) 6;
777
778 // check that internal state has not been affected
779 assertTrue(Arrays.equals(EncryptedPrivateKeyInfoData.encryptedData,
780 epki.getEncryptedData()));
781 }
782
783 /**
784 * Test #1 for <code>getAlgParameters()</code> method <br>
785 * Assertion: returns the algorithm parameters <br>
786 * Test preconditions: test object created using ctor which takes encoded
787 * form as the only parameter; encoded form passed contains algorithm
788 * parameters encoding <br>
789 * Expected: corresponding algorithm parameters must be returned
790 *
791 * @throws IOException
792 */
793 @TestTargetNew(
794 level = TestLevel.PARTIAL_COMPLETE,
795 notes = "This is a complete subset of tests for getAlgParameters method.",
796 method = "getAlgParameters",
797 args = {}
798 )
799 public final void testGetAlgParameters01() throws IOException {
800 boolean performed = false;
801 for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) {
802 try {
803 EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(
804 EncryptedPrivateKeyInfoData
805 .getValidEncryptedPrivateKeyInfoEncoding(
806 EncryptedPrivateKeyInfoData.algName0[i][0]));
807
808 AlgorithmParameters apar = epki.getAlgParameters();
809 if (apar == null) {
810 continue;
811 }
812
813 // check that method under test returns
814 // parameters with the same encoded form
815 assertTrue(Arrays
816 .equals(
817 EncryptedPrivateKeyInfoData
818 .getParametersEncoding(EncryptedPrivateKeyInfoData.algName0[i][0]),
819 apar.getEncoded()));
820 performed = true;
821 } catch (NoSuchAlgorithmException allowedFailure) {
822 }
823 }
824 assertTrue("Test not performed", performed);
825 }
826
827 @TestTargetNew(
828 level = TestLevel.PARTIAL_COMPLETE,
829 notes = "This is a complete subset of tests for getAlgParameters method.",
830 method = "getAlgParameters",
831 args = {}
832 )
833 public final void testGetAlgParameters01_01() throws Exception {
834 byte[] validEncodingWithUnknownAlgOID = EncryptedPrivateKeyInfoData
835 .getValidEncryptedPrivateKeyInfoEncoding("DH");
836 // correct oid value
837 validEncodingWithUnknownAlgOID[18] = 0;
838 EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(
839 validEncodingWithUnknownAlgOID);
840
841 assertNull(epki.getAlgParameters());
842 }
843
844 /**
845 * Test #2 for <code>getAlgParameters()</code> method <br>
846 * Assertion: returns the algorithm parameters <br>
847 * Test preconditions: test object created using ctor which takes encoded
848 * form as the only parameter; encoded form passed does not contain
849 * algorithm parameters encoding <br>
850 * Expected: <code>null</code> must be returned
851 *
852 * @throws IOException
853 */
854 @TestTargetNew(
855 level = TestLevel.PARTIAL_COMPLETE,
856 notes = "This is a complete subset of tests for getAlgParameters method.",
857 method = "getAlgParameters",
858 args = {}
859 )
860 public final void testGetAlgParameters02() throws IOException {
861 boolean performed = false;
862 for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) {
863 try {
864 EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(
865 EncryptedPrivateKeyInfoData
866 .getValidEncryptedPrivateKeyInfoEncoding(
867 EncryptedPrivateKeyInfoData.algName0[i][0],
868 false));
869
870 // check that method under test returns null
871 assertNull(epki.getAlgParameters());
872
873 performed = true;
874 } catch (NoSuchAlgorithmException allowedFailure) {
875 }
876 }
877 assertTrue("Test not performed", performed);
878 }
879
880 /**
881 * Test #3 for <code>getAlgParameters()</code> method <br>
882 * Assertion: returns the algorithm parameters <br>
883 * Test #6 for <code>EncryptedPrivateKeyInfo(String, byte[])</code>
884 * constructor <br>
885 * Assertion: ...This constructor will use null as the value of the
886 * algorithm parameters. <br>
887 * Test preconditions: test object created using ctor which takes algorithm
888 * name and encrypted data as a parameters <br>
889 * Expected: <code>null</code> must be returned
890 *
891 * @throws IOException
892 */
893 @TestTargetNew(
894 level = TestLevel.PARTIAL_COMPLETE,
895 notes = "This is a complete subset of tests for getAlgParameters method.",
896 method = "getAlgParameters",
897 args = {}
898 )
899 public final void testGetAlgParameters03() throws IOException {
900 boolean performed = false;
901 for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) {
902 try {
903 EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(
904 EncryptedPrivateKeyInfoData.algName0[i][0],
905 EncryptedPrivateKeyInfoData.encryptedData);
906
907 // check that method under test returns null
908 // for object constructed in such a way
909 assertNull(epki.getAlgParameters());
910
911 performed = true;
912 } catch (NoSuchAlgorithmException allowedFailure) {
913 }
914 }
915 assertTrue("Test not performed", performed);
916 }
917
918 /**
919 * Test #4 for <code>getAlgParameters()</code> method <br>
920 * Assertion: returns the algorithm parameters <br>
921 * Test preconditions: test object created using ctor which takes
922 * AlgorithmParameters and encrypted data as a parameters; <br>
923 * Expected: the same algorithm parameters as ones passed to the ctor must be
924 * returned
925 *
926 * @throws IOException
927 */
928 @TestTargetNew(
929 level = TestLevel.PARTIAL_COMPLETE,
930 notes = "This is a complete subset of tests for getAlgParameters method.",
931 method = "getAlgParameters",
932 args = {}
933 )
934 public final void testGetAlgParameters04() throws IOException {
935 boolean performed = false;
936 for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) {
937 try {
938 AlgorithmParameters ap = AlgorithmParameters
939 .getInstance(EncryptedPrivateKeyInfoData.algName0[i][0]);
940 // use pregenerated AlgorithmParameters encodings
941 ap
942 .init(EncryptedPrivateKeyInfoData
943 .getParametersEncoding(
944 EncryptedPrivateKeyInfoData.algName0[i][0]));
945
946 EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(ap,
947 EncryptedPrivateKeyInfoData.encryptedData);
948
949 // check that method under test returns
950 // the same parameters instance
951 assertSame(ap, epki.getAlgParameters());
952
953 performed = true;
954 } catch (NoSuchAlgorithmException allowedFailure) {
955 }
956 }
957 assertTrue("Test not performed", performed);
958 }
959
960 /**
961 * Test #1 for <code>getEncryptedData()</code> method <br>
962 * Assertion: returns the encrypted data <br>
963 * Test preconditions: test object created using ctor which takes encoded
964 * form as the only parameter; encoded form passed contains encrypted data
965 * <br>
966 * Expected: the equivalent encrypted data must be returned
967 *
968 * @throws IOException
969 */
970 @TestTargetNew(
971 level = TestLevel.PARTIAL_COMPLETE,
972 notes = "This is a complete subset of tests for getEncryptedData method.",
973 method = "getEncryptedData",
974 args = {}
975 )
976 public final void testGetEncryptedData01() throws IOException {
977 boolean performed = false;
978 for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) {
979 try {
980 EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(
981 EncryptedPrivateKeyInfoData
982 .getValidEncryptedPrivateKeyInfoEncoding(
983 EncryptedPrivateKeyInfoData.algName0[i][0]));
984
985 // check that method under test returns
986 // valid encrypted data
987 assertTrue(Arrays.equals(
988 EncryptedPrivateKeyInfoData.encryptedData, epki
989 .getEncryptedData()));
990
991 performed = true;
992 } catch (NoSuchAlgorithmException allowedFailure) {
993 }
994 }
995 assertTrue("Test not performed", performed);
996 }
997
998 /**
999 * Test #2 for <code>getEncryptedData()</code> method <br>
1000 * Assertion: returns the encrypted data <br>
1001 * Test preconditions: test object created using ctor which takes algorithm
1002 * name and encrypted data as a parameters <br>
1003 * Expected: the equivalent encrypted data must be returned
1004 */
1005 @TestTargetNew(
1006 level = TestLevel.PARTIAL_COMPLETE,
1007 notes = "This is a complete subset of tests for getEncryptedData method.",
1008 method = "getEncryptedData",
1009 args = {}
1010 )
1011 public final void testGetEncryptedData02() {
1012 boolean performed = false;
1013 for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) {
1014 try {
1015 EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(
1016 EncryptedPrivateKeyInfoData.algName0[i][0],
1017 EncryptedPrivateKeyInfoData.encryptedData);
1018
1019 // check that method under test returns
1020 // valid encrypted data
1021 assertTrue(Arrays.equals(
1022 EncryptedPrivateKeyInfoData.encryptedData, epki
1023 .getEncryptedData()));
1024
1025 performed = true;
1026 } catch (NoSuchAlgorithmException allowedFailure) {
1027 }
1028 }
1029 assertTrue("Test not performed", performed);
1030 }
1031
1032 /**
1033 * Test #3 for <code>getEncryptedData()</code> method <br>
1034 * Assertion: returns the encrypted data <br>
1035 * Test preconditions: test object created using ctor which takes algorithm
1036 * parameters and encrypted data as a parameters <br>
1037 * Expected: the equivalent encrypted data must be returned
1038 *
1039 * @throws IOException
1040 */
1041 @TestTargetNew(
1042 level = TestLevel.PARTIAL_COMPLETE,
1043 notes = "This is a complete subset of tests for getEncryptedData method.",
1044 method = "getEncryptedData",
1045 args = {}
1046 )
1047 public final void testGetEncryptedData03() throws IOException {
1048 boolean performed = false;
1049 for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) {
1050 try {
1051 AlgorithmParameters ap = AlgorithmParameters
1052 .getInstance(EncryptedPrivateKeyInfoData.algName0[i][0]);
1053 // use pregenerated AlgorithmParameters encodings
1054 ap.init(EncryptedPrivateKeyInfoData.getParametersEncoding(
1055 EncryptedPrivateKeyInfoData.algName0[i][0]));
1056
1057 EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(ap,
1058 EncryptedPrivateKeyInfoData.encryptedData);
1059
1060 // check that method under test returns
1061 // valid encrypted data
1062 assertTrue(Arrays.equals(
1063 EncryptedPrivateKeyInfoData.encryptedData, epki
1064 .getEncryptedData()));
1065
1066 performed = true;
1067 } catch (NoSuchAlgorithmException allowedFailure) {
1068 }
1069 }
1070 assertTrue("Test not performed", performed);
1071 }
1072
1073 /**
1074 * Test #4 for <code>getEncryptedData()</code> method <br>
1075 * Assertion: returns a new array each time this method is called <br>
1076 * Test preconditions: test object created using ctor which takes algorithm
1077 * name and encrypted data as a parameters <br>
1078 * Expected: refs to encrypted data byte array passed to the ctor and
1079 * returned by the method under test must be different
1080 */
1081 @TestTargetNew(
1082 level = TestLevel.PARTIAL_COMPLETE,
1083 notes = "This is a complete subset of tests for getEncryptedData method.",
1084 method = "getEncryptedData",
1085 args = {}
1086 )
1087 public final void testGetEncryptedData04() {
1088 boolean performed = false;
1089 for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) {
1090 try {
1091 EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(
1092 EncryptedPrivateKeyInfoData.algName0[i][0],
1093 EncryptedPrivateKeyInfoData.encryptedData);
1094
1095 // check that method under test returns
1096 // new array each time
1097 byte[] ecd1 = epki.getEncryptedData();
1098 byte[] ecd2 = epki.getEncryptedData();
1099 assertNotSame(EncryptedPrivateKeyInfoData.encryptedData, ecd1);
1100 assertNotSame(EncryptedPrivateKeyInfoData.encryptedData, ecd2);
1101 assertNotSame(ecd1, ecd2);
1102
1103 performed = true;
1104 } catch (NoSuchAlgorithmException allowedFailure) {
1105 }
1106 }
1107 assertTrue("Test not performed", performed);
1108 }
1109
1110 /**
1111 * Test #1 for <code>getEncoded()</code> method <br>
1112 * Assertion: returns the ASN.1 encoding of this object <br>
1113 * Test preconditions: test object created using ctor which takes encoded
1114 * form as the only parameter <br>
1115 * Expected: equivalent encoded form must be returned
1116 *
1117 * @throws IOException
1118 */
1119 @TestTargetNew(
1120 level = TestLevel.PARTIAL_COMPLETE,
1121 notes = "Can not check IOException",
1122 method = "getEncoded",
1123 args = {}
1124 )
1125 public final void testGetEncoded01() throws IOException {
1126 boolean performed = false;
1127 for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) {
1128 try {
1129 byte[] enc = EncryptedPrivateKeyInfoData
1130 .getValidEncryptedPrivateKeyInfoEncoding(
1131 EncryptedPrivateKeyInfoData.algName0[i][0]);
1132 EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(enc);
1133
1134 // check that method under test returns
1135 // valid encoded form
1136 assertTrue(Arrays.equals(enc, epki.getEncoded()));
1137
1138 performed = true;
1139 } catch (NoSuchAlgorithmException allowedFailure) {
1140 }
1141 }
1142 assertTrue("Test not performed", performed);
1143 }
1144
1145 /**
1146 * Test #2 for <code>getEncoded()</code> method <br>
1147 * Assertion: returns the ASN.1 encoding of this object <br>
1148 * Test preconditions: test object created using ctor which takes algorithm
1149 * name and encrypted data as a parameters <br>
1150 * Expected: equivalent encoded form (without alg params) must be returned
1151 *
1152 * @throws IOException
1153 */
1154 @TestTargetNew(
1155 level = TestLevel.PARTIAL_COMPLETE,
1156 notes = "Can not check IOException",
1157 method = "getEncoded",
1158 args = {}
1159 )
1160 public final void testGetEncoded02() throws IOException {
1161 boolean performed = false;
1162 for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) {
1163 try {
1164 EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(
1165 EncryptedPrivateKeyInfoData.algName0[i][0],
1166 EncryptedPrivateKeyInfoData.encryptedData);
1167
1168 // check that method under test returns
1169 // valid encoded form
1170 byte[] refEnc = EncryptedPrivateKeyInfoData
1171 .getValidEncryptedPrivateKeyInfoEncoding(
1172 EncryptedPrivateKeyInfoData.algName0[i][0],
1173 false);
1174 // System.out.println(Array.toString(refEnc, " "));
1175 byte[] actEnc = epki.getEncoded();
1176 // System.out.println(Array.toString(actEnc, " "));
1177 assertTrue(Arrays.equals(refEnc, actEnc));
1178
1179 performed = true;
1180 } catch (NoSuchAlgorithmException allowedFailure) {
1181 }
1182 }
1183 assertTrue("Test not performed", performed);
1184 }
1185
1186 /**
1187 * Test #3 for <code>getEncoded()</code> method <br>
1188 * Assertion: returns the ASN.1 encoding of this object <br>
1189 * Test preconditions: test object created using ctor which takes algorithm
1190 * name and encrypted data as a parameters <br>
1191 * Expected: equivalent encoded form (without alg params) must be returned
1192 *
1193 * @throws IOException
1194 */
1195 @TestTargetNew(
1196 level = TestLevel.PARTIAL_COMPLETE,
1197 notes = "Can not check IOException",
1198 method = "getEncoded",
1199 args = {}
1200 )
1201 public final void testGetEncoded03() throws IOException {
1202 boolean performed = false;
1203 for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) {
1204 try {
1205 AlgorithmParameters ap = AlgorithmParameters
1206 .getInstance(EncryptedPrivateKeyInfoData.algName0[i][0]);
1207 // use pregenerated AlgorithmParameters encodings
1208 ap.init(EncryptedPrivateKeyInfoData.getParametersEncoding(
1209 EncryptedPrivateKeyInfoData.algName0[i][0]));
1210
1211 EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(ap,
1212 EncryptedPrivateKeyInfoData.encryptedData);
1213
1214 // check that method under test returns
1215 // valid encoded form
1216 assertTrue(Arrays.equals(
1217 EncryptedPrivateKeyInfoData
1218 .getValidEncryptedPrivateKeyInfoEncoding(
1219 EncryptedPrivateKeyInfoData.algName0[i][0]),
1220 epki.getEncoded()));
1221
1222 performed = true;
1223 } catch (NoSuchAlgorithmException allowedFailure) {
1224 }
1225 }
1226 assertTrue("Test not performed", performed);
1227 }
1228
1229 /**
1230 * Test #4 for <code>getEncoded()</code> method <br>
1231 * Assertion: returns a new array each time this method is called <br>
1232 * Test preconditi