Search in sources :

Example 16 with MyMessageDigest1

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

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

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

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

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

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

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

the class MessageDigest1Test method test_updateLB$.

/**
     * java.security.MessageDigest#update(byte[])
     */
public void test_updateLB$() {
    MyMessageDigest1 md = new MyMessageDigest1("ABC");
    byte[] b = { 1, 2, 3, 4, 5 };
    md.update(b);
    assertTrue(md.runEngineUpdate2);
}
Also used : MyMessageDigest1(org.apache.harmony.security.tests.support.MyMessageDigest1)

Example 20 with MyMessageDigest1

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

the class DigestOutputStreamTest method test_getMessageDigest.

/**
     * java.security.DigestOutputStream#getMessageDigest()
     */
public void test_getMessageDigest() {
    MessageDigest digest = new MyMessageDigest1();
    OutputStream out = new MyOutputStream();
    // non-null parameter
    DigestOutputStream dos = new DigestOutputStream(out, digest);
    assertSame(digest, dos.getMessageDigest());
    // null parameter
    dos = new DigestOutputStream(out, null);
    assertNull("getMessageDigest should have returned null", dos.getMessageDigest());
}
Also used : DigestOutputStream(java.security.DigestOutputStream) OutputStream(java.io.OutputStream) DigestOutputStream(java.security.DigestOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Support_OutputStream(tests.support.Support_OutputStream) MyMessageDigest1(org.apache.harmony.security.tests.support.MyMessageDigest1) 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