use of java.security.spec.InvalidKeySpecException in project robovm by robovm.
the class SignatureTest method testSign_SHA1withRSA_Key_EmptyKey_Failure.
public void testSign_SHA1withRSA_Key_EmptyKey_Failure() throws Exception {
KeyFactory kf = KeyFactory.getInstance("RSA");
RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec(null, null);
// Failing on this key early is okay.
final PrivateKey privKey;
try {
privKey = kf.generatePrivate(keySpec);
} catch (NullPointerException e) {
return;
} catch (InvalidKeySpecException e) {
return;
}
Signature sig = Signature.getInstance("SHA1withRSA");
try {
sig.initSign(privKey);
fail("Should throw error when key is empty");
} catch (InvalidKeyException expected) {
}
}
use of java.security.spec.InvalidKeySpecException in project robovm by robovm.
the class EncryptedPrivateKeyInfoTest method testGetKeySpecCipher01.
public final void testGetKeySpecCipher01() {
boolean performed = false;
for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) {
try {
EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(EncryptedPrivateKeyInfoData.algName0[i][0], EncryptedPrivateKeyInfoData.encryptedData);
try {
// check that method under test throws NPE
epki.getKeySpec((Cipher) null);
fail(getName() + "NullPointerException has not been thrown");
} catch (NullPointerException ok) {
} catch (InvalidKeySpecException e) {
fail(getName() + "Unexpected exception: " + e);
}
performed = true;
} catch (NoSuchAlgorithmException allowedFailure) {
}
}
assertTrue("Test not performed", performed);
}
use of java.security.spec.InvalidKeySpecException in project robovm by robovm.
the class InvalidKeySpecExceptionTest method testInvalidKeySpecException01.
/**
* Test for <code>InvalidKeySpecException()</code> constructor Assertion:
* constructs InvalidKeySpecException with no detail message
*/
public void testInvalidKeySpecException01() {
InvalidKeySpecException tE = new InvalidKeySpecException();
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 testInvalidKeySpecException05.
/**
* Test for <code>InvalidKeySpecException(Throwable)</code> constructor
* Assertion: constructs InvalidKeySpecException when <code>cause</code>
* is not null
*/
public void testInvalidKeySpecException05() {
InvalidKeySpecException tE = new InvalidKeySpecException(tCause);
if (tE.getMessage() != null) {
String toS = tCause.toString();
String getM = tE.getMessage();
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 testInvalidKeySpecException07.
/**
* Test for <code>InvalidKeySpecException(String, Throwable)</code>
* constructor Assertion: constructs InvalidKeySpecException when
* <code>cause</code> is null <code>msg</code> is not null
*/
public void testInvalidKeySpecException07() {
InvalidKeySpecException tE;
for (int i = 0; i < msgs.length; i++) {
tE = new InvalidKeySpecException(msgs[i], null);
assertEquals("getMessage() must return: ".concat(msgs[i]), tE.getMessage(), msgs[i]);
assertNull("getCause() must return null", tE.getCause());
}
}
Aggregations