use of java.security.DigestException in project robovm by robovm.
the class DigestExceptionTest method testDigestException05.
/**
* Test for <code>DigestException(Throwable)</code> constructor Assertion:
* constructs DigestException when <code>cause</code> is not null
*/
public void testDigestException05() {
DigestException tE = new DigestException(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.DigestException in project robovm by robovm.
the class DigestExceptionTest method testDigestException03.
/**
* Test for <code>DigestException(String)</code> constructor Assertion:
* constructs DigestException when <code>msg</code> is null
*/
public void testDigestException03() {
String msg = null;
DigestException tE = new DigestException(msg);
assertNull("getMessage() must return null.", tE.getMessage());
assertNull("getCause() must return null", tE.getCause());
}
use of java.security.DigestException in project robovm by robovm.
the class DigestExceptionTest method testDigestException09.
/**
* Test for <code>DigestException(String, Throwable)</code> constructor
* Assertion: constructs DigestException when <code>cause</code> is not
* null <code>msg</code> is not null
*/
public void testDigestException09() {
DigestException tE;
for (int i = 0; i < msgs.length; i++) {
tE = new DigestException(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.DigestException in project robovm by robovm.
the class MessageDigest1Test method testSHAProvider.
/**
* Tests SHA MessageDigest provider
*/
public void testSHAProvider() {
MessageDigest md = null;
try {
md = MessageDigest.getInstance("SHA");
} catch (NoSuchAlgorithmException e) {
fail("unexpected exception: " + e);
}
byte[] bytes = new byte[] { 1, 1, 1, 1, 1 };
// testing combination with provider
try {
// offset < 0
md.update(bytes, -1, 1);
fail("No expected IndexOutOfBoundsException");
} catch (IndexOutOfBoundsException e) {
}
try {
md.update(bytes, 1, -1);
fail("No expected IndexOutOfBoundsException");
} catch (IndexOutOfBoundsException e) {
}
//Regression for Harmony-1148
try {
md = MessageDigest.getInstance("SHA");
} catch (NoSuchAlgorithmException e) {
fail("unexpected exception: " + e);
}
try {
// offset < 0
md.digest(bytes, 0, -1);
fail("No expected DigestException");
} catch (DigestException e) {
}
try {
// len < 0
md.digest(bytes, -1, 0);
fail("No expected DigestException");
} catch (DigestException e) {
}
try {
md = MessageDigest.getInstance("UnknownDigest");
fail("expected NoSuchAlgorithmException");
} catch (NoSuchAlgorithmException e) {
// ok
}
}
use of java.security.DigestException in project atlas by alibaba.
the class DexFile method calcSignature.
/**
* Calculates the signature for the {@code .dex} file in the
* given array, and modify the array to contain it.
*
* @param bytes {@code non-null;} the bytes of the file
*/
private static void calcSignature(byte[] bytes) {
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-1");
} catch (NoSuchAlgorithmException ex) {
throw new RuntimeException(ex);
}
md.update(bytes, 32, bytes.length - 32);
try {
int amt = md.digest(bytes, 12, 20);
if (amt != 20) {
throw new RuntimeException("unexpected digest write: " + amt + " bytes");
}
} catch (DigestException ex) {
throw new RuntimeException(ex);
}
}
Aggregations