hello there,

the attached patch ensures cloning of HMac implementations.

ChangeLog entry follows:

2006-01-30  Raif S. Naffah  <[EMAIL PROTECTED]>

        * gnu/javax/crypto/mac/HMac.java (clone): Clone ipadHash, opadHash, and
        the ipad buffer.
        * gnu/javax/crypto/mac/BaseMac.java (clone): Clone underlyingHash.

cheers;
rsn
Index: BaseMac.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/javax/crypto/mac/BaseMac.java,v
retrieving revision 1.1
diff -u -r1.1 BaseMac.java
--- BaseMac.java	26 Jan 2006 02:25:09 -0000	1.1
+++ BaseMac.java	30 Jan 2006 08:38:47 -0000
@@ -130,7 +130,11 @@

   public Object clone() throws CloneNotSupportedException
   {
-    return super.clone();
+    BaseMac result = (BaseMac) super.clone();
+    if (this.underlyingHash != null)
+      result.underlyingHash = (IMessageDigest) this.underlyingHash.clone();
+
+    return result;
   }

   // methods to be implemented by concrete subclasses ------------------------
Index: HMac.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/javax/crypto/mac/HMac.java,v
retrieving revision 1.3
diff -u -r1.3 HMac.java
--- HMac.java	28 Jan 2006 13:11:08 -0000	1.3
+++ HMac.java	30 Jan 2006 08:41:07 -0000
@@ -132,12 +132,15 @@

   // java.lang.Cloneable interface implementation ----------------------------

-  public Object clone()
+  public Object clone() throws CloneNotSupportedException
   {
-    HMac result = new HMac((IMessageDigest) underlyingHash.clone());
-    result.ipadHash = this.ipadHash;
-    result.opadHash = this.opadHash;
-    result.ipad = (byte[]) this.ipad.clone();
+    HMac result = (HMac) super.clone();
+    if (this.ipadHash != null)
+      result.ipadHash = (IMessageDigest) this.ipadHash.clone();
+    if (this.opadHash != null)
+      result.opadHash = (IMessageDigest) this.opadHash.clone();
+    if (this.ipad != null)
+      result.ipad = (byte[]) this.ipad.clone();

     return result;
   }

Attachment: pgpyxJ1tlQY7d.pgp
Description: PGP signature

Reply via email to