Search in sources :

Example 1 with ExemptionMechanismException

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

the class ExemptionMechanismExceptionTest method testExemptionMechanismException03.

/**
     * Test for <code>ExemptionMechanismException(String)</code> constructor
     * Assertion: constructs ExemptionMechanismException when <code>msg</code>
     * is null
     */
public void testExemptionMechanismException03() {
    String msg = null;
    ExemptionMechanismException tE = new ExemptionMechanismException(msg);
    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 2 with ExemptionMechanismException

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

the class ExemptionMechanismExceptionTest method testExemptionMechanismException02.

/**
     * Test for <code>ExemptionMechanismException(String)</code> constructor
     * Assertion: constructs ExemptionMechanismException with detail message
     * msg. Parameter <code>msg</code> is not null.
     */
public void testExemptionMechanismException02() {
    ExemptionMechanismException tE;
    for (int i = 0; i < msgs.length; i++) {
        tE = new ExemptionMechanismException(msgs[i]);
        assertEquals("getMessage() must return: ".concat(msgs[i]), tE.getMessage(), msgs[i]);
        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 3 with ExemptionMechanismException

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

the class ExemptionMechanismSpiTest method testExemptionMechanismSpi01.

/**
     * Test for <code>ExemptionMechanismSpi</code> constructor Assertion:
     * constructs ExemptionMechanismSpi
     * @throws Exception
     */
public void testExemptionMechanismSpi01() throws Exception {
    Mock_ExemptionMechanismSpi emSpi = new Mock_ExemptionMechanismSpi() {
    };
    int len = MyExemptionMechanismSpi.getLength();
    byte[] bbRes = emSpi.engineGenExemptionBlob();
    assertEquals("Incorrect length", bbRes.length, len);
    assertEquals("Incorrect result", emSpi.engineGenExemptionBlob(new byte[1], len), len);
    assertEquals("Incorrect output size", 10, emSpi.engineGetOutputSize(100));
    Key key = null;
    AlgorithmParameters params = null;
    AlgorithmParameterSpec parSpec = null;
    try {
        emSpi.engineInit(key);
        fail("InvalidKeyException must be thrown");
    } catch (InvalidKeyException e) {
    }
    try {
        emSpi.engineInit(key, params);
        fail("InvalidKeyException must be thrown");
    } catch (InvalidKeyException e) {
    }
    try {
        emSpi.engineInit(key, parSpec);
        fail("InvalidKeyException must be thrown");
    } catch (InvalidKeyException e) {
    }
    key = ((MyExemptionMechanismSpi) emSpi).new tmp1Key("Proba", new byte[0]);
    try {
        emSpi.engineInit(key);
        fail("ExemptionMechanismException must be thrown");
    } catch (ExemptionMechanismException e) {
    }
    try {
        emSpi.engineInit(key, params);
        fail("ExemptionMechanismException must be thrown");
    } catch (ExemptionMechanismException e) {
    }
    try {
        emSpi.engineInit(key, parSpec);
        fail("ExemptionMechanismException must be thrown");
    } catch (ExemptionMechanismException e) {
    }
    key = ((MyExemptionMechanismSpi) emSpi).new tmpKey("Proba", new byte[0]);
    emSpi.engineInit(key);
    emSpi.engineInit(key, AlgorithmParameters.getInstance("DH"));
    emSpi.engineInit(key, new RSAKeyGenParameterSpec(10, new BigInteger("10")));
    assertEquals("Incorrect result", 10, emSpi.engineGetOutputSize(100));
}
Also used : RSAKeyGenParameterSpec(java.security.spec.RSAKeyGenParameterSpec) BigInteger(java.math.BigInteger) InvalidKeyException(java.security.InvalidKeyException) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec) ExemptionMechanismException(javax.crypto.ExemptionMechanismException) Key(java.security.Key) AlgorithmParameters(java.security.AlgorithmParameters)

Example 4 with ExemptionMechanismException

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

the class ExemptionMechanismTest method test_genExemptionBlob.

public void test_genExemptionBlob() throws InvalidKeyException, ExemptionMechanismException {
    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.genExemptionBlob();
        fail("IllegalStateException expected");
    } catch (IllegalStateException e) {
    //failed
    }
    em.init(key);
    assertNotNull(em.genExemptionBlob());
    em = new ExemptionMechanism(new Mock_ExemptionMechanismSpi(), mProv, defaultAlg) {
    };
    key = new Mock_ExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);
    em.init(key);
    try {
        em.genExemptionBlob();
        fail("ExemptionMechanismException expected");
    } catch (ExemptionMechanismException e) {
    //failed
    }
}
Also used : SpiEngUtils(org.apache.harmony.security.tests.support.SpiEngUtils) MyExemptionMechanismSpi(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi) 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 5 with ExemptionMechanismException

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

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