Search in sources :

Example 6 with MyMessageDigest1

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

the class MessageDigest1Test method test_updateLB.

/**
     * java.security.MessageDigest#update(byte)
     */
public void test_updateLB() {
    MyMessageDigest1 md = new MyMessageDigest1("ABC");
    md.update((byte) 1);
    assertTrue(md.runEngineUpdate1);
}
Also used : MyMessageDigest1(org.apache.harmony.security.tests.support.MyMessageDigest1)

Example 7 with MyMessageDigest1

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

the class MessageDigest1Test method test_digestLB$LILI.

/**
     * java.security.MessageDigest#digest(byte[], int, int)
     */
public void test_digestLB$LILI() throws Exception {
    MyMessageDigest1 md = new MyMessageDigest1("ABC");
    byte[] b = { 1, 2, 3, 4, 5 };
    assertEquals("incorrect result", 0, md.digest(b, 2, 3));
    assertTrue("digest failed", md.runEngineDigest);
    // Regression for Harmony-1148
    md = new MyMessageDigest1();
    final byte[] bytes = new byte[] { 2, 4, 1 };
    try {
        // buf == null
        md.digest(null, 0, 1);
        fail("No expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }
    try {
        // offset + len > buf.length
        md.digest(bytes, 0, bytes.length + 1);
        fail("No expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }
    try {
        // offset + len > Integer.MAX_VALUE
        md.digest(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;
    final int status = 33;
    md = new MyMessageDigest1("ABC") {

        @Override
        public int engineDigest(byte[] arg0, int arg1, int arg2) {
            assertSame("buf", bytes, arg0);
            assertEquals("offset", offset, arg1);
            assertEquals("len", len, arg2);
            return status;
        }
    };
    assertEquals("returned status", status, md.digest(bytes, offset, len));
    try {
        MessageDigest digest = MessageDigest.getInstance("TestDigest", new TestProvider());
        digest.digest(new byte[5], 0, 5);
        fail("expected DigestException");
    } catch (DigestException e) {
    // ok
    }
}
Also used : DigestException(java.security.DigestException) MyMessageDigest1(org.apache.harmony.security.tests.support.MyMessageDigest1) MessageDigest(java.security.MessageDigest)

Example 8 with MyMessageDigest1

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

the class MessageDigest1Test method test_getProvider.

/**
     * java.security.MessageDigest#getProvider()
     */
public void test_getProvider() {
    MyMessageDigest1 md = new MyMessageDigest1("ABC");
    assertNull(md.getProvider());
}
Also used : MyMessageDigest1(org.apache.harmony.security.tests.support.MyMessageDigest1)

Example 9 with MyMessageDigest1

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

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 10 with MyMessageDigest1

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

the class DigestOutputStreamTest method test_write$BII_6.

/**
     * java.security.DigestOutputStream#write(byte[], int, int)
     */
public void test_write$BII_6() throws Exception {
    // Regression form HARMONY-1091.
    MessageDigest md = new MyMessageDigest1();
    byte[] bytes = new byte[] { 1, 2 };
    DigestOutputStream dig = new DigestOutputStream(new ByteArrayOutputStream(), md);
    // buf == null
    try {
        dig.write(null, -1, 0);
        fail("No expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }
    // offset + len > buf.length
    try {
        dig.write(bytes, 0, bytes.length + 1);
        fail("No expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }
    // offset < 0
    try {
        dig.write(bytes, -1, 1);
        fail("No expected IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    }
    // len < 0
    try {
        dig.write(bytes, 0, -1);
        fail("No expected IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    }
}
Also used : DigestOutputStream(java.security.DigestOutputStream) MyMessageDigest1(org.apache.harmony.security.tests.support.MyMessageDigest1) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MessageDigest(java.security.MessageDigest)

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