use of java.security.AlgorithmParameters in project robovm by robovm.
the class EncryptedPrivateKeyInfoTest method testGetAlgParameters01.
/**
* Test #1 for <code>getAlgParameters()</code> method <br>
* Assertion: returns the algorithm parameters <br>
* Test preconditions: test object created using ctor which takes encoded
* form as the only parameter; encoded form passed contains algorithm
* parameters encoding <br>
* Expected: corresponding algorithm parameters must be returned
*
* @throws IOException
*/
public final void testGetAlgParameters01() throws IOException {
boolean performed = false;
for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) {
try {
EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(EncryptedPrivateKeyInfoData.getValidEncryptedPrivateKeyInfoEncoding(EncryptedPrivateKeyInfoData.algName0[i][0]));
AlgorithmParameters apar = epki.getAlgParameters();
if (apar == null) {
continue;
}
// check that method under test returns
// parameters with the same encoded form
assertTrue(Arrays.equals(EncryptedPrivateKeyInfoData.getParametersEncoding(EncryptedPrivateKeyInfoData.algName0[i][0]), apar.getEncoded()));
performed = true;
} catch (NoSuchAlgorithmException allowedFailure) {
}
}
assertTrue("Test not performed", performed);
}
use of java.security.AlgorithmParameters in project robovm by robovm.
the class EncryptedPrivateKeyInfoTest method testEncryptedPrivateKeyInfoAlgorithmParametersbyteArray1.
/**
* Test #1 for
* <code>EncryptedPrivateKeyInfo(java.security.AlgorithmParameters, byte[])
* </code>
* constructor <br>
* Assertion: creates <code>EncryptedPrivateKeyInfo</code> instance <br>
* Test preconditions: valid parameters passed <br>
* Expected: must pass without any exceptions
*
* @throws IOException
* @throws NoSuchAlgorithmException
*/
public final void testEncryptedPrivateKeyInfoAlgorithmParametersbyteArray1() throws IOException, NoSuchAlgorithmException {
AlgorithmParameters ap = null;
boolean performed = false;
for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) {
try {
ap = AlgorithmParameters.getInstance(EncryptedPrivateKeyInfoData.algName0[i][0]);
// use pregenerated AlgorithmParameters encodings
ap.init(EncryptedPrivateKeyInfoData.getParametersEncoding(EncryptedPrivateKeyInfoData.algName0[i][0]));
new EncryptedPrivateKeyInfo(ap, EncryptedPrivateKeyInfoData.encryptedData);
performed = true;
} catch (NoSuchAlgorithmException allowedFailure) {
}
}
assertTrue("Test not performed", performed);
ap = new Mock_AlgorithmParameters(null, null, "Wrong alg name");
try {
new EncryptedPrivateKeyInfo(ap, EncryptedPrivateKeyInfoData.encryptedData);
fail("NoSuchAlgorithmException expected");
} catch (NoSuchAlgorithmException e) {
//expected
}
}
use of java.security.AlgorithmParameters in project robovm by robovm.
the class EncryptedPrivateKeyInfoTest method testGetEncryptedData03.
/**
* Test #3 for <code>getEncryptedData()</code> method <br>
* Assertion: returns the encrypted data <br>
* Test preconditions: test object created using ctor which takes algorithm
* parameters and encrypted data as a parameters <br>
* Expected: the equivalent encrypted data must be returned
*
* @throws IOException
*/
public final void testGetEncryptedData03() 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
// valid encrypted data
assertTrue(Arrays.equals(EncryptedPrivateKeyInfoData.encryptedData, epki.getEncryptedData()));
performed = true;
} catch (NoSuchAlgorithmException allowedFailure) {
}
}
assertTrue("Test not performed", performed);
}
use of java.security.AlgorithmParameters in project robovm by robovm.
the class EncryptedPrivateKeyInfoTest method testEncryptedPrivateKeyInfoAlgorithmParametersbyteArray3.
/**
* Test #3 for
* <code>EncryptedPrivateKeyInfo(java.security.AlgorithmParameters, byte[])
* </code>
* constructor <br>
* Assertion: <code>IllegalArgumentException</code>- if encrypted data is
* empty, i.e. 0-length <br>
* Test preconditions: pass empty encrypted data <br>
* Expected: <code>IllegalArgumentException</code>
*
* @throws NoSuchAlgorithmException
* @throws IOException
*/
public final void testEncryptedPrivateKeyInfoAlgorithmParametersbyteArray3() throws Exception {
try {
AlgorithmParameters ap = AlgorithmParameters.getInstance("DSA");
// use pregenerated AlgorithmParameters encodings
ap.init(EncryptedPrivateKeyInfoData.getParametersEncoding("DSA"));
new EncryptedPrivateKeyInfo(ap, new byte[] {});
fail(getName() + ": IllegalArgumentException has not been thrown");
} catch (IllegalArgumentException ok) {
}
}
use of java.security.AlgorithmParameters in project robovm by robovm.
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) {
}
}
Aggregations