Search in sources :

Example 31 with MySignature1

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

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 32 with MySignature1

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

the class SignatureTest method testSetParameterStringObject.

/*
     * Class under test for void setParameter(String, Object)
     */
@SuppressWarnings("deprecation")
public void testSetParameterStringObject() {
    MySignature1 s = new MySignature1("ABC");
    s.setParameter("aaa", new Object());
    try {
        Signature sig = getTestSignature();
        sig.setParameter("TestParam", new Integer(42));
        fail("expected InvalidParameterException");
    } catch (InvalidParameterException e) {
    // expected
    } catch (NoSuchAlgorithmException e) {
        fail("unexpected: " + e);
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) Signature(java.security.Signature) MySignature1(org.apache.harmony.security.tests.support.MySignature1) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 33 with MySignature1

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

the class SignatureTest method testClone.

/*
     * Class under test for Object clone()
     */
public void testClone() {
    MySignature1 s = new MySignature1("ABC");
    try {
        s.clone();
        fail("No expected CloneNotSupportedException");
    } catch (CloneNotSupportedException e) {
    }
    MySignature sc = new MySignature();
    try {
        sc.clone();
    } catch (CloneNotSupportedException e) {
        fail("unexpected exception: " + e);
    }
}
Also used : MySignature1(org.apache.harmony.security.tests.support.MySignature1)

Example 34 with MySignature1

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

the class SignatureTest method testUpdatebyteArrayintint.

/*
     * Class under test for void update(byte[], int, int)
     */
public void testUpdatebyteArrayintint() throws Exception {
    MySignature1 s = new MySignature1("ABC");
    byte[] b = { 1, 2, 3, 4 };
    try {
        s.update(b, 0, 3);
        fail("No expected SignatureException");
    } catch (SignatureException e) {
    }
    s.initVerify(new MyPublicKey());
    s.update(b, 0, 3);
    s.initSign(new MyPrivateKey());
    s.update(b, 0, 3);
    assertEquals("state", MySignature1.SIGN, s.getState());
    assertTrue("update() failed", s.runEngineUpdate2);
    try {
        s.update(b, 3, 0);
        fail("expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    // ok
    }
    try {
        s.update(b, 0, b.length + 1);
        fail("expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    // ok
    }
    try {
        s.update(b, -1, b.length);
        fail("expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    // ok
    }
}
Also used : MySignature1(org.apache.harmony.security.tests.support.MySignature1) SignatureException(java.security.SignatureException)

Example 35 with MySignature1

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

the class SignatureTest method testConstructor.

/*
     * Class under test for Signature(String)
     */
public void testConstructor() {
    String[] algorithms = { "SHA256WITHRSA", "NONEWITHDSA", "SHA384WITHRSA", "MD5ANDSHA1WITHRSA", "SHA512WITHRSA", "SHA1WITHRSA", "SHA1WITHDSA", "MD5WITHRSA" };
    for (int i = 0; i < algorithms.length; i++) {
        MySignature1 s = new MySignature1(algorithms[i]);
        assertEquals(algorithms[i], s.getAlgorithm());
        assertNull(s.getProvider());
        assertEquals(0, s.getState());
    }
    MySignature1 s1 = new MySignature1(null);
    assertNull(s1.getAlgorithm());
    assertNull(s1.getProvider());
    assertEquals(0, s1.getState());
    MySignature1 s2 = new MySignature1("ABCD@#&^%$)(*&");
    assertEquals("ABCD@#&^%$)(*&", s2.getAlgorithm());
    assertNull(s2.getProvider());
    assertEquals(0, s2.getState());
}
Also used : MySignature1(org.apache.harmony.security.tests.support.MySignature1)

Aggregations

MySignature1 (org.apache.harmony.security.tests.support.MySignature1)38 Signature (java.security.Signature)16 SignatureException (java.security.SignatureException)14 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)12 InvalidKeyException (java.security.InvalidKeyException)8 InvalidParameterException (java.security.InvalidParameterException)4 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)2 SecureRandom (java.security.SecureRandom)2 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)2 KnownFailure (dalvik.annotation.KnownFailure)1