use of java.security.Provider in project robovm by robovm.
the class SecurityTest method test_getProviderLjava_lang_String.
/**
* java.security.Security#getProvider(String)
*/
public final void test_getProviderLjava_lang_String() {
// Returns null if no provider with the specified name is installed
assertNull(Security.getProvider("SOMEINCORRECTPROVIDERNAME"));
// Returns null if name is null
assertNull(Security.getProvider(null));
// test for existing providers
Provider[] providers = Security.getProviders();
assertTrue("getProviders returned zero length array", providers.length > 0);
for (Provider p : providers) {
String providerName = p.getName();
assertSame(p, Security.getProvider(providerName));
}
// test for newly installed provider
Provider p = new MyProvider();
try {
Security.addProvider(p);
assertSame(p, Security.getProvider(p.getName()));
} finally {
// clean up
Security.removeProvider(p.getName());
}
}
use of java.security.Provider in project robovm by robovm.
the class Signature2Test method test_initVerifyLjava_security_Certificate.
/**
* java.security.Signature#initVerify(java.security.cert.Certificate)
*/
public void test_initVerifyLjava_security_Certificate() throws Exception {
Provider p = new MyProvider();
p.put("DSA", "tests.java.security.support.cert.MyCertificate$1");
Provider myProvider = new MyProvider();
Security.addProvider(myProvider);
try {
Provider[] pp = Security.getProviders();
if (pp == null) {
return;
}
try {
Signature.getInstance("DSA").initVerify((Certificate) null);
fail();
} catch (NullPointerException expected) {
}
} finally {
Security.removeProvider(myProvider.getName());
}
}
use of java.security.Provider in project robovm by robovm.
the class Signature2Test method test_getInstanceLjava_lang_StringLjava_lang_String_java_security_Provider.
/**
* java.security.Signature#getInstance(java.lang.String,
* java.security.Provider)
*/
public void test_getInstanceLjava_lang_StringLjava_lang_String_java_security_Provider() throws Exception {
Provider[] providers = Security.getProviders("Signature.DSA");
for (int i = 0; i < providers.length; i++) {
Signature signature = Signature.getInstance("DSA", providers[i]);
assertEquals("DSA", signature.getAlgorithm());
assertEquals(providers[i], signature.getProvider());
}
try {
Signature.getInstance((String) null, (Provider) null);
fail();
} catch (NullPointerException expected) {
}
try {
Signature.getInstance("DSA", (Provider) null);
fail();
} catch (IllegalArgumentException expected) {
}
try {
Signature.getInstance((String) null, providers[0]);
fail();
} catch (NullPointerException expected) {
}
try {
Signature.getInstance("bogus", providers[0]);
fail();
} catch (NoSuchAlgorithmException expected) {
}
}
use of java.security.Provider in project robovm by robovm.
the class MessageDigest2Test method test_getInstanceLjava_lang_StringLjava_lang_String.
/**
* java.security.MessageDigest#getInstance(java.lang.String,
* java.lang.String)
*/
public void test_getInstanceLjava_lang_StringLjava_lang_String() throws Exception {
for (Entry<Provider, List<String>> e : digestAlgs.entrySet()) {
for (String algorithm : e.getValue()) {
MessageDigest md = MessageDigest.getInstance(algorithm, e.getKey().getName());
assertNotNull(md);
}
}
for (List<String> algorithms : digestAlgs.values()) {
for (String algorithm : algorithms) {
try {
MessageDigest.getInstance(algorithm, "UnknownProvider");
fail("expected NoSuchProviderException");
} catch (NoSuchProviderException expected) {
}
}
}
for (Provider provider : digestAlgs.keySet()) {
try {
MessageDigest.getInstance("UnknownDigest", provider.getName());
fail("expected NoSuchAlgorithmException");
} catch (NoSuchAlgorithmException expected) {
}
}
for (Provider provider : digestAlgs.keySet()) {
try {
MessageDigest.getInstance(null, provider.getName());
fail("expected NullPointerException");
} catch (NullPointerException expected) {
}
}
try {
MessageDigest.getInstance("AnyDigest", (String) null);
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException expected) {
}
}
use of java.security.Provider in project robovm by robovm.
the class MessageDigest2Test method test_getAlgorithm.
/**
* java.security.MessageDigest#getAlgorithm()
*/
public void test_getAlgorithm() throws Exception {
for (Entry<Provider, List<String>> e : digestAlgs.entrySet()) {
for (String algorithm : e.getValue()) {
MessageDigest md = MessageDigest.getInstance(algorithm, e.getKey().getName());
assertEquals(algorithm, md.getAlgorithm());
}
}
}
Aggregations