use of java.security.AlgorithmParameters in project j2objc by google.
the class AlgorithmParametersTest method test_getParameterSpecLjava_lang_Class.
/**
* java.security.AlgorithmParameters#getParameterSpec(Class)
*/
public void test_getParameterSpecLjava_lang_Class() throws Exception {
final MyAlgorithmParameterSpec myParamSpec = new MyAlgorithmParameterSpec();
MyAlgorithmParameters paramSpi = new MyAlgorithmParameters() {
protected AlgorithmParameterSpec engineGetParameterSpec(Class paramSpec) {
return myParamSpec;
}
};
AlgorithmParameters params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
//
try {
params.getParameterSpec(null);
fail("No expected InvalidParameterSpecException");
} catch (InvalidParameterSpecException e) {
// expected
}
try {
params.getParameterSpec(MyAlgorithmParameterSpec.class);
fail("No expected InvalidParameterSpecException");
} catch (InvalidParameterSpecException e) {
// expected
}
//
// test: corresponding spi method is invoked
//
params.init(new MyAlgorithmParameterSpec());
assertSame(myParamSpec, params.getParameterSpec(MyAlgorithmParameterSpec.class));
//
// test: if paramSpec is null
// Regression test for HARMONY-2733
//
paramSpi = new MyAlgorithmParameters() {
protected AlgorithmParameterSpec engineGetParameterSpec(Class paramSpec) {
// null is passed to spi-provider
assertNull(paramSpec);
return null;
}
};
params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
params.init(new MyAlgorithmParameterSpec());
assertNull(params.getParameterSpec(null));
}
use of java.security.AlgorithmParameters in project j2objc by google.
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");
}
}
use of java.security.AlgorithmParameters in project j2objc by google.
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 j2objc by google.
the class AlgorithmParametersTest method test_getInstanceLjava_lang_StringLjava_lang_String.
/**
* java.security.AlgorithmParameters#getInstance(String, String)
*/
public void test_getInstanceLjava_lang_StringLjava_lang_String() {
String[] alg = { "", "qwertyu", "!@#$%^&*()" };
String[] prv = { "", null };
String[] prv1 = { "1234567890", "qwertyu", "!@#$%^&*()" };
try {
AlgorithmParameters ap = AlgorithmParameters.getInstance("ABC", "MyProvider");
checkUnititialized(ap);
ap.init(new byte[6]);
checkAP(ap, p);
} catch (Exception e) {
fail("Unexpected exception");
}
for (int i = 0; i < alg.length; i++) {
try {
AlgorithmParameters ap = AlgorithmParameters.getInstance(alg[i], "MyProvider");
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]);
}
}
for (int i = 0; i < prv.length; i++) {
try {
AlgorithmParameters ap = AlgorithmParameters.getInstance("ABC", prv[i]);
fail("IllegalArgumentException was not thrown for parameter " + prv[i]);
} catch (IllegalArgumentException iae) {
//expected
} catch (Exception e) {
fail("Incorrect exception " + e + " was thrown for " + prv[i]);
}
}
for (int i = 0; i < prv1.length; i++) {
try {
AlgorithmParameters ap = AlgorithmParameters.getInstance("ABC", prv1[i]);
fail("NoSuchProviderException was not thrown for parameter " + prv1[i]);
} catch (NoSuchProviderException nspe) {
//expected
} catch (Exception e) {
fail("Incorrect exception " + e + " was thrown for " + prv1[i]);
}
}
}
use of java.security.AlgorithmParameters in project j2objc by google.
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
}
}
}
Aggregations