home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / java / security / Signature$Delegate.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  5.7 KB  |  257 lines

  1. package java.security;
  2.  
  3. import java.nio.ByteBuffer;
  4. import java.security.spec.AlgorithmParameterSpec;
  5. import java.util.Iterator;
  6. import javax.crypto.Cipher;
  7. import javax.crypto.NoSuchPaddingException;
  8.  
  9. class Signature$Delegate extends Signature {
  10.    private SignatureSpi sigSpi;
  11.    private final Object lock;
  12.    private Provider.Service firstService;
  13.    private Iterator serviceIterator;
  14.    private static int warnCount = 10;
  15.    private static final int I_PUB = 1;
  16.    private static final int I_PRIV = 2;
  17.    private static final int I_PRIV_SR = 3;
  18.  
  19.    Signature$Delegate(SignatureSpi var1, String var2) {
  20.       super(var2);
  21.       this.sigSpi = var1;
  22.       this.lock = null;
  23.    }
  24.  
  25.    Signature$Delegate(Provider.Service var1, Iterator var2, String var3) {
  26.       super(var3);
  27.       this.firstService = var1;
  28.       this.serviceIterator = var2;
  29.       this.lock = new Object();
  30.    }
  31.  
  32.    public Object clone() throws CloneNotSupportedException {
  33.       this.chooseFirstProvider();
  34.       if (this.sigSpi instanceof Cloneable) {
  35.          SignatureSpi var1 = (SignatureSpi)this.sigSpi.clone();
  36.          Signature$Delegate var2 = new Signature$Delegate(var1, Signature.access$000(this));
  37.          var2.provider = super.provider;
  38.          return var2;
  39.       } else {
  40.          throw new CloneNotSupportedException();
  41.       }
  42.    }
  43.  
  44.    private static SignatureSpi newInstance(Provider.Service var0) throws NoSuchAlgorithmException {
  45.       if (var0.getType().equals("Cipher")) {
  46.          try {
  47.             Cipher var3 = Cipher.getInstance("RSA/ECB/PKCS1Padding", var0.getProvider());
  48.             return new Signature.CipherAdapter(var3);
  49.          } catch (NoSuchPaddingException var2) {
  50.             throw new NoSuchAlgorithmException(var2);
  51.          }
  52.       } else {
  53.          Object var1 = var0.newInstance((Object)null);
  54.          if (!(var1 instanceof SignatureSpi)) {
  55.             throw new NoSuchAlgorithmException("Not a SignatureSpi: " + var1.getClass().getName());
  56.          } else {
  57.             return (SignatureSpi)var1;
  58.          }
  59.       }
  60.    }
  61.  
  62.    void chooseFirstProvider() {
  63.       if (this.sigSpi == null) {
  64.          synchronized(this.lock) {
  65.             if (this.sigSpi == null) {
  66.                if (Signature.access$100() != null) {
  67.                   int var2 = --warnCount;
  68.                   if (var2 >= 0) {
  69.                      Signature.access$100().println("Signature.init() not first method called, disabling delayed provider selection");
  70.                      if (var2 == 0) {
  71.                         Signature.access$100().println("Further warnings of this type will be suppressed");
  72.                      }
  73.  
  74.                      (new Exception("Call trace")).printStackTrace();
  75.                   }
  76.                }
  77.  
  78.                NoSuchAlgorithmException var8 = null;
  79.  
  80.                while(this.firstService != null || this.serviceIterator.hasNext()) {
  81.                   Provider.Service var3;
  82.                   if (this.firstService != null) {
  83.                      var3 = this.firstService;
  84.                      this.firstService = null;
  85.                   } else {
  86.                      var3 = (Provider.Service)this.serviceIterator.next();
  87.                   }
  88.  
  89.                   if (Signature.access$200(var3)) {
  90.                      try {
  91.                         this.sigSpi = newInstance(var3);
  92.                         this.provider = var3.getProvider();
  93.                         this.firstService = null;
  94.                         this.serviceIterator = null;
  95.                         return;
  96.                      } catch (NoSuchAlgorithmException var6) {
  97.                         var8 = var6;
  98.                      }
  99.                   }
  100.                }
  101.  
  102.                ProviderException var9 = new ProviderException("Could not construct SignatureSpi instance");
  103.                if (var8 != null) {
  104.                   var9.initCause(var8);
  105.                }
  106.  
  107.                throw var9;
  108.             }
  109.          }
  110.       }
  111.    }
  112.  
  113.    private void chooseProvider(int var1, Key var2, SecureRandom var3) throws InvalidKeyException {
  114.       synchronized(this.lock) {
  115.          if (this.sigSpi != null) {
  116.             this.init(this.sigSpi, var1, var2, var3);
  117.          } else {
  118.             Exception var5 = null;
  119.  
  120.             while(this.firstService != null || this.serviceIterator.hasNext()) {
  121.                Provider.Service var6;
  122.                if (this.firstService != null) {
  123.                   var6 = this.firstService;
  124.                   this.firstService = null;
  125.                } else {
  126.                   var6 = (Provider.Service)this.serviceIterator.next();
  127.                }
  128.  
  129.                if (var6.supportsParameter(var2) && Signature.access$200(var6)) {
  130.                   try {
  131.                      SignatureSpi var7 = newInstance(var6);
  132.                      this.init(var7, var1, var2, var3);
  133.                      this.provider = var6.getProvider();
  134.                      this.sigSpi = var7;
  135.                      this.firstService = null;
  136.                      this.serviceIterator = null;
  137.                      return;
  138.                   } catch (Exception var9) {
  139.                      if (var5 == null) {
  140.                         var5 = var9;
  141.                      }
  142.                   }
  143.                }
  144.             }
  145.  
  146.             if (var5 instanceof InvalidKeyException) {
  147.                throw (InvalidKeyException)var5;
  148.             } else if (var5 instanceof RuntimeException) {
  149.                throw (RuntimeException)var5;
  150.             } else {
  151.                String var11 = var2 != null ? var2.getClass().getName() : "(null)";
  152.                throw new InvalidKeyException("No installed provider supports this key: " + var11, var5);
  153.             }
  154.          }
  155.       }
  156.    }
  157.  
  158.    private void init(SignatureSpi var1, int var2, Key var3, SecureRandom var4) throws InvalidKeyException {
  159.       switch (var2) {
  160.          case 1:
  161.             var1.engineInitVerify((PublicKey)var3);
  162.             break;
  163.          case 2:
  164.             var1.engineInitSign((PrivateKey)var3);
  165.             break;
  166.          case 3:
  167.             var1.engineInitSign((PrivateKey)var3, var4);
  168.             break;
  169.          default:
  170.             throw new AssertionError("Internal error: " + var2);
  171.       }
  172.  
  173.    }
  174.  
  175.    protected void engineInitVerify(PublicKey var1) throws InvalidKeyException {
  176.       if (this.sigSpi != null) {
  177.          this.sigSpi.engineInitVerify(var1);
  178.       } else {
  179.          this.chooseProvider(1, var1, (SecureRandom)null);
  180.       }
  181.  
  182.    }
  183.  
  184.    protected void engineInitSign(PrivateKey var1) throws InvalidKeyException {
  185.       if (this.sigSpi != null) {
  186.          this.sigSpi.engineInitSign(var1);
  187.       } else {
  188.          this.chooseProvider(2, var1, (SecureRandom)null);
  189.       }
  190.  
  191.    }
  192.  
  193.    protected void engineInitSign(PrivateKey var1, SecureRandom var2) throws InvalidKeyException {
  194.       if (this.sigSpi != null) {
  195.          this.sigSpi.engineInitSign(var1, var2);
  196.       } else {
  197.          this.chooseProvider(3, var1, var2);
  198.       }
  199.  
  200.    }
  201.  
  202.    protected void engineUpdate(byte var1) throws SignatureException {
  203.       this.chooseFirstProvider();
  204.       this.sigSpi.engineUpdate(var1);
  205.    }
  206.  
  207.    protected void engineUpdate(byte[] var1, int var2, int var3) throws SignatureException {
  208.       this.chooseFirstProvider();
  209.       this.sigSpi.engineUpdate(var1, var2, var3);
  210.    }
  211.  
  212.    protected void engineUpdate(ByteBuffer var1) {
  213.       this.chooseFirstProvider();
  214.       this.sigSpi.engineUpdate(var1);
  215.    }
  216.  
  217.    protected byte[] engineSign() throws SignatureException {
  218.       this.chooseFirstProvider();
  219.       return this.sigSpi.engineSign();
  220.    }
  221.  
  222.    protected int engineSign(byte[] var1, int var2, int var3) throws SignatureException {
  223.       this.chooseFirstProvider();
  224.       return this.sigSpi.engineSign(var1, var2, var3);
  225.    }
  226.  
  227.    protected boolean engineVerify(byte[] var1) throws SignatureException {
  228.       this.chooseFirstProvider();
  229.       return this.sigSpi.engineVerify(var1);
  230.    }
  231.  
  232.    protected boolean engineVerify(byte[] var1, int var2, int var3) throws SignatureException {
  233.       this.chooseFirstProvider();
  234.       return this.sigSpi.engineVerify(var1, var2, var3);
  235.    }
  236.  
  237.    protected void engineSetParameter(String var1, Object var2) throws InvalidParameterException {
  238.       this.chooseFirstProvider();
  239.       this.sigSpi.engineSetParameter(var1, var2);
  240.    }
  241.  
  242.    protected void engineSetParameter(AlgorithmParameterSpec var1) throws InvalidAlgorithmParameterException {
  243.       this.chooseFirstProvider();
  244.       this.sigSpi.engineSetParameter(var1);
  245.    }
  246.  
  247.    protected Object engineGetParameter(String var1) throws InvalidParameterException {
  248.       this.chooseFirstProvider();
  249.       return this.sigSpi.engineGetParameter(var1);
  250.    }
  251.  
  252.    protected AlgorithmParameters engineGetParameters() {
  253.       this.chooseFirstProvider();
  254.       return this.sigSpi.engineGetParameters();
  255.    }
  256. }
  257.