home *** CD-ROM | disk | FTP | other *** search
- package java.security;
-
- import java.nio.ByteBuffer;
- import java.security.spec.AlgorithmParameterSpec;
- import java.util.Iterator;
- import javax.crypto.Cipher;
- import javax.crypto.NoSuchPaddingException;
-
- class Signature$Delegate extends Signature {
- private SignatureSpi sigSpi;
- private final Object lock;
- private Provider.Service firstService;
- private Iterator serviceIterator;
- private static int warnCount = 10;
- private static final int I_PUB = 1;
- private static final int I_PRIV = 2;
- private static final int I_PRIV_SR = 3;
-
- Signature$Delegate(SignatureSpi var1, String var2) {
- super(var2);
- this.sigSpi = var1;
- this.lock = null;
- }
-
- Signature$Delegate(Provider.Service var1, Iterator var2, String var3) {
- super(var3);
- this.firstService = var1;
- this.serviceIterator = var2;
- this.lock = new Object();
- }
-
- public Object clone() throws CloneNotSupportedException {
- this.chooseFirstProvider();
- if (this.sigSpi instanceof Cloneable) {
- SignatureSpi var1 = (SignatureSpi)this.sigSpi.clone();
- Signature$Delegate var2 = new Signature$Delegate(var1, Signature.access$000(this));
- var2.provider = super.provider;
- return var2;
- } else {
- throw new CloneNotSupportedException();
- }
- }
-
- private static SignatureSpi newInstance(Provider.Service var0) throws NoSuchAlgorithmException {
- if (var0.getType().equals("Cipher")) {
- try {
- Cipher var3 = Cipher.getInstance("RSA/ECB/PKCS1Padding", var0.getProvider());
- return new Signature.CipherAdapter(var3);
- } catch (NoSuchPaddingException var2) {
- throw new NoSuchAlgorithmException(var2);
- }
- } else {
- Object var1 = var0.newInstance((Object)null);
- if (!(var1 instanceof SignatureSpi)) {
- throw new NoSuchAlgorithmException("Not a SignatureSpi: " + var1.getClass().getName());
- } else {
- return (SignatureSpi)var1;
- }
- }
- }
-
- void chooseFirstProvider() {
- if (this.sigSpi == null) {
- synchronized(this.lock) {
- if (this.sigSpi == null) {
- if (Signature.access$100() != null) {
- int var2 = --warnCount;
- if (var2 >= 0) {
- Signature.access$100().println("Signature.init() not first method called, disabling delayed provider selection");
- if (var2 == 0) {
- Signature.access$100().println("Further warnings of this type will be suppressed");
- }
-
- (new Exception("Call trace")).printStackTrace();
- }
- }
-
- NoSuchAlgorithmException var8 = null;
-
- while(this.firstService != null || this.serviceIterator.hasNext()) {
- Provider.Service var3;
- if (this.firstService != null) {
- var3 = this.firstService;
- this.firstService = null;
- } else {
- var3 = (Provider.Service)this.serviceIterator.next();
- }
-
- if (Signature.access$200(var3)) {
- try {
- this.sigSpi = newInstance(var3);
- this.provider = var3.getProvider();
- this.firstService = null;
- this.serviceIterator = null;
- return;
- } catch (NoSuchAlgorithmException var6) {
- var8 = var6;
- }
- }
- }
-
- ProviderException var9 = new ProviderException("Could not construct SignatureSpi instance");
- if (var8 != null) {
- var9.initCause(var8);
- }
-
- throw var9;
- }
- }
- }
- }
-
- private void chooseProvider(int var1, Key var2, SecureRandom var3) throws InvalidKeyException {
- synchronized(this.lock) {
- if (this.sigSpi != null) {
- this.init(this.sigSpi, var1, var2, var3);
- } else {
- Exception var5 = null;
-
- while(this.firstService != null || this.serviceIterator.hasNext()) {
- Provider.Service var6;
- if (this.firstService != null) {
- var6 = this.firstService;
- this.firstService = null;
- } else {
- var6 = (Provider.Service)this.serviceIterator.next();
- }
-
- if (var6.supportsParameter(var2) && Signature.access$200(var6)) {
- try {
- SignatureSpi var7 = newInstance(var6);
- this.init(var7, var1, var2, var3);
- this.provider = var6.getProvider();
- this.sigSpi = var7;
- this.firstService = null;
- this.serviceIterator = null;
- return;
- } catch (Exception var9) {
- if (var5 == null) {
- var5 = var9;
- }
- }
- }
- }
-
- if (var5 instanceof InvalidKeyException) {
- throw (InvalidKeyException)var5;
- } else if (var5 instanceof RuntimeException) {
- throw (RuntimeException)var5;
- } else {
- String var11 = var2 != null ? var2.getClass().getName() : "(null)";
- throw new InvalidKeyException("No installed provider supports this key: " + var11, var5);
- }
- }
- }
- }
-
- private void init(SignatureSpi var1, int var2, Key var3, SecureRandom var4) throws InvalidKeyException {
- switch (var2) {
- case 1:
- var1.engineInitVerify((PublicKey)var3);
- break;
- case 2:
- var1.engineInitSign((PrivateKey)var3);
- break;
- case 3:
- var1.engineInitSign((PrivateKey)var3, var4);
- break;
- default:
- throw new AssertionError("Internal error: " + var2);
- }
-
- }
-
- protected void engineInitVerify(PublicKey var1) throws InvalidKeyException {
- if (this.sigSpi != null) {
- this.sigSpi.engineInitVerify(var1);
- } else {
- this.chooseProvider(1, var1, (SecureRandom)null);
- }
-
- }
-
- protected void engineInitSign(PrivateKey var1) throws InvalidKeyException {
- if (this.sigSpi != null) {
- this.sigSpi.engineInitSign(var1);
- } else {
- this.chooseProvider(2, var1, (SecureRandom)null);
- }
-
- }
-
- protected void engineInitSign(PrivateKey var1, SecureRandom var2) throws InvalidKeyException {
- if (this.sigSpi != null) {
- this.sigSpi.engineInitSign(var1, var2);
- } else {
- this.chooseProvider(3, var1, var2);
- }
-
- }
-
- protected void engineUpdate(byte var1) throws SignatureException {
- this.chooseFirstProvider();
- this.sigSpi.engineUpdate(var1);
- }
-
- protected void engineUpdate(byte[] var1, int var2, int var3) throws SignatureException {
- this.chooseFirstProvider();
- this.sigSpi.engineUpdate(var1, var2, var3);
- }
-
- protected void engineUpdate(ByteBuffer var1) {
- this.chooseFirstProvider();
- this.sigSpi.engineUpdate(var1);
- }
-
- protected byte[] engineSign() throws SignatureException {
- this.chooseFirstProvider();
- return this.sigSpi.engineSign();
- }
-
- protected int engineSign(byte[] var1, int var2, int var3) throws SignatureException {
- this.chooseFirstProvider();
- return this.sigSpi.engineSign(var1, var2, var3);
- }
-
- protected boolean engineVerify(byte[] var1) throws SignatureException {
- this.chooseFirstProvider();
- return this.sigSpi.engineVerify(var1);
- }
-
- protected boolean engineVerify(byte[] var1, int var2, int var3) throws SignatureException {
- this.chooseFirstProvider();
- return this.sigSpi.engineVerify(var1, var2, var3);
- }
-
- protected void engineSetParameter(String var1, Object var2) throws InvalidParameterException {
- this.chooseFirstProvider();
- this.sigSpi.engineSetParameter(var1, var2);
- }
-
- protected void engineSetParameter(AlgorithmParameterSpec var1) throws InvalidAlgorithmParameterException {
- this.chooseFirstProvider();
- this.sigSpi.engineSetParameter(var1);
- }
-
- protected Object engineGetParameter(String var1) throws InvalidParameterException {
- this.chooseFirstProvider();
- return this.sigSpi.engineGetParameter(var1);
- }
-
- protected AlgorithmParameters engineGetParameters() {
- this.chooseFirstProvider();
- return this.sigSpi.engineGetParameters();
- }
- }
-