use of java.security.AlgorithmParameters in project j2objc by google.
the class AlgorithmParametersTest method test_getEncoded.
/**
* java.security.AlgorithmParameters#getEncoded()
*/
public void test_getEncoded() throws Exception {
final byte[] enc = new byte[] { 0x02, 0x01, 0x03 };
MyAlgorithmParameters paramSpi = new MyAlgorithmParameters() {
protected byte[] engineGetEncoded() throws IOException {
return enc;
}
};
AlgorithmParameters params = new DummyAlgorithmParameters(paramSpi, p, "algorithm");
//
try {
params.getEncoded();
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());
}
use of java.security.AlgorithmParameters in project j2objc by google.
the class AlgorithmParametersTest method test_getAlgorithm.
/**
* java.security.AlgorithmParameters#getAlgorithm()
*/
public void test_getAlgorithm() throws Exception {
// test: null value
AlgorithmParameters ap = new DummyAlgorithmParameters(null, p, null);
assertNull(ap.getAlgorithm());
// test: not null value
ap = new DummyAlgorithmParameters(null, p, "AAA");
assertEquals("AAA", ap.getAlgorithm());
}
use of java.security.AlgorithmParameters in project j2objc by google.
the class AlgorithmParameterGeneratorSpiTest method testAlgorithmParameterGeneratorSpi01.
/**
* Test for <code>AlgorithmParameterGeneratorSpi</code> constructor
* Assertion: constructs AlgorithmParameterGeneratorSpi
*/
public void testAlgorithmParameterGeneratorSpi01() throws InvalidAlgorithmParameterException {
MyAlgorithmParameterGeneratorSpi algParGen = new MyAlgorithmParameterGeneratorSpi();
AlgorithmParameters param = algParGen.engineGenerateParameters();
assertNull("Not null parameters", param);
AlgorithmParameterSpec pp = null;
algParGen.engineInit(pp, new SecureRandom());
try {
algParGen.engineInit(pp, null);
fail("IllegalArgumentException must be thrown");
} catch (IllegalArgumentException e) {
}
algParGen.engineInit(0, null);
algParGen.engineInit(0, new SecureRandom());
try {
algParGen.engineInit(-10, null);
fail("IllegalArgumentException must be thrown");
} catch (IllegalArgumentException e) {
}
try {
algParGen.engineInit(-10, new SecureRandom());
fail("IllegalArgumentException must be thrown");
} catch (IllegalArgumentException e) {
}
}
use of java.security.AlgorithmParameters in project netty by netty.
the class OpenSslEngineTest method testAlgorithmConstraintsThrows.
@Test(expected = IllegalArgumentException.class)
public void testAlgorithmConstraintsThrows() throws Exception {
SelfSignedCertificate ssc = new SelfSignedCertificate();
serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).sslProvider(sslServerProvider()).build();
SSLEngine engine = serverSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT);
try {
SSLParameters parameters = new SSLParameters();
parameters.setAlgorithmConstraints(new AlgorithmConstraints() {
@Override
public boolean permits(Set<CryptoPrimitive> primitives, String algorithm, AlgorithmParameters parameters) {
return false;
}
@Override
public boolean permits(Set<CryptoPrimitive> primitives, Key key) {
return false;
}
@Override
public boolean permits(Set<CryptoPrimitive> primitives, String algorithm, Key key, AlgorithmParameters parameters) {
return false;
}
});
engine.setSSLParameters(parameters);
} finally {
cleanupServerSslEngine(engine);
ssc.delete();
}
}
use of java.security.AlgorithmParameters in project robovm by robovm.
the class BaseStreamCipher method engineGetParameters.
protected AlgorithmParameters engineGetParameters() {
if (engineParams == null) {
if (pbeSpec != null) {
try {
AlgorithmParameters engineParams = AlgorithmParameters.getInstance(pbeAlgorithm, BouncyCastleProvider.PROVIDER_NAME);
engineParams.init(pbeSpec);
return engineParams;
} catch (Exception e) {
return null;
}
}
}
return engineParams;
}
Aggregations