From 2be1f59cabb48fd8a8110263f5c9d2a771ed23f9 Mon Sep 17 00:00:00 2001 From: Casey Marshall Date: Wed, 28 Jun 2006 22:56:36 +0000 Subject: 2006-06-28 Casey Marshall * java/security/Signature.java (update): new method. * java/security/SignatureSpi.java (engineUpdate): new method. --- ChangeLog-ssl-nio | 5 +++++ java/security/Signature.java | 17 +++++++++++++++++ java/security/SignatureSpi.java | 19 +++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/ChangeLog-ssl-nio b/ChangeLog-ssl-nio index 4da5570cb..96702f846 100644 --- a/ChangeLog-ssl-nio +++ b/ChangeLog-ssl-nio @@ -1,3 +1,8 @@ +2006-06-28 Casey Marshall + + * java/security/Signature.java (update): new method. + * java/security/SignatureSpi.java (engineUpdate): new method. + 2006-06-10 Casey Marshall * jessie-tests/testClientHello.java: update for extensions diff --git a/java/security/Signature.java b/java/security/Signature.java index 845a77a8b..68ae99d42 100644 --- a/java/security/Signature.java +++ b/java/security/Signature.java @@ -40,6 +40,7 @@ package java.security; import gnu.java.security.Engine; +import java.nio.ByteBuffer; import java.security.cert.Certificate; import java.security.cert.X509Certificate; import java.security.spec.AlgorithmParameterSpec; @@ -467,6 +468,22 @@ public abstract class Signature extends SignatureSpi else throw new SignatureException(); } + + /** + * Update this signature with the {@link java.nio.Buffer#remaining()} + * bytes of the input buffer. + * + * @param input The input buffer. + * @throws SignatureException If this instance was not properly + * initialized. + */ + public final void update(ByteBuffer input) throws SignatureException + { + if (state != UNINITIALIZED) + engineUpdate(input); + else + throw new SignatureException("not initialized"); + } /** * Returns the name of the algorithm currently used. The names of algorithms diff --git a/java/security/SignatureSpi.java b/java/security/SignatureSpi.java index 25d49dedd..3b46815ec 100644 --- a/java/security/SignatureSpi.java +++ b/java/security/SignatureSpi.java @@ -37,6 +37,7 @@ exception statement from your version. */ package java.security; +import java.nio.ByteBuffer; import java.security.spec.AlgorithmParameterSpec; /** @@ -130,6 +131,24 @@ public abstract class SignatureSpi protected abstract void engineUpdate(byte[] b, int off, int len) throws SignatureException; + /** + * Update this signature with the {@link java.nio.Buffer#remaining()} + * bytes of the given buffer. + * + * @param input The input buffer. + * @throws SignatureException + */ + protected void engineUpdate(ByteBuffer input) throws SignatureException + { + byte[] buf = new byte[4096]; + while (input.hasRemaining()) + { + int l = Math.min(input.remaining(), buf.length); + input.get(buf, 0, l); + engineUpdate(buf, 0, l); + } + } + /** * Returns the signature bytes of all the data fed to this instance. The * format of the output depends on the underlying signature algorithm. -- cgit v1.2.1