use of org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi 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
}
}
use of org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi in project robovm by robovm.
the class ExemptionMechanismTest method testIsCryptoAllowed.
/**
* Test for <code>isCryptoAllowed(Key key)</code> method
*/
public void testIsCryptoAllowed() throws Exception {
//Regression for HARMONY-1029
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]);
assertFalse(em.isCryptoAllowed(key));
em.init(key);
assertFalse(em.isCryptoAllowed(key));
em.genExemptionBlob();
assertTrue(em.isCryptoAllowed(key));
Key key1 = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[] { 1 });
assertFalse(em.isCryptoAllowed(key1));
em.init(key1);
assertFalse(em.isCryptoAllowed(key));
}
use of org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi in project robovm by robovm.
the class ExemptionMechanismTest method test_getProvider.
public void test_getProvider() 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(mProv, em.getProvider());
}
use of org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi 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) {
}
}
use of org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi 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
}
}
Aggregations