Search in sources :

Example 1 with MyKeyPairGenerator2

use of org.apache.harmony.security.tests.support.MyKeyPairGenerator2 in project robovm by robovm.

the class KeyPairGenerator1Test method testKeyPairGenerator13.

/**
     * 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: initialize(int ...) throws InvalidParameterException when
     * keysize in incorrect Assertion: initialize(AlgorithmParameterSpec
     * ...)throws UnsupportedOperationException Assertion: generateKeyPair() and
     * genKeyPair() return not null KeyPair Additional class MyKeyPairGenerator2
     * is used
     */
public void testKeyPairGenerator13() {
    int[] keys = { -1, -250, 1, 63, -512, -1024 };
    SecureRandom random = new SecureRandom();
    KeyPairGenerator mKPG = new MyKeyPairGenerator2(null);
    assertEquals("Algorithm must be null", mKPG.getAlgorithm(), MyKeyPairGenerator2.getResAlgorithm());
    assertNull("genKeyPair() must return null", mKPG.genKeyPair());
    assertNull("generateKeyPair() mut return null", mKPG.generateKeyPair());
    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(64);
    } catch (InvalidParameterException e) {
        fail("Unexpected InvalidParameterException was thrown");
    }
    try {
        mKPG.initialize(64, null);
    } catch (InvalidParameterException e) {
        fail("Unexpected InvalidParameterException was thrown");
    }
    try {
        mKPG.initialize(null, random);
    } catch (UnsupportedOperationException e) {
    // on j2se1.4 this exception is not thrown
    } catch (InvalidAlgorithmParameterException e) {
        fail("Unexpected InvalidAlgorithmParameterException was thrown");
    }
}
Also used : MyKeyPairGenerator2(org.apache.harmony.security.tests.support.MyKeyPairGenerator2) InvalidParameterException(java.security.InvalidParameterException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) SecureRandom(java.security.SecureRandom) KeyPairGenerator(java.security.KeyPairGenerator)

Example 2 with MyKeyPairGenerator2

use of org.apache.harmony.security.tests.support.MyKeyPairGenerator2 in project j2objc by google.

the class KeyPairGenerator1Test method testKeyPairGenerator13.

/**
 * 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: initialize(int ...) throws InvalidParameterException when
 * keysize in incorrect Assertion: initialize(AlgorithmParameterSpec
 * ...)throws UnsupportedOperationException Assertion: generateKeyPair() and
 * genKeyPair() return not null KeyPair Additional class MyKeyPairGenerator2
 * is used
 */
public void testKeyPairGenerator13() {
    int[] keys = { -1, -250, 1, 63, -512, -1024 };
    SecureRandom random = new SecureRandom();
    KeyPairGenerator mKPG = new MyKeyPairGenerator2(null);
    assertEquals("Algorithm must be null", mKPG.getAlgorithm(), MyKeyPairGenerator2.getResAlgorithm());
    assertNull("genKeyPair() must return null", mKPG.genKeyPair());
    assertNull("generateKeyPair() mut return null", mKPG.generateKeyPair());
    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(64);
    } catch (InvalidParameterException e) {
        fail("Unexpected InvalidParameterException was thrown");
    }
    try {
        mKPG.initialize(64, null);
    } catch (InvalidParameterException e) {
        fail("Unexpected InvalidParameterException was thrown");
    }
    try {
        mKPG.initialize(null, random);
    } catch (UnsupportedOperationException e) {
    // on j2se1.4 this exception is not thrown
    } catch (InvalidAlgorithmParameterException e) {
        fail("Unexpected InvalidAlgorithmParameterException was thrown");
    }
}
Also used : MyKeyPairGenerator2(org.apache.harmony.security.tests.support.MyKeyPairGenerator2) InvalidParameterException(java.security.InvalidParameterException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) SecureRandom(java.security.SecureRandom) KeyPairGenerator(java.security.KeyPairGenerator)

Aggregations

InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)2 InvalidParameterException (java.security.InvalidParameterException)2 KeyPairGenerator (java.security.KeyPairGenerator)2 SecureRandom (java.security.SecureRandom)2 MyKeyPairGenerator2 (org.apache.harmony.security.tests.support.MyKeyPairGenerator2)2