Search in sources :

Example 6 with SpiEngUtils

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

the class ExemptionMechanismTest method testExemptionMechanism.

/**
     * Test for <code>ExemptionMechanism</code> constructor
     * Assertion: creates new object using provider and mechanism name
     */
public void testExemptionMechanism() throws Exception {
    Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", "Provider for ExemptionMechanism testing", srvExemptionMechanism.concat(".").concat(defaultAlg), ExemptionMechanismProviderClass);
    ExemptionMechanismSpi spi = new MyExemptionMechanismSpi();
    ExemptionMechanism em = new ExemptionMechanism(spi, mProv, defaultAlg) {
    };
    assertEquals("Incorrect provider", em.getProvider(), mProv);
    assertEquals("Incorrect algorithm", em.getName(), defaultAlg);
    try {
        em.init(null);
        fail("InvalidKeyException must be thrown");
    } catch (InvalidKeyException e) {
    }
    try {
        em.getOutputSize(100);
        fail("IllegalStateException must be thrown");
    } catch (IllegalStateException e) {
    }
    em = new ExemptionMechanism(null, null, null) {
    };
    assertNull("Incorrect mechanism", em.getName());
    assertNull("Incorrect provider", em.getProvider());
    try {
        em.init(null);
        fail("NullPointerException must be thrown");
    } catch (NullPointerException e) {
    }
    try {
        em.getOutputSize(100);
        fail("IllegalStateException must be thrown");
    } catch (IllegalStateException e) {
    }
}
Also used : ExemptionMechanismSpi(javax.crypto.ExemptionMechanismSpi) MyExemptionMechanismSpi(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi) SpiEngUtils(org.apache.harmony.security.tests.support.SpiEngUtils) InvalidKeyException(java.security.InvalidKeyException) MyExemptionMechanismSpi(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi) ExemptionMechanism(javax.crypto.ExemptionMechanism) Provider(java.security.Provider)

Example 7 with SpiEngUtils

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

the class ExemptionMechanismTest method test_initLjava_security_KeyLjava_security_AlgorithmParameters.

public void test_initLjava_security_KeyLjava_security_AlgorithmParameters() throws Exception {
    Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", "Provider for ExemptionMechanism testing", srvExemptionMechanism.concat(".").concat(defaultAlg), ExemptionMechanismProviderClass);
    ExemptionMechanism em = new ExemptionMechanism(new MyExemptionMechanismSpi(), mProv, defaultAlg) {
    };
    Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);
    em.init(key, AlgorithmParameters.getInstance("DES"));
    try {
        em.init(key, (AlgorithmParameters) null);
        fail("InvalidAlgorithmParameterException expected");
    } catch (InvalidAlgorithmParameterException e) {
    //expected
    }
    KeyGenerator kg = KeyGenerator.getInstance("DES");
    kg.init(56, new SecureRandom());
    key = kg.generateKey();
    try {
        em.init(null, AlgorithmParameters.getInstance("DES"));
        fail("InvalidKeyException expected");
    } catch (InvalidKeyException e) {
    //expected
    }
    try {
        em.init(key, AlgorithmParameters.getInstance("DES"));
        fail("ExemptionMechanismException expected");
    } catch (ExemptionMechanismException e) {
    //expected
    }
}
Also used : SpiEngUtils(org.apache.harmony.security.tests.support.SpiEngUtils) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) SecureRandom(java.security.SecureRandom) InvalidKeyException(java.security.InvalidKeyException) MyExemptionMechanismSpi(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi) KeyGenerator(javax.crypto.KeyGenerator) ExemptionMechanismException(javax.crypto.ExemptionMechanismException) ExemptionMechanism(javax.crypto.ExemptionMechanism) MyExemptionMechanismSpi.tmpKey(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey) Key(java.security.Key) MyExemptionMechanismSpi.tmpKey(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey) Provider(java.security.Provider)

Example 8 with SpiEngUtils

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

the class ExemptionMechanismTest method test_getOutputSizeI.

public void test_getOutputSizeI() throws Exception {
    Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", "Provider for ExemptionMechanism testing", srvExemptionMechanism.concat(".").concat(defaultAlg), ExemptionMechanismProviderClass);
    ExemptionMechanism em = new ExemptionMechanism(new MyExemptionMechanismSpi(), mProv, defaultAlg) {
    };
    Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);
    try {
        em.getOutputSize(10);
        fail("IllegalStateException expected");
    } catch (IllegalStateException e) {
    //failed
    }
    em.init(key);
    assertEquals(10, em.getOutputSize(10));
}
Also used : SpiEngUtils(org.apache.harmony.security.tests.support.SpiEngUtils) MyExemptionMechanismSpi(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi) ExemptionMechanism(javax.crypto.ExemptionMechanism) MyExemptionMechanismSpi.tmpKey(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey) Key(java.security.Key) MyExemptionMechanismSpi.tmpKey(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey) Provider(java.security.Provider)

Example 9 with SpiEngUtils

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

the class ExemptionMechanismTest method test_initLjava_security_KeyLjava_security_spec_AlgorithmParameterSpec.

public void test_initLjava_security_KeyLjava_security_spec_AlgorithmParameterSpec() throws Exception {
    Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", "Provider for ExemptionMechanism testing", srvExemptionMechanism.concat(".").concat(defaultAlg), ExemptionMechanismProviderClass);
    ExemptionMechanism em = new ExemptionMechanism(new MyExemptionMechanismSpi(), mProv, defaultAlg) {
    };
    Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);
    em.init(key, new RSAKeyGenParameterSpec(10, new BigInteger("10")));
    try {
        em.init(key, (AlgorithmParameterSpec) null);
        fail("InvalidAlgorithmParameterException expected");
    } catch (InvalidAlgorithmParameterException e) {
    //expected
    }
    KeyGenerator kg = KeyGenerator.getInstance("DES");
    kg.init(56, new SecureRandom());
    key = kg.generateKey();
    try {
        em.init(null, new RSAKeyGenParameterSpec(10, new BigInteger("10")));
        fail("InvalidKeyException expected");
    } catch (InvalidKeyException e) {
    //expected
    }
    try {
        em.init(key, new RSAKeyGenParameterSpec(10, new BigInteger("10")));
        fail("ExemptionMechanismException expected");
    } catch (ExemptionMechanismException e) {
    //expected
    }
}
Also used : SpiEngUtils(org.apache.harmony.security.tests.support.SpiEngUtils) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) RSAKeyGenParameterSpec(java.security.spec.RSAKeyGenParameterSpec) SecureRandom(java.security.SecureRandom) InvalidKeyException(java.security.InvalidKeyException) MyExemptionMechanismSpi(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi) ExemptionMechanism(javax.crypto.ExemptionMechanism) MyExemptionMechanismSpi.tmpKey(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey) Provider(java.security.Provider) BigInteger(java.math.BigInteger) KeyGenerator(javax.crypto.KeyGenerator) ExemptionMechanismException(javax.crypto.ExemptionMechanismException) MyExemptionMechanismSpi.tmpKey(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey) Key(java.security.Key)

Example 10 with SpiEngUtils

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

the class ExemptionMechanismTest method test_getName.

public void test_getName() throws Exception {
    Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", "Provider for ExemptionMechanism testing", srvExemptionMechanism.concat(".").concat(defaultAlg), ExemptionMechanismProviderClass);
    ExemptionMechanism em = new ExemptionMechanism(new MyExemptionMechanismSpi(), mProv, defaultAlg) {
    };
    Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);
    assertEquals(defaultAlg, em.getName());
}
Also used : SpiEngUtils(org.apache.harmony.security.tests.support.SpiEngUtils) MyExemptionMechanismSpi(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi) ExemptionMechanism(javax.crypto.ExemptionMechanism) MyExemptionMechanismSpi.tmpKey(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey) Key(java.security.Key) MyExemptionMechanismSpi.tmpKey(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey) Provider(java.security.Provider)

Aggregations

SpiEngUtils (org.apache.harmony.security.tests.support.SpiEngUtils)23 Provider (java.security.Provider)14 ExemptionMechanism (javax.crypto.ExemptionMechanism)14 Key (java.security.Key)11 MyExemptionMechanismSpi.tmpKey (org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey)11 MyExemptionMechanismSpi (org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi)10 ExemptionMechanismException (javax.crypto.ExemptionMechanismException)6 InvalidKeyException (java.security.InvalidKeyException)4 SecureRandom (java.security.SecureRandom)3 KeyGenerator (javax.crypto.KeyGenerator)3 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 ShortBufferException (javax.crypto.ShortBufferException)2 BigInteger (java.math.BigInteger)1 RSAKeyGenParameterSpec (java.security.spec.RSAKeyGenParameterSpec)1 ExemptionMechanismSpi (javax.crypto.ExemptionMechanismSpi)1 MyProvider (tests.security.cert.myCertPathBuilder.MyProvider)1