use of java.security.AlgorithmParameters in project robovm by robovm.
the class EncryptedPrivateKeyInfoTest method testGetAlgParameters04.
/**
* Test #4 for <code>getAlgParameters()</code> method <br>
* Assertion: returns the algorithm parameters <br>
* Test preconditions: test object created using ctor which takes
* AlgorithmParameters and encrypted data as a parameters; <br>
* Expected: the same algorithm parameters as ones passed to the ctor must be
* returned
*
* @throws IOException
*/
public final void testGetAlgParameters04() throws IOException {
boolean performed = false;
for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) {
try {
AlgorithmParameters ap = AlgorithmParameters.getInstance(EncryptedPrivateKeyInfoData.algName0[i][0]);
// use pregenerated AlgorithmParameters encodings
ap.init(EncryptedPrivateKeyInfoData.getParametersEncoding(EncryptedPrivateKeyInfoData.algName0[i][0]));
EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(ap, EncryptedPrivateKeyInfoData.encryptedData);
// check that method under test returns
// the same parameters instance
assertSame(ap, epki.getAlgParameters());
performed = true;
} catch (NoSuchAlgorithmException allowedFailure) {
}
}
assertTrue("Test not performed", performed);
}
use of java.security.AlgorithmParameters in project robovm by robovm.
the class AlgorithmParametersTest method test_getEncodedLjava_lang_String.
/**
* java.security.AlgorithmParameters#getEncoded(String)
*/
public void test_getEncodedLjava_lang_String() throws Exception {
final byte[] enc = new byte[] { 0x02, 0x01, 0x03 };
final String strFormatParam = "format";
MyAlgorithmParameters paramSpi = new MyAlgorithmParameters() {
protected byte[] engineGetEncoded(String format) throws IOException {
assertEquals(strFormatParam, format);
return enc;
}
};
AlgorithmParameters params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
//
try {
params.getEncoded(strFormatParam);
fail("should not get encoded from un-initialized instance");
} catch (IOException e) {
// expected
}
//
// test: corresponding spi method is invoked
//
params.init(new MyAlgorithmParameterSpec());
assertSame(enc, params.getEncoded(strFormatParam));
//
// test: if format param is null
// Regression test for HARMONY-2680
//
paramSpi = new MyAlgorithmParameters() {
protected byte[] engineGetEncoded(String format) throws IOException {
// null is passed to spi-provider
assertNull(format);
return enc;
}
};
params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
params.init(new MyAlgorithmParameterSpec());
assertSame(enc, params.getEncoded(null));
}
use of java.security.AlgorithmParameters in project robovm by robovm.
the class AlgorithmParametersTest method testAlgorithmParametersConst.
/**
* Test for <code>AlgorithmParameters</code> constructor
* Assertion: returns AlgorithmParameters object
*/
public void testAlgorithmParametersConst() throws Exception {
AlgorithmParametersSpi spi = new MyAlgorithmParameters();
AlgorithmParameters ap = new myAlgP(spi, p, "ABC");
checkUnititialized(ap);
ap.init(new byte[6], "aaa");
checkAP(ap, p);
//NULL parameters
try {
ap = new myAlgP(null, null, null);
} catch (Exception e) {
fail("Exception should be not thrown");
}
}
use of java.security.AlgorithmParameters in project robovm by robovm.
the class AlgorithmParametersTest method test_getInstanceLjava_lang_String.
/**
* java.security.AlgorithmParameters#getInstance(String)
*/
public void test_getInstanceLjava_lang_String() {
String[] str = { "", "qwertyu", "!@#$%^&*()" };
try {
AlgorithmParameters ap = AlgorithmParameters.getInstance("ABC");
checkUnititialized(ap);
ap.init(new MyAlgorithmParameterSpec());
checkAP(ap, p);
} catch (Exception e) {
fail("Unexpected exception");
}
for (int i = 0; i < str.length; i++) {
try {
AlgorithmParameters ap = AlgorithmParameters.getInstance(str[i]);
fail("NoSuchAlgorithmException was not thrown for parameter " + str[i]);
} catch (NoSuchAlgorithmException nsae) {
//expected
}
}
}
use of java.security.AlgorithmParameters in project robovm by robovm.
the class AlgorithmParametersTest method test_getInstanceLjava_lang_StringLjava_security_Provider.
/**
* java.security.AlgorithmParameters#getInstance(String, Provider)
*/
public void test_getInstanceLjava_lang_StringLjava_security_Provider() {
String[] alg = { "", "qwertyu", "!@#$%^&*()" };
Provider pp = null;
try {
AlgorithmParameters ap = AlgorithmParameters.getInstance("ABC", p);
checkUnititialized(ap);
ap.init(new byte[6], "aaa");
checkAP(ap, p);
} catch (Exception e) {
fail("Unexpected exception");
}
for (int i = 0; i < alg.length; i++) {
try {
AlgorithmParameters ap = AlgorithmParameters.getInstance(alg[i], p);
fail("NoSuchAlgorithmException was not thrown for parameter " + alg[i]);
} catch (NoSuchAlgorithmException nsae) {
//expected
} catch (Exception e) {
fail("Incorrect exception " + e + " was thrown for " + alg[i]);
}
}
try {
AlgorithmParameters ap = AlgorithmParameters.getInstance("ABC", pp);
fail("IllegalArgumentException was not thrown for NULL provider");
} catch (IllegalArgumentException iae) {
//expected
} catch (Exception e) {
fail("Incorrect exception " + e + " was thrown");
}
}
Aggregations