use of java.security.Provider in project robovm by robovm.
the class KeyFactoryTest method testGetInstanceStringProvider.
@SuppressWarnings("unchecked")
public void testGetInstanceStringProvider() {
try {
KeyFactory factory = KeyFactory.getInstance(TEST_KEYFACTORY_NAME, provider);
assertNotNull(factory);
} catch (NoSuchAlgorithmException e) {
fail("unexpected exception: " + e);
}
String[] algorithms = { "UnknownKeyFactory", null, TEST_KEYFACTORY_NAME, TEST_KEYFACTORY_NAME };
Provider[] providers = { provider, provider, existingProvider, null };
Class[] exceptions = { NoSuchAlgorithmException.class, NullPointerException.class, NoSuchAlgorithmException.class, IllegalArgumentException.class };
for (int i = 0; i < algorithms.length; i++) {
String algorithm = algorithms[i];
Provider provider = providers[i];
String message = "getInstance(" + (algorithm == null ? "null" : "\"" + algorithm + "\"") + ", " + (provider == null ? "null" : "provider");
exceptionThrown = false;
try {
KeyFactory.getInstance(algorithm, provider);
} catch (Exception e) {
checkException(message, e, exceptions[i]);
} finally {
checkException(message, null, exceptions[i]);
}
}
}
use of java.security.Provider in project robovm by robovm.
the class KeyPairGenerator2Test method GetInstance03.
/**
* Test for <code>getInstance(String algorithm, Provider provider)</code>
* method
* Assertions:
* throws NullPointerException when algorithm is null
* throws NoSuchAlgorithmException when algorithm is incorrect;
* throws IllegalArgumentException when provider is null;
* returns KeyPairGenerator object
*/
private void GetInstance03(int mode) throws NoSuchAlgorithmException, IllegalArgumentException, InvalidAlgorithmParameterException {
try {
KeyPairGenerator.getInstance(null, mProv);
fail("NullPointerException or KeyStoreException must be thrown");
} catch (NoSuchAlgorithmException e) {
} catch (NullPointerException e) {
}
for (int i = 0; i < invalidValues.length; i++) {
try {
KeyPairGenerator.getInstance(invalidValues[i], mProv);
fail("NoSuchAlgorithmException must be thrown (algorithm: ".concat(invalidValues[i]).concat(")"));
} catch (NoSuchAlgorithmException e) {
}
}
Provider prov = null;
for (int i = 0; i < validValues.length; i++) {
String alg = validValues[i].concat(post);
try {
KeyPairGenerator.getInstance(alg, prov);
fail("IllegalArgumentException must be thrown when provider is null (algorithm: ".concat(alg).concat(")"));
} catch (IllegalArgumentException e) {
}
}
KeyPairGenerator kpG;
for (int i = 0; i < validValues.length; i++) {
String alg = validValues[i].concat(post);
kpG = KeyPairGenerator.getInstance(alg, mProv);
assertEquals("Incorrect algorithm", kpG.getAlgorithm().toUpperCase(), (mode <= 2 ? resAlg : alg).toUpperCase());
assertEquals("Incorrect provider", kpG.getProvider(), mProv);
checkResult(kpG, mode);
}
}
use of java.security.Provider in project robovm by robovm.
the class KeyPairGenerator4Test method test_getProvider.
/**
* java.security.KeyPairGenerator#getProvider()
*/
public void test_getProvider() throws Exception {
Provider p = KeyPairGenerator.getInstance("DSA").getProvider();
assertNotNull("provider is null", p);
}
use of java.security.Provider in project robovm by robovm.
the class KeyFactory2Test method getKeyFactoryAlgorithms.
/*
* Returns the key algorithms that the given provider supports.
*/
private String[] getKeyFactoryAlgorithms(String providerName) {
Vector<String> algs = new Vector<String>();
Provider provider = Security.getProvider(providerName);
if (provider == null)
return new String[0];
Enumeration<Object> e = provider.keys();
while (e.hasMoreElements()) {
String algorithm = (String) e.nextElement();
if (algorithm.startsWith(KEYFACTORY_ID) && !algorithm.contains(" ")) {
algs.addElement(algorithm.substring(KEYFACTORY_ID.length()));
}
}
return algs.toArray(new String[algs.size()]);
}
use of java.security.Provider in project robovm by robovm.
the class KeyFactory2Test method setUp.
protected void setUp() {
if (keyfactAlgs == null) {
Provider[] providers = Security.getProviders();
// KeyFactory algorithms
for (Provider provider : providers) {
providerName = provider.getName();
keyfactAlgs = getKeyFactoryAlgorithms(providerName);
if (keyfactAlgs.length != 0) {
break;
}
}
}
}
Aggregations