home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / java / security / Signature.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-23  |  3.6 KB  |  141 lines

  1. package java.security;
  2.  
  3. public abstract class Signature {
  4.    private static boolean debug;
  5.    private String algorithm;
  6.    protected static final int UNINITIALIZED = 0;
  7.    protected static final int SIGN = 2;
  8.    protected static final int VERIFY = 3;
  9.    protected int state = 0;
  10.  
  11.    protected Signature(String var1) {
  12.       this.algorithm = var1;
  13.    }
  14.  
  15.    public static Signature getInstance(String var0) throws NoSuchAlgorithmException {
  16.       try {
  17.          return (Signature)Security.getImpl(var0, "Signature", (String)null);
  18.       } catch (NoSuchProviderException var1) {
  19.          throw new InternalError("please send a bug report via " + System.getProperty("java.vendor.url.bug"));
  20.       }
  21.    }
  22.  
  23.    public static Signature getInstance(String var0, String var1) throws NoSuchAlgorithmException, NoSuchProviderException {
  24.       return (Signature)Security.getImpl(var0, "Signature", var1);
  25.    }
  26.  
  27.    public final void initVerify(PublicKey var1) throws InvalidKeyException {
  28.       this.engineInitVerify(var1);
  29.       this.state = 3;
  30.    }
  31.  
  32.    public final void initSign(PrivateKey var1) throws InvalidKeyException {
  33.       this.engineInitSign(var1);
  34.       this.state = 2;
  35.    }
  36.  
  37.    public final byte[] sign() throws SignatureException {
  38.       if (this.state == 2) {
  39.          return this.engineSign();
  40.       } else {
  41.          throw new SignatureException("object not initialized for signing.");
  42.       }
  43.    }
  44.  
  45.    public final boolean verify(byte[] var1) throws SignatureException {
  46.       if (this.state == 3) {
  47.          return this.engineVerify(var1);
  48.       } else {
  49.          throw new SignatureException("object not initialized for verification.");
  50.       }
  51.    }
  52.  
  53.    public final void update(byte var1) throws SignatureException {
  54.       if (this.state != 3 && this.state != 2) {
  55.          throw new SignatureException("object not initialized for signature or verification.");
  56.       } else {
  57.          this.engineUpdate(var1);
  58.       }
  59.    }
  60.  
  61.    public final void update(byte[] var1) throws SignatureException {
  62.       this.update(var1, 0, var1.length);
  63.    }
  64.  
  65.    public final void update(byte[] var1, int var2, int var3) throws SignatureException {
  66.       if (this.state != 2 && this.state != 3) {
  67.          throw new SignatureException("object not initialized for signature or verification.");
  68.       } else {
  69.          this.engineUpdate(var1, var2, var3);
  70.       }
  71.    }
  72.  
  73.    public final String getAlgorithm() {
  74.       return this.algorithm;
  75.    }
  76.  
  77.    public String toString() {
  78.       String var1 = "";
  79.       switch (this.state) {
  80.          case 0:
  81.             var1 = "<not initialized>";
  82.          case 1:
  83.          default:
  84.             break;
  85.          case 2:
  86.             var1 = "<initialized for signing>";
  87.             break;
  88.          case 3:
  89.             var1 = "<initialized for verifying>";
  90.       }
  91.  
  92.       return "Signature object: " + this.getAlgorithm() + var1;
  93.    }
  94.  
  95.    public final void setParameter(String var1, Object var2) throws InvalidParameterException {
  96.       this.engineSetParameter(var1, var2);
  97.    }
  98.  
  99.    public final Object getParameter(String var1) throws InvalidParameterException {
  100.       return this.engineGetParameter(var1);
  101.    }
  102.  
  103.    protected abstract void engineInitVerify(PublicKey var1) throws InvalidKeyException;
  104.  
  105.    protected abstract void engineInitSign(PrivateKey var1) throws InvalidKeyException;
  106.  
  107.    protected abstract void engineUpdate(byte var1) throws SignatureException;
  108.  
  109.    protected abstract void engineUpdate(byte[] var1, int var2, int var3) throws SignatureException;
  110.  
  111.    protected abstract byte[] engineSign() throws SignatureException;
  112.  
  113.    protected abstract boolean engineVerify(byte[] var1) throws SignatureException;
  114.  
  115.    protected abstract void engineSetParameter(String var1, Object var2) throws InvalidParameterException;
  116.  
  117.    protected abstract Object engineGetParameter(String var1) throws InvalidParameterException;
  118.  
  119.    public Object clone() throws CloneNotSupportedException {
  120.       if (this instanceof Cloneable) {
  121.          return super.clone();
  122.       } else {
  123.          throw new CloneNotSupportedException();
  124.       }
  125.    }
  126.  
  127.    private static void debug(String var0) {
  128.       if (debug) {
  129.          System.err.println(var0);
  130.       }
  131.  
  132.    }
  133.  
  134.    private static void debug(Exception var0) {
  135.       if (debug) {
  136.          ((Throwable)var0).printStackTrace();
  137.       }
  138.  
  139.    }
  140. }
  141.