Search in sources :

Example 6 with ExemptionMechanismException

use of javax.crypto.ExemptionMechanismException 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 7 with ExemptionMechanismException

use of javax.crypto.ExemptionMechanismException in project robovm by robovm.

the class ExemptionMechanismExceptionTest method testExemptionMechanismException01.

/**
     * Test for <code>ExemptionMechanismException()</code> constructor
     * Assertion: constructs ExemptionMechanismException with no detail message
     */
public void testExemptionMechanismException01() {
    ExemptionMechanismException tE = new ExemptionMechanismException();
    assertNull("getMessage() must return null.", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
    try {
        throw tE;
    } catch (Exception e) {
        assertTrue(createErr(tE, e), tE.equals(e));
    }
}
Also used : ExemptionMechanismException(javax.crypto.ExemptionMechanismException) ExemptionMechanismException(javax.crypto.ExemptionMechanismException)

Example 8 with ExemptionMechanismException

use of javax.crypto.ExemptionMechanismException in project robovm by robovm.

the class ExemptionMechanismTest method test_initLjava_security_Key.

public void test_initLjava_security_Key() 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);
    KeyGenerator kg = KeyGenerator.getInstance("DES");
    kg.init(56, new SecureRandom());
    key = kg.generateKey();
    try {
        em.init(null);
        fail("InvalidKeyException expected");
    } catch (InvalidKeyException e) {
    //expected
    }
    try {
        em.init(key);
        fail("ExemptionMechanismException expected");
    } catch (ExemptionMechanismException e) {
    //expected
    }
}
Also used : SpiEngUtils(org.apache.harmony.security.tests.support.SpiEngUtils) 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 9 with ExemptionMechanismException

use of javax.crypto.ExemptionMechanismException in project robovm by robovm.

the class ExemptionMechanismTest method test_genExemptionBlob$BI.

public void test_genExemptionBlob$BI() throws InvalidKeyException, ExemptionMechanismException, ShortBufferException {
    Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", "Provider for ExemptionMechanism testing", srvExemptionMechanism.concat(".").concat(defaultAlg), ExemptionMechanismProviderClass);
    ExemptionMechanism em = new ExemptionMechanism(new Mock_ExemptionMechanismSpi(), mProv, defaultAlg) {
    };
    Key key = new Mock_ExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);
    try {
        em.genExemptionBlob(new byte[10], 2);
        fail("IllegalStateException expected");
    } catch (IllegalStateException e) {
    //failed
    }
    em.init(key);
    assertEquals(5, (em.genExemptionBlob(new byte[10], 5)));
    try {
        em.genExemptionBlob(new byte[7], 3);
        fail("ShortBufferException expected");
    } catch (ShortBufferException e) {
    //failed
    }
    byte[] b = new byte[] { 0, 0, 0, 1, 2, 3, 33, 0 };
    try {
        em.genExemptionBlob(b, 3);
        fail("ExemptionMechanismException expected");
    } catch (ExemptionMechanismException e) {
    //failed
    }
}
Also used : SpiEngUtils(org.apache.harmony.security.tests.support.SpiEngUtils) ShortBufferException(javax.crypto.ShortBufferException) 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 10 with ExemptionMechanismException

use of javax.crypto.ExemptionMechanismException in project robovm by robovm.

the class ExemptionMechanismTest method test_genExemptionBlob$B.

public void test_genExemptionBlob$B() throws InvalidKeyException, ExemptionMechanismException, ShortBufferException {
    Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", "Provider for ExemptionMechanism testing", srvExemptionMechanism.concat(".").concat(defaultAlg), ExemptionMechanismProviderClass);
    ExemptionMechanism em = new ExemptionMechanism(new Mock_ExemptionMechanismSpi(), mProv, defaultAlg) {
    };
    Key key = new Mock_ExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);
    try {
        em.genExemptionBlob(new byte[10]);
        fail("IllegalStateException expected");
    } catch (IllegalStateException e) {
    //failed
    }
    em.init(key);
    assertEquals(5, (em.genExemptionBlob(new byte[10])));
    try {
        em.genExemptionBlob(new byte[2]);
        fail("ShortBufferException expected");
    } catch (ShortBufferException e) {
    //failed
    }
    byte[] b = new byte[] { 0, 0, 0, 33, 0 };
    try {
        em.genExemptionBlob(b);
        fail("ExemptionMechanismException expected");
    } catch (ExemptionMechanismException e) {
    //failed
    }
}
Also used : SpiEngUtils(org.apache.harmony.security.tests.support.SpiEngUtils) ShortBufferException(javax.crypto.ShortBufferException) 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)

Aggregations

ExemptionMechanismException (javax.crypto.ExemptionMechanismException)10 Key (java.security.Key)7 Provider (java.security.Provider)6 ExemptionMechanism (javax.crypto.ExemptionMechanism)6 MyExemptionMechanismSpi.tmpKey (org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey)6 SpiEngUtils (org.apache.harmony.security.tests.support.SpiEngUtils)6 InvalidKeyException (java.security.InvalidKeyException)4 MyExemptionMechanismSpi (org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi)4 SecureRandom (java.security.SecureRandom)3 KeyGenerator (javax.crypto.KeyGenerator)3 BigInteger (java.math.BigInteger)2 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)2 RSAKeyGenParameterSpec (java.security.spec.RSAKeyGenParameterSpec)2 ShortBufferException (javax.crypto.ShortBufferException)2 AlgorithmParameters (java.security.AlgorithmParameters)1 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)1