From ba5a4d78782c981e6e955444281a7867dd7292de Mon Sep 17 00:00:00 2001 From: Casey Marshall Date: Sat, 3 Jun 2006 07:36:50 +0000 Subject: 2006-06-03 Casey Marshall * javax/crypto/Mac.java (update): new method. * javax/crypto/MacSpi.java (engineUpdate): new method. --- javax/crypto/Mac.java | 13 +++++++++++++ javax/crypto/MacSpi.java | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/javax/crypto/Mac.java b/javax/crypto/Mac.java index abbff8b23..055b20a4f 100644 --- a/javax/crypto/Mac.java +++ b/javax/crypto/Mac.java @@ -41,6 +41,7 @@ package javax.crypto; import gnu.java.security.Engine; import java.lang.reflect.InvocationTargetException; +import java.nio.ByteBuffer; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.Key; @@ -397,6 +398,18 @@ public class Mac implements Cloneable macSpi.engineUpdate(input, offset, length); } + /** + * Update this MAC with the remaining bytes in the given buffer + * @param buffer The input buffer. + * @since 1.5 + */ + public final void update (final ByteBuffer buffer) + { + if (virgin) + throw new IllegalStateException ("not initialized"); + macSpi.engineUpdate(buffer); + } + /** * Clone this instance, if the underlying implementation supports it. * diff --git a/javax/crypto/MacSpi.java b/javax/crypto/MacSpi.java index b0f96bff3..853bd66aa 100644 --- a/javax/crypto/MacSpi.java +++ b/javax/crypto/MacSpi.java @@ -38,6 +38,7 @@ exception statement from your version. */ package javax.crypto; +import java.nio.ByteBuffer; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.Key; @@ -142,4 +143,21 @@ public abstract class MacSpi * @param length The number of bytes to update. */ protected abstract void engineUpdate(byte[] input, int offset, int length); + + /** + * Update this MAC with the remaining bytes of a buffer. + * + * @param buffer The input buffer. + * @since 1.5 + */ + protected void engineUpdate (final ByteBuffer buffer) + { + byte[] buf = new byte[1024]; + while (buffer.hasRemaining ()) + { + int n = Math.min (buffer.remaining (), buf.length); + buffer.get (buf, 0, n); + engineUpdate (buf, 0, n); + } + } } -- cgit v1.2.1