use of java.security.AlgorithmParameters in project robovm by robovm.
the class AlgorithmParametersTest method test_toString.
/**
* java.security.AlgorithmParameters#toString()
*/
public void test_toString() throws Exception {
final String str = "AlgorithmParameters";
MyAlgorithmParameters paramSpi = new MyAlgorithmParameters() {
protected String engineToString() {
return str;
}
};
AlgorithmParameters params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
assertNull("unititialized", params.toString());
params.init(new byte[0]);
assertSame(str, params.toString());
}
use of java.security.AlgorithmParameters in project robovm by robovm.
the class AlgorithmParametersTest method test_getProvider.
/**
* java.security.AlgorithmParameters#getProvider()
*/
public void test_getProvider() throws Exception {
// test: null value
AlgorithmParameters ap = new DummyAlgorithmParameters(null, null, "AAA");
assertNull(ap.getProvider());
// test: not null value
ap = new DummyAlgorithmParameters(null, p, "AAA");
assertSame(p, ap.getProvider());
}
use of java.security.AlgorithmParameters in project robovm by robovm.
the class AlgorithmParametersTest method testDSAProvider.
/**
* Tests DSA AlgorithmParameters provider
*/
public void testDSAProvider() throws Exception {
AlgorithmParameters params = AlgorithmParameters.getInstance("DSA");
assertEquals("Algorithm", "DSA", params.getAlgorithm());
// init(AlgorithmParameterSpec)
BigInteger p = BigInteger.ONE;
BigInteger q = BigInteger.TEN;
BigInteger g = BigInteger.ZERO;
params.init(new DSAParameterSpec(p, q, g));
// getEncoded() and getEncoded(String) (TODO verify returned encoding)
byte[] enc = params.getEncoded();
assertNotNull(enc);
assertNotNull(params.getEncoded("ASN.1"));
// TODO assertNotNull(params.getEncoded(null)); // HARMONY-2680
// getParameterSpec(Class)
DSAParameterSpec spec = params.getParameterSpec(DSAParameterSpec.class);
assertEquals("p is wrong ", p, spec.getP());
assertEquals("q is wrong ", q, spec.getQ());
assertEquals("g is wrong ", g, spec.getG());
// init(byte[])
params = AlgorithmParameters.getInstance("DSA");
params.init(enc);
assertTrue("param encoded is different", Arrays.equals(enc, params.getEncoded()));
// init(byte[], String)
params = AlgorithmParameters.getInstance("DSA");
params.init(enc, "ASN.1");
assertTrue("param encoded is different", Arrays.equals(enc, params.getEncoded()));
params = AlgorithmParameters.getInstance("DSA");
try {
params.init(enc, "DOUGLASMAWSON");
fail("unsupported format should have raised IOException");
} catch (IOException e) {
// expected
}
}
use of java.security.AlgorithmParameters in project robovm by robovm.
the class AlgorithmParametersTest method test_initLjava_security_spec_AlgorithmParameterSpec.
/**
* java.security.AlgorithmParameters#init(java.security.spec.AlgorithmParameterSpec)
*/
public void test_initLjava_security_spec_AlgorithmParameterSpec() throws Exception {
//
// test: corresponding spi method is invoked
//
final MyAlgorithmParameterSpec spec = new MyAlgorithmParameterSpec();
MyAlgorithmParameters paramSpi = new MyAlgorithmParameters() {
protected void engineInit(AlgorithmParameterSpec paramSpec) throws InvalidParameterSpecException {
assertSame(spec, paramSpec);
runEngineInit_AlgParamSpec = true;
}
};
AlgorithmParameters params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
params.init(spec);
assertTrue(paramSpi.runEngineInit_AlgParamSpec);
//
try {
params.init(spec);
fail("No expected InvalidParameterSpecException");
} catch (InvalidParameterSpecException e) {
// expected
}
params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
params.init(new byte[0]);
try {
params.init(spec);
fail("No expected InvalidParameterSpecException");
} catch (InvalidParameterSpecException e) {
// expected
}
params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
params.init(new byte[0], "format");
try {
params.init(spec);
fail("No expected InvalidParameterSpecException");
} catch (InvalidParameterSpecException e) {
// expected
}
//
// test: if paramSpec is null
//
paramSpi = new MyAlgorithmParameters() {
protected void engineInit(AlgorithmParameterSpec paramSpec) throws InvalidParameterSpecException {
// null is passed to spi-provider
assertNull(paramSpec);
runEngineInit_AlgParamSpec = true;
}
};
params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
params.init((AlgorithmParameterSpec) null);
assertTrue(paramSpi.runEngineInit_AlgParamSpec);
}
use of java.security.AlgorithmParameters in project robovm by robovm.
the class AlgorithmParametersTest method test_init$B.
/**
* java.security.AlgorithmParameters#init(byte[])
*/
public void test_init$B() throws Exception {
//
// test: corresponding spi method is invoked
//
final byte[] enc = new byte[] { 0x02, 0x01, 0x03 };
MyAlgorithmParameters paramSpi = new MyAlgorithmParameters() {
protected void engineInit(byte[] params) throws IOException {
runEngineInitB$ = true;
assertSame(enc, params);
}
};
AlgorithmParameters params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
params.init(enc);
assertTrue(paramSpi.runEngineInitB$);
//
try {
params.init(enc);
fail("No expected IOException");
} catch (IOException e) {
// expected
}
params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
params.init(new MyAlgorithmParameterSpec());
try {
params.init(enc);
fail("No expected IOException");
} catch (IOException e) {
// expected
}
params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
params.init(enc, "format");
try {
params.init(enc);
fail("No expected IOException");
} catch (IOException e) {
// expected
}
//
// test: if params is null
//
paramSpi = new MyAlgorithmParameters() {
protected void engineInit(byte[] params) throws IOException {
runEngineInitB$ = true;
// null is passed to spi-provider
assertNull(params);
}
};
params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
params.init((byte[]) null);
assertTrue(paramSpi.runEngineInitB$);
}
Aggregations