use of org.apache.harmony.security.tests.support.MyKeyPairGenerator1 in project robovm by robovm.
the class KeyPairGenerator1Test method testKeyPairGenerator12.
/**
* Test for methods: <code>initialize(int keysize)</code>
* <code>initialize(int keysize, SecureRandom random)</code>
* <code>initialize(AlgorithmParameterSpec param)</code>
* <code>initialize(AlgorithmParameterSpec param, SecureRandom random)</code>
* <code>generateKeyPair()</code>
* <code>genKeyPair()</code>
* Assertion: throws InvalidParameterException or
* InvalidAlgorithmParameterException when parameters keysize or param are
* incorrect Assertion: generateKeyPair() and genKeyPair() return null
* KeyPair Additional class MyKeyPairGenerator1 is used
*/
public void testKeyPairGenerator12() {
int[] keys = { -1, -250, 1, 64, 512, 1024 };
SecureRandom random = new SecureRandom();
AlgorithmParameterSpec aps;
KeyPairGenerator mKPG = new MyKeyPairGenerator1("");
assertEquals("Incorrect algorithm", mKPG.getAlgorithm(), MyKeyPairGenerator1.getResAlgorithm());
mKPG.generateKeyPair();
mKPG.genKeyPair();
for (int i = 0; i < keys.length; i++) {
try {
mKPG.initialize(keys[i]);
fail("InvalidParameterException must be thrown (key: " + Integer.toString(keys[i]) + ")");
} catch (InvalidParameterException e) {
}
try {
mKPG.initialize(keys[i], random);
fail("InvalidParameterException must be thrown (key: " + Integer.toString(keys[i]) + ")");
} catch (InvalidParameterException e) {
}
}
try {
mKPG.initialize(100, null);
fail("InvalidParameterException must be thrown when random is null");
} catch (InvalidParameterException e) {
}
mKPG.initialize(100, random);
assertEquals("Incorrect random", random, ((MyKeyPairGenerator1) mKPG).secureRandom);
assertEquals("Incorrect keysize", 100, ((MyKeyPairGenerator1) mKPG).keySize);
try {
mKPG.initialize(null, random);
fail("InvalidAlgorithmParameterException must be thrown when param is null");
} catch (InvalidAlgorithmParameterException e) {
}
if (DSASupported) {
BigInteger bInt = new BigInteger("1");
aps = new java.security.spec.DSAParameterSpec(bInt, bInt, bInt);
try {
mKPG.initialize(aps, null);
fail("InvalidParameterException must be thrown when random is null");
} catch (InvalidParameterException e) {
} catch (InvalidAlgorithmParameterException e) {
fail("Unexpected InvalidAlgorithmParameterException was thrown");
}
try {
mKPG.initialize(aps, random);
assertEquals("Incorrect random", random, ((MyKeyPairGenerator1) mKPG).secureRandom);
assertEquals("Incorrect params", aps, ((MyKeyPairGenerator1) mKPG).paramSpec);
} catch (InvalidAlgorithmParameterException e) {
fail("Unexpected InvalidAlgorithmParameterException was thrown");
}
}
}
Aggregations