home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / java / security / Signature.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  4.6 KB  |  202 lines

  1. package java.security;
  2.  
  3. import java.security.cert.Certificate;
  4. import java.security.cert.X509Certificate;
  5. import java.security.spec.AlgorithmParameterSpec;
  6. import java.util.Set;
  7.  
  8. public abstract class Signature extends SignatureSpi {
  9.    private static final boolean debug = false;
  10.    private String algorithm;
  11.    private Provider provider;
  12.    protected static final int UNINITIALIZED = 0;
  13.    protected static final int SIGN = 2;
  14.    protected static final int VERIFY = 3;
  15.    protected int state = 0;
  16.  
  17.    protected Signature(String var1) {
  18.       this.algorithm = var1;
  19.    }
  20.  
  21.    public static Signature getInstance(String var0) throws NoSuchAlgorithmException {
  22.       try {
  23.          Object[] var1 = Security.getImpl(var0, "Signature", (String)null);
  24.          if (var1[0] instanceof Signature) {
  25.             Signature var4 = (Signature)var1[0];
  26.             var4.provider = (Provider)var1[1];
  27.             return var4;
  28.          } else {
  29.             Delegate var2 = new Delegate((SignatureSpi)var1[0], var0);
  30.             var2.provider = (Provider)var1[1];
  31.             return var2;
  32.          }
  33.       } catch (NoSuchProviderException var3) {
  34.          throw new NoSuchAlgorithmException(var0 + " not found");
  35.       }
  36.    }
  37.  
  38.    public static Signature getInstance(String var0, String var1) throws NoSuchAlgorithmException, NoSuchProviderException {
  39.       if (var1 != null && var1.length() != 0) {
  40.          Object[] var2 = Security.getImpl(var0, "Signature", var1);
  41.          if (var2[0] instanceof Signature) {
  42.             Signature var4 = (Signature)var2[0];
  43.             var4.provider = (Provider)var2[1];
  44.             return var4;
  45.          } else {
  46.             Delegate var3 = new Delegate((SignatureSpi)var2[0], var0);
  47.             var3.provider = (Provider)var2[1];
  48.             return var3;
  49.          }
  50.       } else {
  51.          throw new IllegalArgumentException("missing provider");
  52.       }
  53.    }
  54.  
  55.    public final Provider getProvider() {
  56.       return this.provider;
  57.    }
  58.  
  59.    public final void initVerify(PublicKey var1) throws InvalidKeyException {
  60.       ((SignatureSpi)this).engineInitVerify(var1);
  61.       this.state = 3;
  62.    }
  63.  
  64.    public final void initVerify(Certificate var1) throws InvalidKeyException {
  65.       if (var1 instanceof X509Certificate) {
  66.          X509Certificate var2 = (X509Certificate)var1;
  67.          Set var3 = var2.getCriticalExtensionOIDs();
  68.          if (var3 != null && !var3.isEmpty() && var3.contains(new String("2.5.29.15"))) {
  69.             boolean[] var4 = var2.getKeyUsage();
  70.             if (var4 != null && !var4[0]) {
  71.                throw new InvalidKeyException("Wrong key usage");
  72.             }
  73.          }
  74.       }
  75.  
  76.       PublicKey var5 = var1.getPublicKey();
  77.       ((SignatureSpi)this).engineInitVerify(var5);
  78.       this.state = 3;
  79.    }
  80.  
  81.    public final void initSign(PrivateKey var1) throws InvalidKeyException {
  82.       ((SignatureSpi)this).engineInitSign(var1);
  83.       this.state = 2;
  84.    }
  85.  
  86.    public final void initSign(PrivateKey var1, SecureRandom var2) throws InvalidKeyException {
  87.       ((SignatureSpi)this).engineInitSign(var1, var2);
  88.       this.state = 2;
  89.    }
  90.  
  91.    public final byte[] sign() throws SignatureException {
  92.       if (this.state == 2) {
  93.          return ((SignatureSpi)this).engineSign();
  94.       } else {
  95.          throw new SignatureException("object not initialized for signing");
  96.       }
  97.    }
  98.  
  99.    public final int sign(byte[] var1, int var2, int var3) throws SignatureException {
  100.       if (var1 == null) {
  101.          throw new IllegalArgumentException("No output buffer given");
  102.       } else if (var1.length - var2 < var3) {
  103.          throw new IllegalArgumentException("Output buffer too small for specified offset and length");
  104.       } else if (this.state != 2) {
  105.          throw new SignatureException("object not initialized for signing");
  106.       } else {
  107.          return ((SignatureSpi)this).engineSign(var1, var2, var3);
  108.       }
  109.    }
  110.  
  111.    public final boolean verify(byte[] var1) throws SignatureException {
  112.       if (this.state == 3) {
  113.          return ((SignatureSpi)this).engineVerify(var1);
  114.       } else {
  115.          throw new SignatureException("object not initialized for verification");
  116.       }
  117.    }
  118.  
  119.    public final void update(byte var1) throws SignatureException {
  120.       if (this.state != 3 && this.state != 2) {
  121.          throw new SignatureException("object not initialized for signature or verification");
  122.       } else {
  123.          ((SignatureSpi)this).engineUpdate(var1);
  124.       }
  125.    }
  126.  
  127.    public final void update(byte[] var1) throws SignatureException {
  128.       this.update(var1, 0, var1.length);
  129.    }
  130.  
  131.    public final void update(byte[] var1, int var2, int var3) throws SignatureException {
  132.       if (this.state != 2 && this.state != 3) {
  133.          throw new SignatureException("object not initialized for signature or verification");
  134.       } else {
  135.          ((SignatureSpi)this).engineUpdate(var1, var2, var3);
  136.       }
  137.    }
  138.  
  139.    public final String getAlgorithm() {
  140.       return this.algorithm;
  141.    }
  142.  
  143.    public String toString() {
  144.       String var1 = "";
  145.       switch (this.state) {
  146.          case 0:
  147.             var1 = "<not initialized>";
  148.          case 1:
  149.          default:
  150.             break;
  151.          case 2:
  152.             var1 = "<initialized for signing>";
  153.             break;
  154.          case 3:
  155.             var1 = "<initialized for verifying>";
  156.       }
  157.  
  158.       return "Signature object: " + this.getAlgorithm() + var1;
  159.    }
  160.  
  161.    public final void setParameter(String var1, Object var2) throws InvalidParameterException {
  162.       ((SignatureSpi)this).engineSetParameter(var1, var2);
  163.    }
  164.  
  165.    public final void setParameter(AlgorithmParameterSpec var1) throws InvalidAlgorithmParameterException {
  166.       ((SignatureSpi)this).engineSetParameter(var1);
  167.    }
  168.  
  169.    public final Object getParameter(String var1) throws InvalidParameterException {
  170.       return ((SignatureSpi)this).engineGetParameter(var1);
  171.    }
  172.  
  173.    public Object clone() throws CloneNotSupportedException {
  174.       if (this instanceof Cloneable) {
  175.          return super.clone();
  176.       } else {
  177.          throw new CloneNotSupportedException();
  178.       }
  179.    }
  180.  
  181.    private static void debug(String var0) {
  182.    }
  183.  
  184.    private static void debug(Exception var0) {
  185.    }
  186.  
  187.    // $FF: synthetic method
  188.    static String access$000(Signature var0) {
  189.       return var0.algorithm;
  190.    }
  191.  
  192.    // $FF: synthetic method
  193.    static Provider access$102(Signature var0, Provider var1) {
  194.       return var0.provider = var1;
  195.    }
  196.  
  197.    // $FF: synthetic method
  198.    static Provider access$100(Signature var0) {
  199.       return var0.provider;
  200.    }
  201. }
  202.