Search in sources :

Example 1 with MyKeyGeneratorSpi

use of org.apache.harmony.crypto.tests.support.MyKeyGeneratorSpi in project robovm by robovm.

the class myKeyGenerator method testKeyGenerator.

/**
     * Test for <code>KeyGenerator</code> constructor Assertion: returns
     * KeyGenerator object
     */
public void testKeyGenerator() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
    if (!DEFSupported) {
        fail(NotSupportMsg);
        return;
    }
    KeyGeneratorSpi spi = new MyKeyGeneratorSpi();
    KeyGenerator keyG = new myKeyGenerator(spi, defaultProvider, defaultAlgorithm);
    assertEquals("Incorrect algorithm", keyG.getAlgorithm(), defaultAlgorithm);
    assertEquals("Incorrect provider", keyG.getProvider(), defaultProvider);
    AlgorithmParameterSpec params = null;
    int keysize = 0;
    try {
        keyG.init(params, null);
        fail("InvalidAlgorithmParameterException must be thrown");
    } catch (InvalidAlgorithmParameterException e) {
    }
    try {
        keyG.init(keysize, null);
        fail("IllegalArgumentException must be thrown");
    } catch (IllegalArgumentException e) {
    }
    keyG = new myKeyGenerator(null, null, null);
    assertNull("Algorithm must be null", keyG.getAlgorithm());
    assertNull("Provider must be null", keyG.getProvider());
    try {
        keyG.init(params, null);
        fail("NullPointerException must be thrown");
    } catch (NullPointerException e) {
    }
    try {
        keyG.init(keysize, null);
        fail("NullPointerException or InvalidParameterException must be thrown");
    } catch (InvalidParameterException e) {
    } catch (NullPointerException e) {
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) MyKeyGeneratorSpi(org.apache.harmony.crypto.tests.support.MyKeyGeneratorSpi) KeyGeneratorSpi(javax.crypto.KeyGeneratorSpi) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) MyKeyGeneratorSpi(org.apache.harmony.crypto.tests.support.MyKeyGeneratorSpi) KeyGenerator(javax.crypto.KeyGenerator) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec)

Aggregations

InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 InvalidParameterException (java.security.InvalidParameterException)1 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)1 KeyGenerator (javax.crypto.KeyGenerator)1 KeyGeneratorSpi (javax.crypto.KeyGeneratorSpi)1 MyKeyGeneratorSpi (org.apache.harmony.crypto.tests.support.MyKeyGeneratorSpi)1