Commit 8ae047f5 authored by Brian Carlstrom's avatar Brian Carlstrom Committed by Android (Google) Code Review
Browse files

Merge "Change Engine.getInstance interfaces to make usage less error prone"

parents 490a5fc2 6cdb6b7e
...@@ -90,12 +90,9 @@ public class AlgorithmParameterGenerator { ...@@ -90,12 +90,9 @@ public class AlgorithmParameterGenerator {
if (algorithm == null) { if (algorithm == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
synchronized (ENGINE) { Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
ENGINE.getInstance(algorithm, null); return new AlgorithmParameterGenerator((AlgorithmParameterGeneratorSpi) sap.spi,
return new AlgorithmParameterGenerator( sap.provider, algorithm);
(AlgorithmParameterGeneratorSpi) ENGINE.getSpi(), ENGINE.getProvider(),
algorithm);
}
} }
/** /**
...@@ -154,11 +151,9 @@ public class AlgorithmParameterGenerator { ...@@ -154,11 +151,9 @@ public class AlgorithmParameterGenerator {
if (algorithm == null) { if (algorithm == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
synchronized (ENGINE) { Object spi = ENGINE.getInstance(algorithm, provider, null);
ENGINE.getInstance(algorithm, provider, null); return new AlgorithmParameterGenerator((AlgorithmParameterGeneratorSpi) spi, provider,
return new AlgorithmParameterGenerator( algorithm);
(AlgorithmParameterGeneratorSpi) ENGINE.getSpi(), provider, algorithm);
}
} }
/** /**
......
...@@ -94,11 +94,8 @@ public class AlgorithmParameters { ...@@ -94,11 +94,8 @@ public class AlgorithmParameters {
if (algorithm == null) { if (algorithm == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
synchronized (ENGINE) { Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
ENGINE.getInstance(algorithm, null); return new AlgorithmParameters((AlgorithmParametersSpi) sap.spi, sap.provider, algorithm);
return new AlgorithmParameters((AlgorithmParametersSpi) ENGINE.getSpi(),
ENGINE.getProvider(), algorithm);
}
} }
/** /**
...@@ -156,11 +153,8 @@ public class AlgorithmParameters { ...@@ -156,11 +153,8 @@ public class AlgorithmParameters {
if (algorithm == null) { if (algorithm == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
synchronized (ENGINE) { Object spi = ENGINE.getInstance(algorithm, provider, null);
ENGINE.getInstance(algorithm, provider, null); return new AlgorithmParameters((AlgorithmParametersSpi) spi, provider, algorithm);
return new AlgorithmParameters((AlgorithmParametersSpi) ENGINE.getSpi(),
provider, algorithm);
}
} }
/** /**
......
...@@ -78,10 +78,8 @@ public class KeyFactory { ...@@ -78,10 +78,8 @@ public class KeyFactory {
if (algorithm == null) { if (algorithm == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
synchronized (ENGINE) { Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
ENGINE.getInstance(algorithm, null); return new KeyFactory((KeyFactorySpi) sap.spi, sap.provider, algorithm);
return new KeyFactory((KeyFactorySpi) ENGINE.getSpi(), ENGINE.getProvider(), algorithm);
}
} }
/** /**
...@@ -135,10 +133,8 @@ public class KeyFactory { ...@@ -135,10 +133,8 @@ public class KeyFactory {
if (algorithm == null) { if (algorithm == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
synchronized (ENGINE) { Object spi = ENGINE.getInstance(algorithm, provider, null);
ENGINE.getInstance(algorithm, provider, null); return new KeyFactory((KeyFactorySpi) spi, provider, algorithm);
return new KeyFactory((KeyFactorySpi) ENGINE.getSpi(), provider, algorithm);
}
} }
/** /**
......
...@@ -82,13 +82,9 @@ public abstract class KeyPairGenerator extends KeyPairGeneratorSpi { ...@@ -82,13 +82,9 @@ public abstract class KeyPairGenerator extends KeyPairGeneratorSpi {
if (algorithm == null) { if (algorithm == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
Object spi; Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
Provider provider; Object spi = sap.spi;
synchronized (ENGINE) { Provider provider = sap.provider;
ENGINE.getInstance(algorithm, null);
spi = ENGINE.getSpi();
provider = ENGINE.getProvider();
}
if (spi instanceof KeyPairGenerator) { if (spi instanceof KeyPairGenerator) {
KeyPairGenerator result = (KeyPairGenerator) spi; KeyPairGenerator result = (KeyPairGenerator) spi;
result.algorithm = algorithm; result.algorithm = algorithm;
...@@ -149,11 +145,7 @@ public abstract class KeyPairGenerator extends KeyPairGeneratorSpi { ...@@ -149,11 +145,7 @@ public abstract class KeyPairGenerator extends KeyPairGeneratorSpi {
if (algorithm == null) { if (algorithm == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
Object spi; Object spi = ENGINE.getInstance(algorithm, provider, null);
synchronized (ENGINE) {
ENGINE.getInstance(algorithm, provider, null);
spi = ENGINE.getSpi();
}
if (spi instanceof KeyPairGenerator) { if (spi instanceof KeyPairGenerator) {
KeyPairGenerator result = (KeyPairGenerator) spi; KeyPairGenerator result = (KeyPairGenerator) spi;
result.algorithm = algorithm; result.algorithm = algorithm;
......
...@@ -111,13 +111,11 @@ public class KeyStore { ...@@ -111,13 +111,11 @@ public class KeyStore {
if (type == null) { if (type == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
synchronized (ENGINE) { try {
try { Engine.SpiAndProvider sap = ENGINE.getInstance(type, null);
ENGINE.getInstance(type, null); return new KeyStore((KeyStoreSpi) sap.spi, sap.provider, type);
return new KeyStore((KeyStoreSpi) ENGINE.getSpi(), ENGINE.getProvider(), type); } catch (NoSuchAlgorithmException e) {
} catch (NoSuchAlgorithmException e) {
throw new KeyStoreException(e.getMessage()); throw new KeyStoreException(e.getMessage());
}
} }
} }
...@@ -187,14 +185,12 @@ public class KeyStore { ...@@ -187,14 +185,12 @@ public class KeyStore {
throw new NullPointerException(); throw new NullPointerException();
} }
// return KeyStore instance // return KeyStore instance
synchronized (ENGINE) { try {
try { Object spi = ENGINE.getInstance(type, provider, null);
ENGINE.getInstance(type, provider, null); return new KeyStore((KeyStoreSpi) spi, provider, type);
return new KeyStore((KeyStoreSpi) ENGINE.getSpi(), provider, type); } catch (Exception e) {
} catch (Exception e) {
// override exception // override exception
throw new KeyStoreException(e.getMessage()); throw new KeyStoreException(e.getMessage());
}
} }
} }
......
...@@ -88,20 +88,16 @@ public abstract class MessageDigest extends MessageDigestSpi { ...@@ -88,20 +88,16 @@ public abstract class MessageDigest extends MessageDigestSpi {
if (algorithm == null) { if (algorithm == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
Object spi; Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
Provider provider; Object spi = sap.spi;
synchronized (ENGINE) { Provider provider = sap.provider;
ENGINE.getInstance(algorithm, null);
spi = ENGINE.getSpi();
provider = ENGINE.getProvider();
}
if (spi instanceof MessageDigest) { if (spi instanceof MessageDigest) {
MessageDigest result = (MessageDigest) spi; MessageDigest result = (MessageDigest) spi;
result.algorithm = algorithm; result.algorithm = algorithm;
result.provider = provider; result.provider = provider;
return result; return result;
} }
return new MessageDigestImpl((MessageDigestSpi) spi, provider, algorithm); return new MessageDigestImpl((MessageDigestSpi) sap.spi, sap.provider, algorithm);
} }
/** /**
...@@ -158,11 +154,7 @@ public abstract class MessageDigest extends MessageDigestSpi { ...@@ -158,11 +154,7 @@ public abstract class MessageDigest extends MessageDigestSpi {
if (algorithm == null) { if (algorithm == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
Object spi; Object spi = ENGINE.getInstance(algorithm, provider, null);
synchronized (ENGINE) {
ENGINE.getInstance(algorithm, provider, null);
spi = ENGINE.getSpi();
}
if (spi instanceof MessageDigest) { if (spi instanceof MessageDigest) {
MessageDigest result = (MessageDigest) spi; MessageDigest result = (MessageDigest) spi;
result.algorithm = algorithm; result.algorithm = algorithm;
......
...@@ -126,12 +126,8 @@ public abstract class Policy { ...@@ -126,12 +126,8 @@ public abstract class Policy {
} }
try { try {
synchronized (ENGINE) { Engine.SpiAndProvider sap = ENGINE.getInstance(type, params);
ENGINE.getInstance(type, params); return new PolicyDelegate((PolicySpi) sap.spi, sap.provider, type, params);
return new PolicyDelegate((PolicySpi) ENGINE.getSpi(),
ENGINE.getProvider(), type, params);
}
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
if (e.getCause() == null) { if (e.getCause() == null) {
throw e; throw e;
...@@ -242,11 +238,8 @@ public abstract class Policy { ...@@ -242,11 +238,8 @@ public abstract class Policy {
} }
try { try {
synchronized (ENGINE) { Object spi = ENGINE.getInstance(type, provider, params);
ENGINE.getInstance(type, provider, params); return new PolicyDelegate((PolicySpi) spi, provider, type, params);
return new PolicyDelegate((PolicySpi) ENGINE.getSpi(), provider,
type, params);
}
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
if (e.getCause() == null) { if (e.getCause() == null) {
throw e; throw e;
......
...@@ -124,11 +124,9 @@ public class SecureRandom extends Random { ...@@ -124,11 +124,9 @@ public class SecureRandom extends Random {
if (algorithm == null) { if (algorithm == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
synchronized (ENGINE) { Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
ENGINE.getInstance(algorithm, null); return new SecureRandom((SecureRandomSpi) sap.spi, sap.provider,
return new SecureRandom((SecureRandomSpi) ENGINE.getSpi(), ENGINE.getProvider(), algorithm);
algorithm);
}
} }
/** /**
...@@ -185,10 +183,8 @@ public class SecureRandom extends Random { ...@@ -185,10 +183,8 @@ public class SecureRandom extends Random {
if (algorithm == null) { if (algorithm == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
synchronized (ENGINE) { Object spi = ENGINE.getInstance(algorithm, provider, null);
ENGINE.getInstance(algorithm, provider, null); return new SecureRandom((SecureRandomSpi) spi, provider, algorithm);
return new SecureRandom((SecureRandomSpi) ENGINE.getSpi(), provider, algorithm);
}
} }
/** /**
......
...@@ -101,13 +101,9 @@ public abstract class Signature extends SignatureSpi { ...@@ -101,13 +101,9 @@ public abstract class Signature extends SignatureSpi {
if (algorithm == null) { if (algorithm == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
Object spi; Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
Provider provider; Object spi = sap.spi;
synchronized (ENGINE) { Provider provider = sap.provider;
ENGINE.getInstance(algorithm, null);
spi = ENGINE.getSpi();
provider = ENGINE.getProvider();
}
if (spi instanceof Signature) { if (spi instanceof Signature) {
Signature result = (Signature) spi; Signature result = (Signature) spi;
result.algorithm = algorithm; result.algorithm = algorithm;
...@@ -179,11 +175,7 @@ public abstract class Signature extends SignatureSpi { ...@@ -179,11 +175,7 @@ public abstract class Signature extends SignatureSpi {
private static Signature getSignatureInstance(String algorithm, private static Signature getSignatureInstance(String algorithm,
Provider provider) throws NoSuchAlgorithmException { Provider provider) throws NoSuchAlgorithmException {
Object spi; Object spi = ENGINE.getInstance(algorithm, provider, null);
synchronized (ENGINE) {
ENGINE.getInstance(algorithm, provider, null);
spi = ENGINE.getSpi();
}
if (spi instanceof Signature) { if (spi instanceof Signature) {
Signature result = (Signature) spi; Signature result = (Signature) spi;
result.algorithm = algorithm; result.algorithm = algorithm;
......
...@@ -105,11 +105,8 @@ public class CertPathBuilder { ...@@ -105,11 +105,8 @@ public class CertPathBuilder {
if (algorithm == null) { if (algorithm == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
synchronized (ENGINE) { Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
ENGINE.getInstance(algorithm, null); return new CertPathBuilder((CertPathBuilderSpi) sap.spi, sap.provider, algorithm);
return new CertPathBuilder((CertPathBuilderSpi) ENGINE.getSpi(),
ENGINE.getProvider(), algorithm);
}
} }
/** /**
...@@ -165,10 +162,8 @@ public class CertPathBuilder { ...@@ -165,10 +162,8 @@ public class CertPathBuilder {
if (algorithm == null) { if (algorithm == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
synchronized (ENGINE) { Object spi = ENGINE.getInstance(algorithm, provider, null);
ENGINE.getInstance(algorithm, provider, null); return new CertPathBuilder((CertPathBuilderSpi) spi, provider, algorithm);
return new CertPathBuilder((CertPathBuilderSpi) ENGINE.getSpi(), provider, algorithm);
}
} }
/** /**
......
...@@ -104,11 +104,8 @@ public class CertPathValidator { ...@@ -104,11 +104,8 @@ public class CertPathValidator {
if (algorithm == null) { if (algorithm == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
synchronized (ENGINE) { Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
ENGINE.getInstance(algorithm, null); return new CertPathValidator((CertPathValidatorSpi) sap.spi, sap.provider, algorithm);
return new CertPathValidator((CertPathValidatorSpi) ENGINE.getSpi(),
ENGINE.getProvider(), algorithm);
}
} }
/** /**
...@@ -166,11 +163,8 @@ public class CertPathValidator { ...@@ -166,11 +163,8 @@ public class CertPathValidator {
if (algorithm == null) { if (algorithm == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
synchronized (ENGINE) { Object spi = ENGINE.getInstance(algorithm, provider, null);
ENGINE.getInstance(algorithm, provider, null); return new CertPathValidator((CertPathValidatorSpi) spi, provider, algorithm);
return new CertPathValidator((CertPathValidatorSpi) ENGINE.getSpi(),
provider, algorithm);
}
} }
/** /**
......
...@@ -101,11 +101,8 @@ public class CertStore { ...@@ -101,11 +101,8 @@ public class CertStore {
throw new NullPointerException(); throw new NullPointerException();
} }
try { try {
synchronized (ENGINE) { Engine.SpiAndProvider sap = ENGINE.getInstance(type, params);
ENGINE.getInstance(type, params); return new CertStore((CertStoreSpi) sap.spi, sap.provider, type, params);
return new CertStore((CertStoreSpi) ENGINE.getSpi(), ENGINE.getProvider(),
type, params);
}
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
Throwable th = e.getCause(); Throwable th = e.getCause();
if (th == null) { if (th == null) {
...@@ -182,11 +179,8 @@ public class CertStore { ...@@ -182,11 +179,8 @@ public class CertStore {
throw new NullPointerException(); throw new NullPointerException();
} }
try { try {
synchronized (ENGINE) { Object spi = ENGINE.getInstance(type, provider, params);
ENGINE.getInstance(type, provider, params); return new CertStore((CertStoreSpi) spi, provider, type, params);
return new CertStore((CertStoreSpi) ENGINE.getSpi(), provider, type,
params);
}
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
Throwable th = e.getCause(); Throwable th = e.getCause();
if (th == null) { if (th == null) {
......
...@@ -87,11 +87,8 @@ public class CertificateFactory { ...@@ -87,11 +87,8 @@ public class CertificateFactory {
throw new NullPointerException(); throw new NullPointerException();
} }
try { try {
synchronized (ENGINE) { Engine.SpiAndProvider sap = ENGINE.getInstance(type, null);
ENGINE.getInstance(type, null); return new CertificateFactory((CertificateFactorySpi) sap.spi, sap.provider, type);
return new CertificateFactory((CertificateFactorySpi) ENGINE.getSpi(),
ENGINE.getProvider(), type);
}
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
throw new CertificateException(e); throw new CertificateException(e);
} }
...@@ -156,11 +153,8 @@ public class CertificateFactory { ...@@ -156,11 +153,8 @@ public class CertificateFactory {
throw new NullPointerException(); throw new NullPointerException();
} }
try { try {
synchronized (ENGINE) { Object spi = ENGINE.getInstance(type, provider, null);
ENGINE.getInstance(type, provider, null); return new CertificateFactory((CertificateFactorySpi) spi, provider, type);
return new CertificateFactory((CertificateFactorySpi) ENGINE.getSpi(),
provider, type);
}
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
throw new CertificateException(e.getMessage()); throw new CertificateException(e.getMessage());
} }
......
...@@ -264,51 +264,54 @@ public class Cipher { ...@@ -264,51 +264,54 @@ public class Cipher {
boolean needSetPadding = false; boolean needSetPadding = false;
boolean needSetMode = false; boolean needSetMode = false;
Object engineSpi; Object engineSpi = null;
Provider engineProvider; Provider engineProvider = provider;
synchronized (ENGINE) { if (transf[1] == null && transf[2] == null) { // "algorithm"
if (transf[1] == null && transf[2] == null) { // "algorithm" if (provider == null) {
if (provider == null) { Engine.SpiAndProvider sap = ENGINE.getInstance(transf[0], null);
ENGINE.getInstance(transf[0], null); engineSpi = sap.spi;
} else { engineProvider = sap.provider;
ENGINE.getInstance(transf[0], provider, null);
}
} else { } else {
String[] searhOrder = { engineSpi = ENGINE.getInstance(transf[0], provider, null);
transf[0] + "/" + transf[1] + "/" + transf[2], // "algorithm/mode/padding" }
transf[0] + "/" + transf[1], // "algorithm/mode" } else {
transf[0] + "//" + transf[2], // "algorithm//padding" String[] searchOrder = {
transf[0] // "algorithm" transf[0] + "/" + transf[1] + "/" + transf[2], // "algorithm/mode/padding"
}; transf[0] + "/" + transf[1], // "algorithm/mode"
int i; transf[0] + "//" + transf[2], // "algorithm//padding"
for (i = 0; i < searhOrder.length; i++) { transf[0] // "algorithm"
try { };
if (provider == null) { int i;
ENGINE.getInstance(searhOrder[i], null); for (i = 0; i < searchOrder.length; i++) {
} else { try {
ENGINE.getInstance(searhOrder[i], provider, null); if (provider == null) {
} Engine.SpiAndProvider sap = ENGINE.getInstance(searchOrder[i], null);
break; engineSpi = sap.spi;
} catch (NoSuchAlgorithmException e) { engineProvider = sap.provider;
if ( i == searhOrder.length-1) { } else {
throw new NoSuchAlgorithmException(transformation); engineSpi = ENGINE.getInstance(searchOrder[i], provider, null);
} }
break;
} catch (NoSuchAlgorithmException e) {
if (i == searchOrder.length-1) {
throw new NoSuchAlgorithmException(transformation);
} }
}
switch (i) {
case 1: // "algorithm/mode"
needSetPadding = true;
break;
case 2: // "algorithm//padding"
needSetMode = true;
break;
case 3: // "algorithm"
needSetPadding = true;
needSetMode = true;
} }
} }
engineSpi = ENGINE.getSpi(); switch (i) {
engineProvider = ENGINE.getProvider(); case 1: // "algorithm/mode"
needSetPadding = true;
break;
case 2: // "algorithm//padding"
needSetMode = true;
break;
case 3: // "algorithm"
needSetPadding = true;
needSetMode = true;
}
}
if (engineSpi == null || engineProvider == null) {
throw new NoSuchAlgorithmException(transformation);
} }
if (!(engineSpi instanceof CipherSpi)) { if (!(engineSpi instanceof CipherSpi)) {
throw new NoSuchAlgorithmException(engineSpi.getClass().getName()); throw new NoSuchAlgorithmException(engineSpi.getClass().getName());
......
...@@ -100,11 +100,8 @@ public class ExemptionMechanism { ...@@ -100,11 +100,8 @@ public class ExemptionMechanism {
if (algorithm == null) { if (algorithm == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
synchronized (ENGINE) { Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
ENGINE.getInstance(algorithm, null); return new ExemptionMechanism((ExemptionMechanismSpi) sap.spi, sap.provider, algorithm);
return new ExemptionMechanism((ExemptionMechanismSpi) ENGINE.getSpi(),
ENGINE.getProvider(), algorithm);
}
} }
/** /**
...@@ -167,11 +164,8 @@ public class ExemptionMechanism { ...@@ -167,11 +164,8 @@ public class ExemptionMechanism {
if (provider == null) { if (provider == null) {
throw new IllegalArgumentException("provider == null"); throw new IllegalArgumentException("provider == null");
} }
synchronized (ENGINE) { Object spi = ENGINE.getInstance(algorithm, provider, null);
ENGINE.getInstance(algorithm, provider, null); return new ExemptionMechanism((ExemptionMechanismSpi) spi, provider, algorithm);
return new ExemptionMechanism((ExemptionMechanismSpi) ENGINE.getSpi(),
provider, algorithm);
}
} }
/** /**
......
...@@ -101,11 +101,8 @@ public class KeyAgreement { ...@@ -101,11 +101,8 @@ public class KeyAgreement {
if (algorithm == null) { if (algorithm == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
synchronized (ENGINE) { Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
ENGINE.getInstance(algorithm, null); return new KeyAgreement((KeyAgreementSpi) sap.spi, sap.provider, algorithm);
return new KeyAgreement((KeyAgreementSpi) ENGINE.getSpi(), ENGINE.getProvider(),
algorithm);
}
} }
/** /**
...@@ -166,11 +163,8 @@ public class KeyAgreement { ...@@ -166,11 +163,8 @@ public class KeyAgreement {
if (algorithm == null) { if (algorithm == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
synchronized (ENGINE) { Object spi = ENGINE.getInstance(algorithm, provider, null);
ENGINE.getInstance(algorithm, provider, null); return new KeyAgreement((KeyAgreementSpi) spi, provider, algorithm);
return new KeyAgreement((KeyAgreementSpi) ENGINE.getSpi(), provider,
algorithm);
}
} }
/** /**
......
...@@ -100,11 +100,8 @@ public class KeyGenerator { ...@@ -100,11 +100,8 @@ public class KeyGenerator {
if (algorithm == null) { if (algorithm == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
synchronized (ENGINE) { Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
ENGINE.getInstance(algorithm, null); return new KeyGenerator((KeyGeneratorSpi) sap.spi, sap.provider, algorithm);
return new KeyGenerator((KeyGeneratorSpi) ENGINE.getSpi(), ENGINE.getProvider(),
algorithm);
}
} }
/** /**
...@@ -163,11 +160,8 @@ public class KeyGenerator { ...@@ -163,11 +160,8 @@ public class KeyGenerator {
if (algorithm == null) { if (algorithm == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
synchronized (ENGINE) { Object spi = ENGINE.getInstance(algorithm, provider, null);
ENGINE.getInstance(algorithm, provider, null); return new KeyGenerator((KeyGeneratorSpi) spi, provider, algorithm);
return new KeyGenerator((KeyGeneratorSpi) ENGINE.getSpi(), provider,
algorithm);
}
} }
/** /**
......
...@@ -103,10 +103,8 @@ public class Mac implements Cloneable { ...@@ -103,10 +103,8 @@ public class Mac implements Cloneable {
if (algorithm == null) { if (algorithm == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
synchronized (ENGINE) { Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
ENGINE.getInstance(algorithm, null); return new Mac((MacSpi) sap.spi, sap.provider, algorithm);
return new Mac((MacSpi) ENGINE.getSpi(), ENGINE.getProvider(), algorithm);
}
} }
/** /**
...@@ -167,10 +165,8 @@ public class Mac implements Cloneable { ...@@ -167,10 +165,8 @@ public class Mac implements Cloneable {
if (algorithm == null) { if (algorithm == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
synchronized (ENGINE) { Object spi = ENGINE.getInstance(algorithm, provider, null);
ENGINE.getInstance(algorithm, provider, null); return new Mac((MacSpi) spi, provider, algorithm);
return new Mac((MacSpi) ENGINE.getSpi(), provider, algorithm);
}
} }
/** /**
......
...@@ -105,11 +105,8 @@ public class SecretKeyFactory { ...@@ -105,11 +105,8 @@ public class SecretKeyFactory {
if (algorithm == null) { if (algorithm == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
synchronized (ENGINE) { Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
ENGINE.getInstance(algorithm, null); return new SecretKeyFactory((SecretKeyFactorySpi) sap.spi, sap.provider, algorithm);
return new SecretKeyFactory((SecretKeyFactorySpi) ENGINE.getSpi(),
ENGINE.getProvider(), algorithm);
}
} }
/** /**
...@@ -170,11 +167,8 @@ public class SecretKeyFactory { ...@@ -170,11 +167,8 @@ public class SecretKeyFactory {
if (algorithm == null) { if (algorithm == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
synchronized (ENGINE) { Object spi = ENGINE.getInstance(algorithm, provider, null);
ENGINE.getInstance(algorithm, provider, null); return new SecretKeyFactory((SecretKeyFactorySpi) spi, provider, algorithm);
return new SecretKeyFactory((SecretKeyFactorySpi) ENGINE.getSpi(), provider,
algorithm);
}
} }
/** /**
......
...@@ -76,11 +76,8 @@ public class KeyManagerFactory { ...@@ -76,11 +76,8 @@ public class KeyManagerFactory {
if (algorithm == null) { if (algorithm == null) {
throw new NullPointerException("algorithm is null"); throw new NullPointerException("algorithm is null");
} }
synchronized (ENGINE) { Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
ENGINE.getInstance(algorithm, null); return new KeyManagerFactory((KeyManagerFactorySpi) sap.spi, sap.provider, algorithm);
return new KeyManagerFactory((KeyManagerFactorySpi) ENGINE.getSpi(),
ENGINE.getProvider(), algorithm);
}
} }
/** /**
...@@ -138,11 +135,8 @@ public class KeyManagerFactory { ...@@ -138,11 +135,8 @@ public class KeyManagerFactory {
if (algorithm == null) { if (algorithm == null) {
throw new NullPointerException("algorithm is null"); throw new NullPointerException("algorithm is null");
} }
synchronized (ENGINE) { Object spi = ENGINE.getInstance(algorithm, provider, null);
ENGINE.getInstance(algorithm, provider, null); return new KeyManagerFactory((KeyManagerFactorySpi) spi, provider, algorithm);
return new KeyManagerFactory((KeyManagerFactorySpi) ENGINE.getSpi(), provider,
algorithm);
}
} }
// Store used provider // Store used provider
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment