Search in sources :

Example 6 with CertificateFactorySpi

use of java.security.cert.CertificateFactorySpi in project robovm by robovm.

the class CertificateFactorySpiTest method testCertificateFactorySpi02.

/**
     * Test for <code>CertificateFactorySpi</code> constructor
     * Assertion: constructs CertificateFactorySpi
     */
public void testCertificateFactorySpi02() throws CertificateException, CRLException {
    CertificateFactorySpi certFactorySpi = new MyCertificateFactorySpi();
    MyCertificateFactorySpi.putMode(true);
    ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]);
    DataInputStream dis = new DataInputStream(bais);
    try {
        certFactorySpi.engineGenerateCertPath(bais);
        fail("CertificateException must be thrown");
    } catch (CertificateException e) {
    }
    certFactorySpi.engineGenerateCertPath(dis);
    try {
        certFactorySpi.engineGenerateCertPath(bais, "aa");
        fail("CertificateException must be thrown");
    } catch (CertificateException e) {
    }
    try {
        certFactorySpi.engineGenerateCertPath(dis, "");
        fail("IllegalArgumentException must be thrown");
    } catch (IllegalArgumentException e) {
    }
    certFactorySpi.engineGenerateCertPath(dis, "ss");
    try {
        certFactorySpi.engineGenerateCertificate(bais);
        fail("CertificateException must be thrown");
    } catch (CertificateException e) {
    }
    try {
        certFactorySpi.engineGenerateCertificates(null);
        fail("CertificateException must be thrown");
    } catch (CertificateException e) {
    }
    Certificate cert = certFactorySpi.engineGenerateCertificate(dis);
    assertNull("Result must be null", cert);
    Collection<? extends Certificate> col = certFactorySpi.engineGenerateCertificates(dis);
    assertNull("Result must be null", col);
    try {
        certFactorySpi.engineGenerateCRL(bais);
        fail("CRLException must be thrown");
    } catch (CRLException e) {
    }
    try {
        certFactorySpi.engineGenerateCRLs(null);
        fail("CRLException must be thrown");
    } catch (CRLException e) {
    }
    CRL crl = certFactorySpi.engineGenerateCRL(dis);
    assertNull("Result must be null", crl);
    Collection<? extends CRL> colcrl = certFactorySpi.engineGenerateCRLs(dis);
    assertNull("Result must be null", colcrl);
    List<Certificate> list = null;
    try {
        certFactorySpi.engineGenerateCertPath(list);
        fail("NullPointerException must be thrown");
    } catch (NullPointerException e) {
    }
    Iterator<String> enc = certFactorySpi.engineGetCertPathEncodings();
    assertTrue("Incorrect Iterator", enc.hasNext());
}
Also used : CertificateFactorySpi(java.security.cert.CertificateFactorySpi) MyCertificateFactorySpi(org.apache.harmony.security.tests.support.cert.MyCertificateFactorySpi) CertificateException(java.security.cert.CertificateException) DataInputStream(java.io.DataInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) MyCertificateFactorySpi(org.apache.harmony.security.tests.support.cert.MyCertificateFactorySpi) CRL(java.security.cert.CRL) CRLException(java.security.cert.CRLException) Certificate(java.security.cert.Certificate)

Example 7 with CertificateFactorySpi

use of java.security.cert.CertificateFactorySpi in project robovm by robovm.

the class myCertificateFactory method testCertificateFactory19.

@SuppressWarnings("cast")
public void testCertificateFactory19() {
    if (!X509Support) {
        fail(NotSupportMsg);
        return;
    }
    CertificateFactorySpi spi = new MyCertificateFactorySpi();
    myCertificateFactory cf;
    try {
        cf = new myCertificateFactory(spi, defaultProvider, defaultType);
        assertEquals("Incorrect type", cf.getType(), defaultType);
        assertEquals("Incorrect provider", cf.getProvider(), defaultProvider);
        assertTrue(cf instanceof CertificateFactory);
    } catch (Exception e) {
        fail("Unexpected exception" + e);
    }
    try {
        cf = new myCertificateFactory(null, null, null);
    } catch (Exception e) {
        fail("Unexpected exception" + e);
    }
}
Also used : CertificateFactorySpi(java.security.cert.CertificateFactorySpi) MyCertificateFactorySpi(org.apache.harmony.security.tests.support.cert.MyCertificateFactorySpi) MyCertificateFactorySpi(org.apache.harmony.security.tests.support.cert.MyCertificateFactorySpi) CertificateFactory(java.security.cert.CertificateFactory) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) CRLException(java.security.cert.CRLException) NoSuchProviderException(java.security.NoSuchProviderException)

Example 8 with CertificateFactorySpi

use of java.security.cert.CertificateFactorySpi in project robovm by robovm.

