Search in sources :

Example 1 with MyMessageDigest1

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

the class MessageDigest1Test method test_updateLjava_nio_ByteBuffer.

/**
     * java.security.MessageDigest#update(ByteBuffer)
     */
public void test_updateLjava_nio_ByteBuffer() {
    MyMessageDigest1 md = new MyMessageDigest1("ABC");
    byte[] b = { 1, 2, 3, 4, 5 };
    ByteBuffer byteBuffer = ByteBuffer.wrap(b);
    int limit = byteBuffer.limit();
    md.update(byteBuffer);
    assertTrue(md.runEngineUpdate2);
    assertEquals(byteBuffer.limit(), byteBuffer.position());
    assertEquals(limit, byteBuffer.limit());
}
Also used : MyMessageDigest1(org.apache.harmony.security.tests.support.MyMessageDigest1) ByteBuffer(java.nio.ByteBuffer)

Example 2 with MyMessageDigest1

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

the class MessageDigest1Test method test_getAlgorithm.

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

Example 3 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 4 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 5 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)

Aggregations

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