Search in sources :

Example 21 with DigestException

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

the class DigestExceptionTest method testDigestException05.

/**
     * Test for <code>DigestException(Throwable)</code> constructor Assertion:
     * constructs DigestException when <code>cause</code> is not null
     */
public void testDigestException05() {
    DigestException tE = new DigestException(tCause);
    if (tE.getMessage() != null) {
        String toS = tCause.toString();
        String getM = tE.getMessage();
        assertTrue("getMessage() should contain ".concat(toS), (getM.indexOf(toS) != -1));
    }
    assertNotNull("getCause() must not return null", tE.getCause());
    assertEquals("getCause() must return ".concat(tCause.toString()), tE.getCause(), tCause);
}
Also used : DigestException(java.security.DigestException)

Example 22 with DigestException

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

the class DigestExceptionTest method testDigestException03.

/**
     * Test for <code>DigestException(String)</code> constructor Assertion:
     * constructs DigestException when <code>msg</code> is null
     */
public void testDigestException03() {
    String msg = null;
    DigestException tE = new DigestException(msg);
    assertNull("getMessage() must return null.", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
}
Also used : DigestException(java.security.DigestException)

Example 23 with DigestException

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

the class DigestExceptionTest method testDigestException09.

/**
     * Test for <code>DigestException(String, Throwable)</code> constructor
     * Assertion: constructs DigestException when <code>cause</code> is not
     * null <code>msg</code> is not null
     */
public void testDigestException09() {
    DigestException tE;
    for (int i = 0; i < msgs.length; i++) {
        tE = new DigestException(msgs[i], tCause);
        String getM = tE.getMessage();
        String toS = tCause.toString();
        if (msgs[i].length() > 0) {
            assertTrue("getMessage() must contain ".concat(msgs[i]), getM.indexOf(msgs[i]) != -1);
            if (!getM.equals(msgs[i])) {
                assertTrue("getMessage() should contain ".concat(toS), getM.indexOf(toS) != -1);
            }
        }
        assertNotNull("getCause() must not return null", tE.getCause());
        assertEquals("getCause() must return ".concat(tCause.toString()), tE.getCause(), tCause);
    }
}
Also used : DigestException(java.security.DigestException)

Example 24 with DigestException

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

the class MessageDigest1Test method testSHAProvider.

/**
     * Tests SHA MessageDigest provider
     */
public void testSHAProvider() {
    MessageDigest md = null;
    try {
        md = MessageDigest.getInstance("SHA");
    } catch (NoSuchAlgorithmException e) {
        fail("unexpected exception: " + e);
    }
    byte[] bytes = new byte[] { 1, 1, 1, 1, 1 };
    // testing combination with provider
    try {
        // offset < 0
        md.update(bytes, -1, 1);
        fail("No expected IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    }
    try {
        md.update(bytes, 1, -1);
        fail("No expected IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
    }
    //Regression for Harmony-1148
    try {
        md = MessageDigest.getInstance("SHA");
    } catch (NoSuchAlgorithmException e) {
        fail("unexpected exception: " + e);
    }
    try {
        // offset < 0
        md.digest(bytes, 0, -1);
        fail("No expected DigestException");
    } catch (DigestException e) {
    }
    try {
        // len < 0
        md.digest(bytes, -1, 0);
        fail("No expected DigestException");
    } catch (DigestException e) {
    }
    try {
        md = MessageDigest.getInstance("UnknownDigest");
        fail("expected NoSuchAlgorithmException");
    } catch (NoSuchAlgorithmException e) {
    // ok
    }
}
Also used : DigestException(java.security.DigestException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest)

Example 25 with DigestException

use of java.security.DigestException in project atlas by alibaba.

the class DexFile method calcSignature.

/**
     * Calculates the signature for the {@code .dex} file in the
     * given array, and modify the array to contain it.
     *
     * @param bytes {@code non-null;} the bytes of the file
     */
private static void calcSignature(byte[] bytes) {
    MessageDigest md;
    try {
        md = MessageDigest.getInstance("SHA-1");
    } catch (NoSuchAlgorithmException ex) {
        throw new RuntimeException(ex);
    }
    md.update(bytes, 32, bytes.length - 32);
    try {
        int amt = md.digest(bytes, 12, 20);
        if (amt != 20) {
            throw new RuntimeException("unexpected digest write: " + amt + " bytes");
        }
    } catch (DigestException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : DigestException(java.security.DigestException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest)

Aggregations

DigestException (java.security.DigestException)30 MessageDigest (java.security.MessageDigest)18 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)14 IOException (java.io.IOException)7 DataSource (com.android.apksigner.core.util.DataSource)3 ByteBuffer (java.nio.ByteBuffer)2 MyMessageDigest1 (org.apache.harmony.security.tests.support.MyMessageDigest1)2 LimitedLengthInputStream (android.content.pm.LimitedLengthInputStream)1 MacAuthenticatedInputStream (android.content.pm.MacAuthenticatedInputStream)1 ParcelFileDescriptor (android.os.ParcelFileDescriptor)1 ByteBufferDataSource (com.android.apksigner.core.internal.util.ByteBufferDataSource)1 MessageDigestSink (com.android.apksigner.core.internal.util.MessageDigestSink)1 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 GeneralSecurityException (java.security.GeneralSecurityException)1 SignatureException (java.security.SignatureException)1 HashMap (java.util.HashMap)1