Search in sources :

Example 21 with MySignature1

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

the class SignatureTest method testUpdatebyteArray.

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

Example 22 with MySignature1

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

the class SignatureTest method testVerifybyteArray.

/*
     * Class under test for boolean verify(byte[])
     */
public void testVerifybyteArray() throws Exception {
    MySignature1 s = new MySignature1("ABC");
    byte[] b = { 1, 2, 3, 4 };
    try {
        s.verify(b);
        fail("No expected SignatureException");
    } catch (SignatureException e) {
    }
    s.initSign(new MyPrivateKey());
    try {
        s.verify(b);
        fail("No expected SignatureException");
    } catch (SignatureException e) {
    }
    s.initVerify(new MyPublicKey());
    s.verify(b);
    assertEquals("state", MySignature1.VERIFY, s.getState());
    assertTrue("verify() failed", s.runEngineVerify);
}
Also used : MySignature1(org.apache.harmony.security.tests.support.MySignature1) SignatureException(java.security.SignatureException)

Example 23 with MySignature1

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

the class SignatureTest method testSign.

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

Example 24 with MySignature1

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

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

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

the class SignatureTest method testUpdatebyte.

/*
     * Class under test for void update(byte)
     */
public void testUpdatebyte() throws Exception {
    MySignature1 s = new MySignature1("ABC");
    try {
        s.update((byte) 1);
        fail("No expected SignatureException");
    } catch (SignatureException e) {
    }
    s.initVerify(new MyPublicKey());
    s.update((byte) 1);
    s.initSign(new MyPrivateKey());
    s.update((byte) 1);
    assertEquals("state", MySignature1.SIGN, s.getState());
    assertTrue("update() failed", s.runEngineUpdate1);
    try {
        Signature sig = getTestSignature();
        sig.update((byte) 42);
        fail("expected SignatureException");
    } catch (SignatureException e) {
    // ok
    }
}
Also used : Signature(java.security.Signature) MySignature1(org.apache.harmony.security.tests.support.MySignature1) SignatureException(java.security.SignatureException)

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