use of java.security.Provider.Service in project j2objc by google.
the class Mac method getInstance.
/**
* Returns a <code>Mac</code> object that implements the
* specified MAC algorithm.
*
* <p> This method traverses the list of registered security Providers,
* starting with the most preferred Provider.
* A new Mac object encapsulating the
* MacSpi implementation from the first
* Provider that supports the specified algorithm is returned.
*
* <p> Note that the list of registered providers may be retrieved via
* the {@link Security#getProviders() Security.getProviders()} method.
*
* @param algorithm the standard name of the requested MAC algorithm.
* See the Mac section in the <a href=
* "{@docRoot}/../technotes/guides/security/StandardNames.html#Mac">
* Java Cryptography Architecture Standard Algorithm Name Documentation</a>
* for information about standard algorithm names.
*
* @return the new <code>Mac</code> object.
*
* @exception NoSuchAlgorithmException if no Provider supports a
* MacSpi implementation for the
* specified algorithm.
*
* @see java.security.Provider
*/
public static final Mac getInstance(String algorithm) throws NoSuchAlgorithmException {
List<Service> services = GetInstance.getServices("Mac", algorithm);
// make sure there is at least one service from a signed provider
Iterator<Service> t = services.iterator();
while (t.hasNext()) {
Service s = t.next();
if (JceSecurity.canUseProvider(s.getProvider()) == false) {
continue;
}
// return new Mac(s, t, algorithm);
return new Mac(algorithm);
}
throw new NoSuchAlgorithmException("Algorithm " + algorithm + " not available");
}
use of java.security.Provider.Service in project j2objc by google.
the class GetInstance method getService.
public static Service getService(String type, String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException {
if ((provider == null) || (provider.length() == 0)) {
throw new IllegalArgumentException("missing provider");
}
Provider p = Providers.getProviderList().getProvider(provider);
if (p == null) {
throw new NoSuchProviderException("no such provider: " + provider);
}
Service s = p.getService(type, algorithm);
if (s == null) {
throw new NoSuchAlgorithmException("no such algorithm: " + algorithm + " for provider " + provider);
}
return s;
}
use of java.security.Provider.Service in project j2objc by google.
the class ProviderServiceTest method testNewlyCreatedServiceDoesntGetsRegistered.
public void testNewlyCreatedServiceDoesntGetsRegistered() throws Exception {
String type = "SecureRandom";
String algorithm = "algorithm";
MyProvider p = new MyProvider();
Provider.Service s = new Provider.Service(p, type, algorithm, "org.apache.harmony.security.tests.support.RandomImpl", null, null);
assertSame(p, s.getProvider());
assertNull(p.getService(type, algorithm));
try {
Object o = s.newInstance(null);
fail("Expected " + NoSuchAlgorithmException.class.getName() + " as the service is not " + "registered with the provider");
} catch (NoSuchAlgorithmException e) {
// Expected.
}
}
use of java.security.Provider.Service in project j2objc by google.
the class GetInstance method getInstance.
/*
* For all the getInstance() methods below:
* @param type the type of engine (e.g. MessageDigest)
* @param clazz the Spi class that the implementation must subclass
* (e.g. MessageDigestSpi.class) or null if no superclass check
* is required
* @param algorithm the name of the algorithm (or alias), e.g. MD5
* @param provider the provider (String or Provider object)
* @param param the parameter to pass to the Spi constructor
* (for CertStores)
*
* There are overloaded methods for all the permutations.
*/
public static Instance getInstance(String type, Class clazz, String algorithm) throws NoSuchAlgorithmException {
// in the almost all cases, the first service will work
// avoid taking long path if so
ProviderList list = Providers.getProviderList();
Service firstService = list.getService(type, algorithm);
if (firstService == null) {
throw new NoSuchAlgorithmException(algorithm + " " + type + " not available");
}
NoSuchAlgorithmException failure;
try {
return getInstance(firstService, clazz);
} catch (NoSuchAlgorithmException e) {
failure = e;
}
// fail over to the next
for (Service s : list.getServices(type, algorithm)) {
if (s == firstService) {
// do not retry initial failed service
continue;
}
try {
return getInstance(s, clazz);
} catch (NoSuchAlgorithmException e) {
failure = e;
}
}
throw failure;
}
use of java.security.Provider.Service in project j2objc by google.
the class GetInstance method getInstance.
public static Instance getInstance(String type, Class clazz, String algorithm, Object param) throws NoSuchAlgorithmException {
List<Service> services = getServices(type, algorithm);
NoSuchAlgorithmException failure = null;
for (Service s : services) {
try {
return getInstance(s, clazz, param);
} catch (NoSuchAlgorithmException e) {
failure = e;
}
}
if (failure != null) {
throw failure;
} else {
throw new NoSuchAlgorithmException(algorithm + " " + type + " not available");
}
}
Aggregations