Search in sources :

Example 96 with DigestInputStream

use of java.security.DigestInputStream in project robovm by robovm.

the class DigestInputStream2Test method test_ConstructorLjava_io_InputStreamLjava_security_MessageDigest.

/**
     * java.security.DigestInputStream#DigestInputStream(java.io.InputStream,
     *        java.security.MessageDigest)
     */
public void test_ConstructorLjava_io_InputStreamLjava_security_MessageDigest() {
    // Test for method java.security.DigestInputStream(java.io.InputStream,
    // java.security.MessageDigest)
    DigestInputStream dis = new DigestInputStream(inStream, digest);
    assertNotNull("Constructor returned null instance", dis);
}
Also used : DigestInputStream(java.security.DigestInputStream)

Example 97 with DigestInputStream

use of java.security.DigestInputStream in project robovm by robovm.

the class DigestInputStream2Test method test_read.

/**
     * java.security.DigestInputStream#read()
     */
public void test_read() throws IOException {
    // Test for method int java.security.DigestInputStream.read()
    DigestInputStream dis = new DigestInputStream(inStream, digest);
    // read and compare the data that the inStream has
    int c;
    while ((c = dis.read()) > -1) {
        int d = inStream1.read();
        assertEquals(d, c);
    }
// end while
}
Also used : DigestInputStream(java.security.DigestInputStream)

Example 98 with DigestInputStream

use of java.security.DigestInputStream in project robovm by robovm.

the class DigestInputStream2Test method test_getMessageDigest.

/**
     * java.security.DigestInputStream#getMessageDigest()
     */
public void test_getMessageDigest() {
    // Test for method java.security.MessageDigest
    // java.security.DigestInputStream.getMessageDigest()
    DigestInputStream dis = new DigestInputStream(inStream, digest);
    assertEquals("getMessageDigest returned a bogus result", digest, dis.getMessageDigest());
}
Also used : DigestInputStream(java.security.DigestInputStream)

Example 99 with DigestInputStream

use of java.security.DigestInputStream in project robovm by robovm.

the class DigestInputStream2Test method test_read$BII_Exception.

/**
     * java.security.DigestInputStream#read(byte[], int, int)
     */
public void test_read$BII_Exception() throws IOException {
    DigestInputStream is = new DigestInputStream(inStream, digest);
    byte[] buf = null;
    try {
        is.read(buf, -1, 0);
        fail("Test 1: NullPointerException expected.");
    } catch (NullPointerException e) {
    // Expected.
    }
    buf = new byte[1000];
    try {
        is.read(buf, -1, 0);
        fail("Test 2: IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected.
    }
    try {
        is.read(buf, 0, -1);
        fail("Test 3: IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected.
    }
    try {
        is.read(buf, -1, -1);
        fail("Test 4: IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected.
    }
    try {
        is.read(buf, 0, 1001);
        fail("Test 5: IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected.
    }
    try {
        is.read(buf, 1001, 0);
        fail("Test 6: IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected.
    }
    try {
        is.read(buf, 500, 501);
        fail("Test 7: IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    // Expected.
    }
    is.close();
    Support_ASimpleInputStream sis = new Support_ASimpleInputStream(true);
    is = new DigestInputStream(sis, digest);
    try {
        is.read(buf, 0, 100);
        fail("Test 9: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
    sis.throwExceptionOnNextUse = false;
    is.close();
}
Also used : DigestInputStream(java.security.DigestInputStream) Support_ASimpleInputStream(tests.support.Support_ASimpleInputStream) IOException(java.io.IOException)

Example 100 with DigestInputStream

use of java.security.DigestInputStream in project robovm by robovm.

the class DigestInputStreamTest method testRead02.

/**
     * Test #2 for <code>read()</code> method<br>
     *
     * Assertion: returns -1 if EOS had been
     * reached but not read before method call<br>
     *
     * Assertion: must not update digest if EOS had been
     * reached but not read before method call<br>
     */
public final void testRead02() throws IOException {
    for (int ii = 0; ii < algorithmName.length; ii++) {
        try {
            MessageDigest md = MessageDigest.getInstance(algorithmName[ii]);
            InputStream is = new ByteArrayInputStream(myMessage);
            DigestInputStream dis = new DigestInputStream(is, md);
            for (int i = 0; i < MY_MESSAGE_LEN; i++) {
                dis.read();
            }
            // check that subsequent read() calls return -1 (eos)
            assertEquals("retval1", -1, dis.read());
            assertEquals("retval2", -1, dis.read());
            assertEquals("retval3", -1, dis.read());
            // check that 3 previous read() calls did not update digest
            assertTrue("update", Arrays.equals(dis.getMessageDigest().digest(), MDGoldenData.getDigest(algorithmName[ii])));
            return;
        } catch (NoSuchAlgorithmException e) {
        // allowed failure
        }
    }
    fail(getName() + ": no MessageDigest algorithms available - test not performed");
}
Also used : DigestInputStream(java.security.DigestInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) DigestInputStream(java.security.DigestInputStream) InputStream(java.io.InputStream) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest)

Aggregations

DigestInputStream (java.security.DigestInputStream)179 MessageDigest (java.security.MessageDigest)138 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)84 IOException (java.io.IOException)74 InputStream (java.io.InputStream)57 FileInputStream (java.io.FileInputStream)41 ByteArrayInputStream (java.io.ByteArrayInputStream)40 File (java.io.File)21 BufferedInputStream (java.io.BufferedInputStream)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 FileOutputStream (java.io.FileOutputStream)8 URL (java.net.URL)8 OutputStream (java.io.OutputStream)7 FileNotFoundException (java.io.FileNotFoundException)5 BigInteger (java.math.BigInteger)5 DigestOutputStream (java.security.DigestOutputStream)5 HashMap (java.util.HashMap)5 Path (java.nio.file.Path)4 CertificateFactory (java.security.cert.CertificateFactory)4 Formatter (java.util.Formatter)4