use of java.security.spec.InvalidKeySpecException in project robovm by robovm.
the class InvalidKeySpecExceptionTest method testInvalidKeySpecException03.
/**
* Test for <code>InvalidKeySpecException(String)</code> constructor
* Assertion: constructs InvalidKeySpecException when <code>msg</code> is
* null
*/
public void testInvalidKeySpecException03() {
String msg = null;
InvalidKeySpecException tE = new InvalidKeySpecException(msg);
assertNull("getMessage() must return null.", tE.getMessage());
assertNull("getCause() must return null", tE.getCause());
}
use of java.security.spec.InvalidKeySpecException in project robovm by robovm.
the class InvalidKeySpecExceptionTest method testInvalidKeySpecException09.
/**
* Test for <code>InvalidKeySpecException(String, Throwable)</code>
* constructor Assertion: constructs InvalidKeySpecException when
* <code>cause</code> is not null <code>msg</code> is not null
*/
public void testInvalidKeySpecException09() {
InvalidKeySpecException tE;
for (int i = 0; i < msgs.length; i++) {
tE = new InvalidKeySpecException(msgs[i], tCause);
String getM = tE.getMessage();
String toS = tCause.toString();
if (msgs[i].length() > 0) {
assertTrue("getMessage() must contain ".concat(msgs[i]), getM.indexOf(msgs[i]) != -1);
if (!getM.equals(msgs[i])) {
assertTrue("getMessage() should contain ".concat(toS), getM.indexOf(toS) != -1);
}
}
assertNotNull("getCause() must not return null", tE.getCause());
assertEquals("getCause() must return ".concat(tCause.toString()), tE.getCause(), tCause);
}
}
use of java.security.spec.InvalidKeySpecException in project robovm by robovm.
the class InvalidKeySpecExceptionTest method testInvalidKeySpecException04.
/**
* Test for <code>InvalidKeySpecException(Throwable)</code> constructor
* Assertion: constructs InvalidKeySpecException when <code>cause</code>
* is null
*/
public void testInvalidKeySpecException04() {
Throwable cause = null;
InvalidKeySpecException tE = new InvalidKeySpecException(cause);
assertNull("getMessage() must return null.", tE.getMessage());
assertNull("getCause() must return null", tE.getCause());
}
use of java.security.spec.InvalidKeySpecException in project robovm by robovm.
the class InvalidKeySpecExceptionTest method testInvalidKeySpecException06.
/**
* Test for <code>InvalidKeySpecException(String, Throwable)</code>
* constructor Assertion: constructs InvalidKeySpecException when
* <code>cause</code> is null <code>msg</code> is null
*/
public void testInvalidKeySpecException06() {
InvalidKeySpecException tE = new InvalidKeySpecException(null, null);
assertNull("getMessage() must return null", tE.getMessage());
assertNull("getCause() must return null", tE.getCause());
}
use of java.security.spec.InvalidKeySpecException in project robovm by robovm.
the class mySecretKeyFactory method testSecretKeyFactory10.
/**
* Test for <code>generateSecret(KeySpec keySpec)</code> and
* <code>getKeySpec(SecretKey key, Class keySpec)
* methods
* Assertion:
* throw InvalidKeySpecException if parameter is inappropriate
*/
public void testSecretKeyFactory10() throws InvalidKeyException, InvalidKeySpecException {
if (!DEFSupported) {
fail(NotSupportMsg);
return;
}
byte[] bb = new byte[24];
KeySpec ks = (defaultAlgorithm.equals(defaultAlgorithm2) ? (KeySpec) new DESKeySpec(bb) : (KeySpec) new DESedeKeySpec(bb));
KeySpec rks = null;
SecretKeySpec secKeySpec = new SecretKeySpec(bb, defaultAlgorithm);
SecretKey secKey = null;
SecretKeyFactory[] skF = createSKFac();
assertNotNull("SecretKeyFactory object were not created", skF);
for (int i = 0; i < skF.length; i++) {
try {
skF[i].generateSecret(null);
fail("generateSecret(null): InvalidKeySpecException must be thrown");
} catch (InvalidKeySpecException e) {
}
secKey = skF[i].generateSecret(ks);
try {
skF[i].getKeySpec(null, null);
fail("getKeySpec(null,null): InvalidKeySpecException must be thrown");
} catch (InvalidKeySpecException e) {
}
try {
skF[i].getKeySpec(null, ks.getClass());
fail("getKeySpec(null, Class): InvalidKeySpecException must be thrown");
} catch (InvalidKeySpecException e) {
}
try {
skF[i].getKeySpec(secKey, null);
fail("getKeySpec(secKey, null): NullPointerException or InvalidKeySpecException must be thrown");
} catch (InvalidKeySpecException e) {
// Expected
} catch (NullPointerException e) {
// Expected
}
try {
Class c;
if (defaultAlgorithm.equals(defaultAlgorithm2)) {
c = DESedeKeySpec.class;
} else {
c = DESKeySpec.class;
}
skF[i].getKeySpec(secKeySpec, c);
fail("getKeySpec(secKey, Class): InvalidKeySpecException must be thrown");
} catch (InvalidKeySpecException e) {
}
rks = skF[i].getKeySpec(secKeySpec, ks.getClass());
if (defaultAlgorithm.equals(defaultAlgorithm1)) {
assertTrue("Incorrect getKeySpec() result 1", rks instanceof DESedeKeySpec);
} else {
assertTrue("Incorrect getKeySpec() result 1", rks instanceof DESKeySpec);
}
rks = skF[i].getKeySpec(secKey, ks.getClass());
if (defaultAlgorithm.equals(defaultAlgorithm1)) {
assertTrue("Incorrect getKeySpec() result 2", rks instanceof DESedeKeySpec);
} else {
assertTrue("Incorrect getKeySpec() result 2", rks instanceof DESKeySpec);
}
}
}
Aggregations