use of java.security.DigestOutputStream in project j2objc by google.
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 j2objc by google.
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 j2objc by google.
the class DigestOutputStreamTest method test_write$BII_1.
/**
* Test #1 for <code>write(byte[],int,int)</code> method<br>
*
* Assertion: put bytes into output stream<br>
*
* Assertion: updates associated digest<br>
*/
public final void test_write$BII_1() throws IOException {
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);
// write message at once
dos.write(myMessage, 0, MY_MESSAGE_LEN);
// check write
assertTrue("write", Arrays.equals(myMessage, bos.toByteArray()));
// check that associated digest has been updated properly
assertTrue("update", Arrays.equals(dos.getMessageDigest().digest(), MDGoldenData.getDigest(algorithmName[k])));
return;
} catch (NoSuchAlgorithmException e) {
// allowed failure
}
}
fail(getName() + ": no MessageDigest algorithms available - test not performed");
}
use of java.security.DigestOutputStream in project j2objc by google.
the class DigestOutputStreamTest method test_write$BII_3.
/**
* Test #3 for <code>write(byte[],int,int)</code> method<br>
*
* Assertion: put bytes into output stream<br>
*
* Assertion: updates associated digest<br>
*/
public final void test_write$BII_3() throws NoSuchAlgorithmException, IOException {
// check precondition
assertTrue(MY_MESSAGE_LEN % (CHUNK_SIZE + 1) != 0);
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);
// write message by chunks
for (int i = 0; i < MY_MESSAGE_LEN / (CHUNK_SIZE + 1); i++) {
dos.write(myMessage, i * (CHUNK_SIZE + 1), CHUNK_SIZE + 1);
}
// write remaining bytes
dos.write(myMessage, MY_MESSAGE_LEN / (CHUNK_SIZE + 1) * (CHUNK_SIZE + 1), MY_MESSAGE_LEN % (CHUNK_SIZE + 1));
// check write
assertTrue("write", Arrays.equals(myMessage, bos.toByteArray()));
// check that associated digest has been updated properly
assertTrue("update", Arrays.equals(dos.getMessageDigest().digest(), MDGoldenData.getDigest(algorithmName[k])));
return;
} catch (NoSuchAlgorithmException e) {
// allowed failure
}
}
fail(getName() + ": no MessageDigest algorithms available - test not performed");
}
use of java.security.DigestOutputStream in project j2objc by google.
the class DigestOutputStreamTest method testWriteint01.
/**
* Test #1 for <code>write(int)</code> method<br>
*
* Assertion: writes the byte to the output stream<br>
* Assertion: updates associated digest<br>
*/
public final void testWriteint01() throws IOException {
for (int k = 0; k < algorithmName.length; k++) {
try {
MessageDigest md = MessageDigest.getInstance(algorithmName[k]);
ByteArrayOutputStream bos = new ByteArrayOutputStream(MY_MESSAGE_LEN);
DigestOutputStream dos = new DigestOutputStream(bos, md);
for (int i = 0; i < MY_MESSAGE_LEN; i++) {
dos.write(myMessage[i]);
}
// check that bytes have been written correctly
assertTrue("write", Arrays.equals(MDGoldenData.getMessage(), bos.toByteArray()));
// check that associated digest has been updated properly
assertTrue("update", Arrays.equals(dos.getMessageDigest().digest(), MDGoldenData.getDigest(algorithmName[k])));
return;
} catch (NoSuchAlgorithmException e) {
// allowed failure
}
}
fail(getName() + ": no MessageDigest algorithms available - test not performed");
}
Aggregations