Search in sources :

Example 11 with MyMessageDigest1

use of org.apache.harmony.security.tests.support.MyMessageDigest1 in project robovm by robovm.

the class DigestOutputStreamTest method test_CtorLjava_io_OutputStreamLjava_security_MessageDigest.

//
// Tests
//
/**
     * java.security.DigestOutputStream#DigestOutputStream(java.io.OutputStream,
     *        java.security.MessageDigest)
     */
public void test_CtorLjava_io_OutputStreamLjava_security_MessageDigest() {
    // non-null parameters
    MessageDigest md = new MyMessageDigest1();
    MyOutputStream out = new MyOutputStream();
    MyDigestOutputStream dos = new MyDigestOutputStream(out, md);
    assertSame(out, dos.myOutputStream());
    assertSame(md, dos.myMessageDigest());
    // null parameters
    dos = new MyDigestOutputStream(null, null);
    assertNull(dos.myOutputStream());
    assertNull(dos.myMessageDigest());
    dos = new MyDigestOutputStream(null, md);
    assertNull(dos.myOutputStream());
    assertNotNull(dos.myMessageDigest());
    dos = new MyDigestOutputStream(out, null);
    assertNotNull(dos.myOutputStream());
    assertNull(dos.myMessageDigest());
}
Also used : MyMessageDigest1(org.apache.harmony.security.tests.support.MyMessageDigest1) MessageDigest(java.security.MessageDigest)

Example 12 with MyMessageDigest1

use of org.apache.harmony.security.tests.support.MyMessageDigest1 in project j2objc by google.

the class MessageDigest1Test method test_digest.

/**
     * java.security.MessageDigest#digest()
     */
public void test_digest() {
    MyMessageDigest1 md = new MyMessageDigest1("ABC");
    assertEquals("incorrect result", 0, md.digest().length);
    assertTrue(md.runEngineDigest);
}
Also used : MyMessageDigest1(org.apache.harmony.security.tests.support.MyMessageDigest1)

Example 13 with MyMessageDigest1

use of org.apache.harmony.security.tests.support.MyMessageDigest1 in project j2objc by google.

the class MessageDigest1Test method test_getDigestLength.

/**
     * java.security.MessageDigest#getDigestLength()
     */
public void test_getDigestLength() {
    MyMessageDigest1 md = new MyMessageDigest1("ABC");
    assertEquals(0, md.getDigestLength());
}
Also used : MyMessageDigest1(org.apache.harmony.security.tests.support.MyMessageDigest1)

Example 14 with MyMessageDigest1

use of org.apache.harmony.security.tests.support.MyMessageDigest1 in project j2objc by google.

the class MessageDigest1Test method test_updateLB$LILI.

/**
     * java.security.MessageDigest#update(byte[], int, int)
     */
public void test_updateLB$LILI() {
    MyMessageDigest1 md = new MyMessageDigest1("ABC");
    final byte[] bytes = { 1, 2, 3, 4, 5 };
    md.update(bytes, 1, 2);
    assertTrue(md.runEngineUpdate2);
    // Regression for HARMONY-1120
    try {
        // buf == null
        md.update(null, 0, 1);
        fail("No expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }
    try {
        // offset + len > buf.length
        md.update(bytes, 0, bytes.length + 1);
        fail("No expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }
    try {
        // offset + len > Integer.MAX_VALUE
        md.update(bytes, Integer.MAX_VALUE, 1);
        fail("No expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }
    // offset<0 and len<0 are passed to provider
    final int offset = -1;
    final int len = -1;
    md = new MyMessageDigest1("ABC") {

        @Override
        public void engineUpdate(byte[] arg0, int arg1, int arg2) {
            assertSame("buf", bytes, arg0);
            assertEquals("offset", offset, arg1);
            assertEquals("len", len, arg2);
            runEngineUpdate2 = true;
        }
    };
    md.update(bytes, offset, len);
    assertTrue(md.runEngineUpdate2);
}
Also used : MyMessageDigest1(org.apache.harmony.security.tests.support.MyMessageDigest1)

Example 15 with MyMessageDigest1

use of org.apache.harmony.security.tests.support.MyMessageDigest1 in project j2objc by google.

the class MessageDigest1Test method test_digestLB$.

/**
     * java.security.MessageDigest#digest(byte[])
     */
public void test_digestLB$() {
    MyMessageDigest1 md = new MyMessageDigest1("ABC");
    byte[] b = { 1, 2, 3, 4, 5 };
    assertEquals("incorrect result", 0, md.digest(b).length);
    assertTrue(md.runEngineDigest);
}
Also used : MyMessageDigest1(org.apache.harmony.security.tests.support.MyMessageDigest1)

Aggregations

MyMessageDigest1 (org.apache.harmony.security.tests.support.MyMessageDigest1)26 MessageDigest (java.security.MessageDigest)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 DigestOutputStream (java.security.DigestOutputStream)3 OutputStream (java.io.OutputStream)2 ByteBuffer (java.nio.ByteBuffer)2 DigestException (java.security.DigestException)2 Support_OutputStream (tests.support.Support_OutputStream)2