This adds methods to MessageDigest and MessageDigestSpi that take ByteBuffers as input.

2006-06-05  C. Scott Marshall  <[EMAIL PROTECTED]>

        * java/security/MessageDigest.java (update): new method.
        * java/security/MessageDigestSpi.java (engineUpdate): new method.


### Eclipse Workspace Patch 1.0
#P classpath-ssl-nio
Index: java/security/MessageDigest.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/security/MessageDigest.java,v
retrieving revision 1.10.2.5
diff -u -r1.10.2.5 MessageDigest.java
--- java/security/MessageDigest.java    2 Mar 2006 09:33:59 -0000       1.10.2.5
+++ java/security/MessageDigest.java    5 Jun 2006 22:12:26 -0000
@@ -38,6 +38,7 @@
 package java.security;
 
 import gnu.java.security.Engine;
+import java.nio.ByteBuffer;
 
 /**
  * Message digests are secure one-way hash functions that take arbitrary-sized
@@ -224,6 +225,17 @@
   }
 
   /**
+   * Updates the digest with the remaining bytes of a buffer.
+   * 
+   * @param input The input byte buffer.
+   * @since 1.5
+   */
+  public void update (ByteBuffer input)
+  {
+    engineUpdate (input);
+  }
+  
+  /**
    * Computes the final digest of the stored data.
    * 
    * @return a byte array representing the message digest.
Index: java/security/MessageDigestSpi.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/security/MessageDigestSpi.java,v
retrieving revision 1.4.2.4
diff -u -r1.4.2.4 MessageDigestSpi.java
--- java/security/MessageDigestSpi.java 2 Aug 2005 20:12:25 -0000       1.4.2.4
+++ java/security/MessageDigestSpi.java 5 Jun 2006 22:12:26 -0000
@@ -37,6 +37,8 @@
 
 package java.security;
 
+import java.nio.ByteBuffer;
+
 /**
    This is the Service Provider Interface (SPI) for MessageDigest
    class in java.security. It provides the back end functionality
@@ -98,6 +100,23 @@
   protected abstract void engineUpdate(byte[]input, int offset, int len);
 
   /**
+   * Updates this digest with the remaining bytes of a byte buffer.
+   * 
+   * @param input The input buffer.
+   * @since 1.5
+   */
+  protected void engineUpdate (ByteBuffer input)
+  {
+    byte[] buf = new byte[1024];
+    while (input.hasRemaining())
+      {
+        int n = Math.min(input.remaining(), buf.length);
+        input.get (buf, 0, n);
+        engineUpdate (buf, 0, n);
+      }
+  }
+  
+  /**
      Computes the final digest of the stored bytes and returns
      them. It performs any necessary padding. The message digest
      should reset sensitive data after performing the digest.

Attachment: PGP.sig
Description: This is a digitally signed message part

Reply via email to