src/share/classes/sun/security/provider/DigestBase.java

Print this page

        

@@ -37,11 +37,10 @@
  * implement the following methods:
  *
  *  . abstract void implCompress(byte[] b, int ofs);
  *  . abstract void implDigest(byte[] out, int ofs);
  *  . abstract void implReset();
- *  . public abstract Object clone();
  *
  * See the inline documentation for details.
  *
  * @since   1.5
  * @author  Andreas Sterbenz

@@ -59,11 +58,11 @@
     // size of the input to the compression function in bytes
     private final int blockSize;
     // buffer to store partial blocks, blockSize bytes large
     // Subclasses should not access this array directly except possibly in their
     // implDigest() method. See MD5.java as an example.
-    final byte[] buffer;
+    byte[] buffer;
     // offset into buffer
     private int bufOfs;
 
     // number of bytes processed so far. subclasses should not modify
     // this value.

@@ -81,22 +80,10 @@
         this.digestLength = digestLength;
         this.blockSize = blockSize;
         buffer = new byte[blockSize];
     }
 
-    /**
-     * Constructor for cloning. Replicates common data.
-     */
-    DigestBase(DigestBase base) {
-        this.algorithm = base.algorithm;
-        this.digestLength = base.digestLength;
-        this.blockSize = base.blockSize;
-        this.buffer = base.buffer.clone();
-        this.bufOfs = base.bufOfs;
-        this.bytesProcessed = base.bytesProcessed;
-    }
-
     // return digest length. See JCA doc.
     protected final int engineGetDigestLength() {
         return digestLength;
     }
 

@@ -204,16 +191,15 @@
      * Reset subclass specific state to their initial values. DigestBase
      * calls this method when necessary.
      */
     abstract void implReset();
 
-    /**
-     * Clone this digest. Should be implemented as "return new MyDigest(this)".
-     * That constructor should first call "super(baseDigest)" and then copy
-     * subclass specific data.
-     */
-    public abstract Object clone();
+    public Object clone() throws CloneNotSupportedException {
+        DigestBase copy = (DigestBase) super.clone();
+        copy.buffer = copy.buffer.clone();
+        return copy;
+    }
 
     // padding used for the MD5, and SHA-* message digests
     static final byte[] padding;
 
     static {

@@ -221,7 +207,6 @@
         // and an additional 8 bytes for the high 8 bytes of the 16
         // byte bit counter in SHA-384/512
         padding = new byte[136];
         padding[0] = (byte)0x80;
     }
-
 }