use of java.security.DigestOutputStream in project robovm by robovm.
the class DigestOutputStreamTest method test_getMessageDigest.
/**
* java.security.DigestOutputStream#getMessageDigest()
*/
public void test_getMessageDigest() {
MessageDigest digest = new MyMessageDigest1();
OutputStream out = new MyOutputStream();
// non-null parameter
DigestOutputStream dos = new DigestOutputStream(out, digest);
assertSame(digest, dos.getMessageDigest());
// null parameter
dos = new DigestOutputStream(out, null);
assertNull("getMessageDigest should have returned null", dos.getMessageDigest());
}
use of java.security.DigestOutputStream in project robovm by robovm.
the class DigestOutputStreamTest method testToString.
/**
* Test for <code>toString()</code> method<br>
* Assertion: returns <code>String</code> representation of this object
*/
public final void testToString() throws NoSuchAlgorithmException {
for (int k = 0; k < algorithmName.length; k++) {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream(MY_MESSAGE_LEN);
MessageDigest md = MessageDigest.getInstance(algorithmName[k]);
DigestOutputStream dos = new DigestOutputStream(bos, md);
assertNotNull(dos.toString());
return;
} catch (NoSuchAlgorithmException e) {
// allowed failure
}
}
fail(getName() + ": no MessageDigest algorithms available - test not performed");
}
use of java.security.DigestOutputStream in project robovm by robovm.
the class DigestOutputStreamTest method test_setMessageDigestLjava_security_MessageDigest.
/**
* java.security.DigestOutputStream#setMessageDigest(MessageDigest)
*/
public void test_setMessageDigestLjava_security_MessageDigest() {
MessageDigest digest = new MyMessageDigest1();
OutputStream out = new MyOutputStream();
DigestOutputStream dos = new DigestOutputStream(out, null);
// non-null parameter
dos.setMessageDigest(digest);
assertSame(digest, dos.getMessageDigest());
// null parameter
dos.setMessageDigest(null);
assertNull("getMessageDigest should have returned null", dos.getMessageDigest());
}
use of java.security.DigestOutputStream in project robovm by robovm.
the class DigestOutputStreamTest method test_write$BII_5.
/**
* java.security.DigestOutputStream#write(byte[], int, int)
*/
public void test_write$BII_5() throws Exception {
// Test for method void java.security.DigestOutputStream.write(byte [],
// int, int)
DigestOutputStream dos = new DigestOutputStream(new ByteArrayOutputStream(), MessageDigest.getInstance("SHA"));
byte[] digestArray = { 23, 43, 44 };
dos.write(digestArray, 1, 1);
byte[] digestResult = dos.getMessageDigest().digest();
byte[] expected = { -87, 121, -17, 16, -52, 111, 106, 54, -33, 107, -118, 50, 51, 7, -18, 59, -78, -30, -37, -100 };
assertTrue("Digest did not return expected result.", Arrays.equals(digestResult, expected));
}
use of java.security.DigestOutputStream in project robovm by robovm.
the class DigestOutputStreamTest method test_write$BII_7.
/**
* java.io.DigestOutputStream#write(byte[], int, int)
*/
public void test_write$BII_7() throws IOException, NoSuchAlgorithmException {
Support_OutputStream sos = new Support_OutputStream(MY_MESSAGE_LEN);
MessageDigest md = MessageDigest.getInstance(algorithmName[0]);
DigestOutputStream dos = new DigestOutputStream(sos, md);
dos.write(myMessage, 0, MY_MESSAGE_LEN);
try {
// Support_OutputStream throws an IOException if the internal
// buffer is full, which it should be now.
dos.write(myMessage, 0, MY_MESSAGE_LEN);
fail("Test 1: IOException expected.");
} catch (IOException e) {
// Expected.
}
}
Aggregations