the class myCertificateFactory method testCertificateFactory17.

/**
     * Test for <code>CertificateFactory</code> constructor
     * Assertion: returns CertificateFactory object
     */
public void testCertificateFactory17() throws CRLException {
    if (!X509Support) {
        fail(NotSupportMsg);
        return;
    }
    CertificateFactorySpi spi = new MyCertificateFactorySpi();
    CertificateFactory cf = new myCertificateFactory(spi, defaultProvider, defaultType);
    assertEquals("Incorrect type", cf.getType(), defaultType);
    assertEquals("Incorrect provider", cf.getProvider(), defaultProvider);
    try {
        cf.generateCRLs(null);
        fail("CRLException must be thrown");
    } catch (CRLException e) {
    }
    cf = new myCertificateFactory(null, null, null);
    assertNull("Incorrect type", cf.getType());
    assertNull("Incorrect provider", cf.getProvider());
    try {
        cf.generateCRLs(null);
        fail("NullPointerException must be thrown");
    } catch (NullPointerException e) {
    }
}
Also used : CertificateFactorySpi(java.security.cert.CertificateFactorySpi) MyCertificateFactorySpi(org.apache.harmony.security.tests.support.cert.MyCertificateFactorySpi) MyCertificateFactorySpi(org.apache.harmony.security.tests.support.cert.MyCertificateFactorySpi) CertificateFactory(java.security.cert.CertificateFactory) CRLException(java.security.cert.CRLException)

Example 9 with CertificateFactorySpi

use of java.security.cert.CertificateFactorySpi in project robovm by robovm.

the class CertificateFactorySpiTest method testEngineGenerateCertPathLjava_io_InputStream01.

/**
     * Test for <code>engineGenerateCertPath(InputStream)</code> method.
     * Assertion: Generates a <code>CertPath</code> object and initializes it
     * with the data read from the <code>InputStream</code>
     */
public void testEngineGenerateCertPathLjava_io_InputStream01() {
    CertificateFactorySpi certFactorySpi = new MyCertificateFactorySpi();
    MyCertificateFactorySpi.putMode(true);
    ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]);
    DataInputStream dis = new DataInputStream(bais);
    try {
        assertNull(certFactorySpi.engineGenerateCertPath(dis));
    } catch (CertificateException e) {
        fail("Unexpected CertificateException " + e.getMessage());
    }
}
Also used : CertificateFactorySpi(java.security.cert.CertificateFactorySpi) MyCertificateFactorySpi(org.apache.harmony.security.tests.support.cert.MyCertificateFactorySpi) ByteArrayInputStream(java.io.ByteArrayInputStream) MyCertificateFactorySpi(org.apache.harmony.security.tests.support.cert.MyCertificateFactorySpi) CertificateException(java.security.cert.CertificateException) DataInputStream(java.io.DataInputStream)

Example 10 with CertificateFactorySpi

use of java.security.cert.CertificateFactorySpi in project robovm by robovm.

the class CertificateFactorySpiTest method testEngineGenerateCertPathLJava_util_List02.

/**
     * Test for <code>engineGenerateCertPath(List<? extends Certificate>)</code>
     * method Assertion: generates a <code>CertPath</code> object and
     * initializes it with a <code>List</code> of <code>Certificates</code>
     */
public void testEngineGenerateCertPathLJava_util_List02() {
    CertificateFactorySpi certFactorySpi = new extCertificateFactorySpi();
    List<Certificate> list = new ArrayList<Certificate>();
    try {
        certFactorySpi.engineGenerateCertPath(list);
        fail("UnsupportedOperationException expected");
    } catch (UnsupportedOperationException e) {
    // expected
    } catch (CertificateException e) {
        fail("Unexpected CertificateException " + e.getMessage());
    }
}
Also used : CertificateFactorySpi(java.security.cert.CertificateFactorySpi) MyCertificateFactorySpi(org.apache.harmony.security.tests.support.cert.MyCertificateFactorySpi) ArrayList(java.util.ArrayList) CertificateException(java.security.cert.CertificateException) Certificate(java.security.cert.Certificate)

Aggregations

CertificateFactorySpi (java.security.cert.CertificateFactorySpi)12 MyCertificateFactorySpi (org.apache.harmony.security.tests.support.cert.MyCertificateFactorySpi)12 CertificateException (java.security.cert.CertificateException)11 ByteArrayInputStream (java.io.ByteArrayInputStream)8 DataInputStream (java.io.DataInputStream)7 CRLException (java.security.cert.CRLException)6 Certificate (java.security.cert.Certificate)5 CRL (java.security.cert.CRL)3 CertificateFactory (java.security.cert.CertificateFactory)2 ArrayList (java.util.ArrayList)2 IOException (java.io.IOException)1 NoSuchProviderException (java.security.NoSuchProviderException)1