use of java.security.cert.CertificateFactory in project robovm by robovm.
the class CertificateFactory4Test method test_getInstanceLjava_lang_StringLjava_lang_String.
/**
* java.security.cert.CertificateFactory#getInstance(java.lang.String,
* java.lang.String)
*/
public void test_getInstanceLjava_lang_StringLjava_lang_String() throws Exception {
// Test for method java.security.cert.CertificateFactory
// java.security.cert.CertificateFactory.getInstance(java.lang.String,
// java.lang.String)
Provider[] providers = Security.getProviders("CertificateFactory.X.509");
if (providers != null) {
for (int i = 0; i < providers.length; i++) {
CertificateFactory fact = CertificateFactory.getInstance("X.509", providers[i].getName());
assertNotNull("factory is null", fact);
}
// end for
} else {
fail("No providers support CertificateFactory.X.509");
}
// exception case
try {
CertificateFactory.getInstance("X.509", "IHaventBeenConfigured");
fail("Should have thrown NoSuchProviderException");
} catch (NoSuchProviderException e) {
// Expected
}
}
use of java.security.cert.CertificateFactory in project robovm by robovm.
the class CertificateFactory4Test method test_generateCRLsLjava_io_InputStream.
/**
* java.security.cert.CertificateFactory#generateCRLs(java.io.InputStream)
*/
public void test_generateCRLsLjava_io_InputStream() throws Exception {
CertificateFactory fact = CertificateFactory.getInstance("X.509");
for (int i = 0; i < CRLCOLLECTION_URLS.length; i++) {
URL certUrl = new URL(BASE_URL + CRLCOLLECTION_URLS[i]);
try {
InputStream is = certUrl.openStream();
Collection<? extends CRL> crls = fact.generateCRLs(is);
assertTrue("The CRLs in \"" + certUrl.toExternalForm() + "\" were not parsed correctly", crls != null && crls.size() > 0);
} catch (IOException e) {
// the certificate could not be found, skip it
}
}
}
use of java.security.cert.CertificateFactory in project robovm by robovm.
the class CertificateFactory4Test method test_generateCertificatesLjava_io_InputStream.
/**
* java.security.cert.CertificateFactory#generateCertificates(java.io.InputStream)
*/
public void test_generateCertificatesLjava_io_InputStream() throws Exception {
CertificateFactory fact = CertificateFactory.getInstance("X.509");
for (int i = 0; i < CERTIFICATE_URLS.length; i++) {
URL certUrl = new URL(BASE_URL + CERTIFICATE_URLS[i]);
try {
InputStream is = certUrl.openStream();
Collection<? extends Certificate> certs = fact.generateCertificates(is);
assertNotNull("The certificates in \"" + certUrl.toExternalForm() + "\" were not parsed correctly", certs);
} catch (IOException e) {
// the certificate could not be found, skip it
} catch (CertificateException e) {
fail("An exception was thrown while parsing \"" + certUrl.toExternalForm() + "\": " + e.getMessage());
}
}
}
use of java.security.cert.CertificateFactory in project robovm by robovm.
the class myCertificateFactory method testCertificateFactory01.
/**
* Test for <code>getInstance(String type)</code> method
* Assertion: returns CertificateFactory if type is X.509
*/
public void testCertificateFactory01() throws CertificateException {
if (!X509Support) {
fail(NotSupportMsg);
return;
}
for (int i = 0; i < validValues.length; i++) {
CertificateFactory certF = CertificateFactory.getInstance(validValues[i]);
assertEquals("Incorrect type: ", validValues[i], certF.getType());
}
}
use of java.security.cert.CertificateFactory in project robovm by robovm.
the class myCertificateFactory method testCertificateFactory12.
/**
* Test for <code>generateCertPath(InputStream inStream)</code>
* <code>generateCertPath(InputStream inStream, String encoding)</code>
* methods
* Assertion: throws CertificateException when inStream is null or
* when isStream contains invalid datas
*/
public void testCertificateFactory12() {
if (!X509Support) {
fail(NotSupportMsg);
return;
}
CertificateFactory[] certFs = initCertFs();
assertNotNull("CertificateFactory objects were not created", certFs);
InputStream is1 = null;
InputStream is2 = new ByteArrayInputStream(new byte[10]);
for (int i = 0; i < certFs.length; i++) {
try {
certFs[i].generateCertPath(is1);
fail("generateCertificate must thrown CertificateException or NullPointerException when input stream is null");
} catch (CertificateException e) {
} catch (NullPointerException e) {
}
try {
certFs[i].generateCertPath(is2);
fail("generateCertificate must thrown CertificateException when input stream contains invalid datas");
} catch (CertificateException e) {
}
Iterator<String> it = certFs[i].getCertPathEncodings();
while (it.hasNext()) {
String enc = it.next();
try {
certFs[i].generateCertPath(is1, enc);
fail("generateCertificate must thrown CertificateException or NullPointerException when input stream is null and encodings ".concat(enc));
} catch (CertificateException e) {
} catch (NullPointerException e) {
}
try {
certFs[i].generateCertPath(is2, enc);
fail("generateCertificate must thrown CertificateException when input stream contains invalid datas and encodings ".concat(enc));
} catch (CertificateException e) {
}
}
}
}
Aggregations