Search in sources :

Example 46 with SignatureException

use of java.security.SignatureException in project j2objc by google.

the class SignatureSpiTest method testEngineUpdate_ByteBuffer.

public void testEngineUpdate_ByteBuffer() {
    MySignature signature = new MySignature("dummy");
    try {
        signature.initSign(new PrivateKey() {

            public String getFormat() {
                return null;
            }

            public byte[] getEncoded() {
                return null;
            }

            public String getAlgorithm() {
                return null;
            }
        });
    } catch (InvalidKeyException e) {
        fail("unexpected exception: " + e);
    }
    try {
        signature.update(ByteBuffer.wrap("Hello".getBytes()));
        assertTrue("SPI method not called", signature.wasMethodCalled("engineUpdate_ByteBuffer"));
    } catch (SignatureException e) {
        fail("unexpected exception");
    }
}
Also used : PrivateKey(java.security.PrivateKey) SignatureException(java.security.SignatureException) InvalidKeyException(java.security.InvalidKeyException)

Example 47 with SignatureException

use of java.security.SignatureException in project j2objc by google.

the class SignatureTest method testSignbyteintint.

/*
     * Class under test for sign(byte[], offset, len)
     */
public void testSignbyteintint() throws Exception {
    MySignature1 s = new MySignature1("ABC");
    byte[] outbuf = new byte[10];
    try {
        s.sign(outbuf, 0, outbuf.length);
        fail("No expected SignatureException");
    } catch (SignatureException e) {
    }
    s.initVerify(new MyPublicKey());
    try {
        s.sign(outbuf, 0, outbuf.length);
        fail("No expected SignatureException");
    } catch (SignatureException e) {
    }
    s.initSign(new MyPrivateKey());
    assertEquals(s.getBufferLength(), s.sign(outbuf, 0, outbuf.length));
    assertEquals("state", MySignature1.SIGN, s.getState());
    assertTrue("sign() failed", s.runEngineSign);
    try {
        s.initSign(new MyPrivateKey());
        s.sign(outbuf, outbuf.length, 0);
        fail("expected SignatureException");
    } catch (SignatureException e) {
    // ok
    }
    try {
        s.initSign(new MyPrivateKey());
        s.sign(outbuf, outbuf.length, 3);
        fail("expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    // ok
    }
}
Also used : MySignature1(org.apache.harmony.security.tests.support.MySignature1) SignatureException(java.security.SignatureException)

Example 48 with SignatureException

use of java.security.SignatureException in project j2objc by google.

the class SignatureExceptionTest method testSignatureException07.

/**
     * Test for <code>SignatureException(String, Throwable)</code> constructor
     * Assertion: constructs SignatureException when <code>cause</code> is
     * null <code>msg</code> is not null
     */
public void testSignatureException07() {
    SignatureException tE;
    for (int i = 0; i < msgs.length; i++) {
        tE = new SignatureException(msgs[i], null);
        assertEquals("getMessage() must return: ".concat(msgs[i]), tE.getMessage(), msgs[i]);
        assertNull("getCause() must return null", tE.getCause());
    }
}
Also used : SignatureException(java.security.SignatureException)

Example 49 with SignatureException

use of java.security.SignatureException in project j2objc by google.

the class SignatureExceptionTest method testSignatureException01.

/**
     * Test for <code>SignatureException()</code> constructor Assertion:
     * constructs SignatureException with no detail message
     */
public void testSignatureException01() {
    SignatureException tE = new SignatureException();
    assertNull("getMessage() must return null.", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
}
Also used : SignatureException(java.security.SignatureException)

Example 50 with SignatureException

use of java.security.SignatureException in project j2objc by google.

the class SignatureExceptionTest method testSignatureException09.

/**
     * Test for <code>SignatureException(String, Throwable)</code> constructor
     * Assertion: constructs SignatureException when <code>cause</code> is not
     * null <code>msg</code> is not null
     */
public void testSignatureException09() {
    SignatureException tE;
    for (int i = 0; i < msgs.length; i++) {
        tE = new SignatureException(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 : SignatureException(java.security.SignatureException)

Aggregations

SignatureException (java.security.SignatureException)196 InvalidKeyException (java.security.InvalidKeyException)94 Signature (java.security.Signature)80 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)66 IOException (java.io.IOException)51 PublicKey (java.security.PublicKey)34 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)26 X509Certificate (java.security.cert.X509Certificate)19 ByteArrayInputStream (java.io.ByteArrayInputStream)16 BigInteger (java.math.BigInteger)16 CertificateException (java.security.cert.CertificateException)16 ArrayList (java.util.ArrayList)14 MySignature1 (org.apache.harmony.security.tests.support.MySignature1)14 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)12 NoSuchProviderException (java.security.NoSuchProviderException)12 PrivateKey (java.security.PrivateKey)12 KeyStoreException (android.security.KeyStoreException)10 KeyFactory (java.security.KeyFactory)10 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9 CertificateEncodingException (java.security.cert.CertificateEncodingException)9