[kaffe] CVS kaffe (dalibor): Resynced with GNU Crypto

Kaffe CVS cvs-commits at kaffe.org
Sun Aug 15 19:09:03 PDT 2004


PatchSet 5069 
Date: 2004/08/16 00:41:14
Author: dalibor
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU Crypto

2004-08-15  Dalibor Topic  <robilad at kaffe.org>

        * libraries/javalib/java/security/DummyMessageDigest.java:
        New file. Taken from GNU Classpath.

        * libraries/javalib/java/security/MessageDigest.java,
        libraries/javalib/java/security/SignatureSpi.java:
        Replaced by implementation from GNU Classpath.

        * libraries/javalib/Makefile.am,
        libraries/javalib/Makefile.in,
        libraries/javalib/all.files:
        Regenerated.

        * libraries/javalib/gnu/crypto/pki/provider/DSASignature.java:
        Resynced with GNU Crypto.

        2004-08-12  Casey Marshall <csm at gnu.org>

        * source/gnu/crypto/pki/provider/DSASignature.java
        (<init>): initialize digest here.
        (init): removed initialization of digest, and remove unnecessary
        catches.
        Reported by Dalibor Topic <robilad at kaffe.org>

Members: 
	ChangeLog:1.2627->1.2628 
	libraries/javalib/Makefile.am:1.220->1.221 
	libraries/javalib/Makefile.in:1.297->1.298 
	libraries/javalib/all.files:1.14->1.15 
	libraries/javalib/gnu/crypto/pki/provider/DSASignature.java:1.1->1.2 
	libraries/javalib/java/security/DummyMessageDigest.java:INITIAL->1.1 
	libraries/javalib/java/security/MessageDigest.java:1.5->1.6 
	libraries/javalib/java/security/SignatureSpi.java:1.2->1.3 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2627 kaffe/ChangeLog:1.2628
--- kaffe/ChangeLog:1.2627	Sun Aug 15 22:34:15 2004
+++ kaffe/ChangeLog	Mon Aug 16 00:41:14 2004
@@ -1,3 +1,28 @@
+2004-08-15  Dalibor Topic  <robilad at kaffe.org>
+
+	* libraries/javalib/java/security/DummyMessageDigest.java:
+	New file. Taken from GNU Classpath.
+
+	* libraries/javalib/java/security/MessageDigest.java,
+	libraries/javalib/java/security/SignatureSpi.java:
+	Replaced by implementation from GNU Classpath.
+
+	* libraries/javalib/Makefile.am,
+	libraries/javalib/Makefile.in,
+	libraries/javalib/all.files:
+	Regenerated.
+
+	* libraries/javalib/gnu/crypto/pki/provider/DSASignature.java:
+	Resynced with GNU Crypto.
+
+	2004-08-12  Casey Marshall <csm at gnu.org>
+
+        * source/gnu/crypto/pki/provider/DSASignature.java
+        (<init>): initialize `digest' here.
+        (init): removed initialization of `digest', and remove unnecessary
+        catches.
+        Reported by Dalibor Topic <robilad at kaffe.org>
+
 2004-08-15  Mark Wielaard  <mark at klomp.org>
 
 	* libraries/javalib/kaffe/tools/jar/Jar.java
Index: kaffe/libraries/javalib/Makefile.am
diff -u kaffe/libraries/javalib/Makefile.am:1.220 kaffe/libraries/javalib/Makefile.am:1.221
--- kaffe/libraries/javalib/Makefile.am:1.220	Sun Aug 15 20:50:40 2004
+++ kaffe/libraries/javalib/Makefile.am	Mon Aug 16 00:41:19 2004
@@ -2174,6 +2174,7 @@
 	java/security/DigestInputStream.java \
 	java/security/DigestOutputStream.java \
 	java/security/DomainCombiner.java \
+	java/security/DummyMessageDigest.java \
 	java/security/GeneralSecurityException.java \
 	java/security/Guard.java \
 	java/security/GuardedObject.java \
Index: kaffe/libraries/javalib/Makefile.in
diff -u kaffe/libraries/javalib/Makefile.in:1.297 kaffe/libraries/javalib/Makefile.in:1.298
--- kaffe/libraries/javalib/Makefile.in:1.297	Sun Aug 15 20:50:40 2004
+++ kaffe/libraries/javalib/Makefile.in	Mon Aug 16 00:41:20 2004
@@ -2657,6 +2657,7 @@
 	java/security/DigestInputStream.java \
 	java/security/DigestOutputStream.java \
 	java/security/DomainCombiner.java \
+	java/security/DummyMessageDigest.java \
 	java/security/GeneralSecurityException.java \
 	java/security/Guard.java \
 	java/security/GuardedObject.java \
Index: kaffe/libraries/javalib/all.files
diff -u kaffe/libraries/javalib/all.files:1.14 kaffe/libraries/javalib/all.files:1.15
--- kaffe/libraries/javalib/all.files:1.14	Sun Aug 15 20:50:43 2004
+++ kaffe/libraries/javalib/all.files	Mon Aug 16 00:41:21 2004
@@ -1739,6 +1739,7 @@
 java/security/DigestInputStream.java
 java/security/DigestOutputStream.java
 java/security/DomainCombiner.java
+java/security/DummyMessageDigest.java
 java/security/GeneralSecurityException.java
 java/security/Guard.java
 java/security/GuardedObject.java
Index: kaffe/libraries/javalib/gnu/crypto/pki/provider/DSASignature.java
diff -u kaffe/libraries/javalib/gnu/crypto/pki/provider/DSASignature.java:1.1 kaffe/libraries/javalib/gnu/crypto/pki/provider/DSASignature.java:1.2
--- kaffe/libraries/javalib/gnu/crypto/pki/provider/DSASignature.java:1.1	Wed Jul 21 01:41:55 2004
+++ kaffe/libraries/javalib/gnu/crypto/pki/provider/DSASignature.java	Mon Aug 16 00:41:22 2004
@@ -75,23 +75,13 @@
   private DSAPrivateKey privateKey;
   private MessageDigest digest = null;
 
-  public DSASignature()
+  public DSASignature() throws NoSuchAlgorithmException
   {
+    digest = MessageDigest.getInstance("SHA-160");
   }
 
   private void init()
   {
-    if (digest == null)
-      {
-        try
-          {
-            digest = MessageDigest.getInstance("SHA-160");
-          }
-        catch (NoSuchAlgorithmException nsae)
-          {
-            throw new Error(nsae);
-          }
-      }
     digest.reset();
   }
 
@@ -264,19 +254,5 @@
     throws InvalidParameterException
   {
     throw new InvalidParameterException();
-  }
-
-  public Object clone() throws CloneNotSupportedException
-  {
-    return new DSASignature(this);
-  }
-
-  private DSASignature(DSASignature copy) throws CloneNotSupportedException
-  {
-    this();
-    this.publicKey = copy.publicKey;
-    this.privateKey = copy.privateKey;
-    if (copy.digest != null)
-      this.digest = (MessageDigest) copy.digest.clone();
   }
 }
===================================================================
Checking out kaffe/libraries/javalib/java/security/DummyMessageDigest.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/java/security/DummyMessageDigest.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/java/security/DummyMessageDigest.java	Mon Aug 16 02:09:02 2004
@@ -0,0 +1,93 @@
+/* DummyMessageDigest.java - Wrapper for MessageDigestSpi
+   Copyright (C) 1999, 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.security;
+
+final class DummyMessageDigest extends MessageDigest
+{
+  private MessageDigestSpi mdSpi = null;
+
+  public DummyMessageDigest(MessageDigestSpi mdSpi, String algorithm)
+  {
+    super(algorithm);
+    this.mdSpi = mdSpi;
+  }
+
+  public Object clone() throws CloneNotSupportedException
+  {
+    if (!(mdSpi instanceof Cloneable))
+      throw new CloneNotSupportedException();
+
+    MessageDigest result = new DummyMessageDigest
+	((MessageDigestSpi) mdSpi.clone(), this.getAlgorithm());
+    result.provider = this.getProvider();
+    return result;
+  }
+
+  // java.security.MessageDigestSpi abstract methods implementation ---------
+
+  public byte[] engineDigest()
+  {
+    return mdSpi.engineDigest();
+  }
+
+  public int engineDigest(byte[] buf, int offset, int len)
+    throws DigestException
+  {
+    return mdSpi.engineDigest(buf, offset, len);
+  }
+
+  public int engineGetDigestLength()
+  {
+    return mdSpi.engineGetDigestLength();
+  }
+
+  public void engineReset()
+  {
+    mdSpi.engineReset();
+  }
+
+  public void engineUpdate(byte input)
+  {
+    mdSpi.engineUpdate(input);
+  }
+
+  public void engineUpdate(byte[] input, int offset, int len)
+  {
+    mdSpi.engineUpdate(input, offset, len);
+  }
+}
Index: kaffe/libraries/javalib/java/security/MessageDigest.java
diff -u kaffe/libraries/javalib/java/security/MessageDigest.java:1.5 kaffe/libraries/javalib/java/security/MessageDigest.java:1.6
--- kaffe/libraries/javalib/java/security/MessageDigest.java:1.5	Wed May 14 06:06:30 2003
+++ kaffe/libraries/javalib/java/security/MessageDigest.java	Mon Aug 16 00:41:24 2004
@@ -1,163 +1,413 @@
+/* MessageDigest.java --- The message digest interface.
+   Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc.
 
-/*
- * Java core library component.
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+package java.security;
+
+import gnu.java.security.Engine;
+
+/**
+ * <p>This <code>MessageDigest</code> class provides applications the
+ * functionality of a message digest algorithm, such as <i>MD5</i> or <i>SHA</i>.
+ * Message digests are secure one-way hash functions that take arbitrary-sized
+ * data and output a fixed-length hash value.</p>
+ *
+ * <p>A <code>MessageDigest</code> object starts out initialized. The data is
+ * processed through it using the <code>update()</code> methods. At any point
+ * <code>reset()</code> can be called to reset the digest. Once all the data to
+ * be updated has been updated, one of the <code>digest()</code> methods should
+ * be called to complete the hash computation.</p>
+ *
+ * <p>The <code>digest()</code> method can be called <b>once</b> for a given
+ * number of updates. After <code>digest()</code> has been called, the
+ * <code>MessageDigest</code> object is <b>reset</b> to its initialized state.
+ * </p>
  *
- * Copyright (c) 1999
- *	Archie L. Cobbs.  All rights reserved.
- * Copyright (c) 1999
- *	Transvirtual Technologies, Inc.  All rights reserved.
+ * <p>Implementations are free to implement the {@link Cloneable} interface.
+ * Client applications can test cloneability by attempting cloning and catching
+ * the {@link CloneNotSupportedException}:
  *
- * See the file "license.terms" for information on usage and redistribution
- * of this file.
+ * <pre>
+ *    MessageDigest md = MessageDigest.getInstance("SHA");
+ *    try
+ *      {
+ *        md.update(toChapter1);
+ *        MessageDigest tc1 = md.clone();
+ *        byte[] toChapter1Digest = tc1.digest();
+ *        md.update(toChapter2);
+ *        // ...
+ *      }
+ *    catch (CloneNotSupportedException x)
+ *      {
+ *        throw new DigestException("couldn't make digest of partial content");
+ *      }
+ * </pre>
  *
- * Author: Archie L. Cobbs <archie at whistle.com>
+ * <p>Note that if a given implementation is not cloneable, it is still possible
+ * to compute intermediate digests by instantiating several instances, if the
+ * number of digests is known in advance.</p>
+ *
+ * <p>Note that this class is abstract and extends from {@link MessageDigestSpi}
+ * for historical reasons. Application developers should only take notice of the
+ * methods defined in this <code>MessageDigest</code> class; all the methods in
+ * the superclass are intended for cryptographic service providers who wish to
+ * supply their own implementations of message digest algorithms.</p>
+ *
+ * @see MessageDigestSpi
+ * @see Provider
+ * @since JDK 1.1
  */
+public abstract class MessageDigest extends MessageDigestSpi
+{
+  /** The service name for message digests. */
+  private static final String MESSAGE_DIGEST = "MessageDigest";
+
+  private String algorithm;
+  Provider provider;
+  private byte[] lastDigest;
+
+  /**
+   * Creates a message digest with the specified algorithm name.
+   *
+   * @param algorithm the standard name of the digest algorithm. 
+   * See Appendix A in the Java Cryptography Architecture API 
+   * Specification &amp; Reference for information about standard 
+   * algorithm names.
+   */
+  protected MessageDigest(String algorithm)
+  {
+    this.algorithm = algorithm;
+    provider = null;
+  }
+
+  /**
+   * Generates a <code>MessageDigest</code> object that implements the specified
+   * digest algorithm. If the default provider package provides an
+   * implementation of the requested digest algorithm, an instance of
+   * <code>MessageDigest</code> containing that implementation is returned. If
+   * the algorithm is not available in the default package, other packages are
+   * searched.
+   *
+   * @param algorithm the name of the algorithm requested. See Appendix A in the
+   * Java Cryptography Architecture API Specification &amp; Reference for
+   * information about standard algorithm names.
+   * @return a Message Digest object implementing the specified algorithm.
+   * @throws NoSuchAlgorithmException if the algorithm is not available in the
+   * caller's environment.
+   */
+  public static MessageDigest getInstance(String algorithm)
+    throws NoSuchAlgorithmException
+  {
+    Provider[] p = Security.getProviders();
+    for (int i = 0; i < p.length; i++)
+      {
+	try
+	  {
+	    return getInstance(algorithm, p[i]);
+	  }
+	catch (NoSuchAlgorithmException ignored) {}
+      }
+
+    throw new NoSuchAlgorithmException(algorithm);
+  }
+
+  /**
+   * Generates a <code>MessageDigest</code> object implementing the specified
+   * algorithm, as supplied from the specified provider, if such an algorithm is
+   * available from the provider.
+   *
+   * @param algorithm the name of the algorithm requested. See Appendix A in the
+   * Java Cryptography Architecture API Specification &amp; Reference for
+   * information about standard algorithm names.
+   * @param provider the name of the provider.
+   * @return a Message Digest object implementing the specified algorithm.
+   * @throws NoSuchAlgorithmException if the algorithm is not available in the
+   * package supplied by the requested provider.
+   * @throws NoSuchProviderException if the provider is not available in the
+   * environment.
+   * @throws IllegalArgumentException if the provider name is null or empty.
+   * @see Provider
+   */
+  public static MessageDigest getInstance(String algorithm, String provider)
+    throws NoSuchAlgorithmException, NoSuchProviderException
+  {
+    if (provider == null || provider.length() == 0)
+      throw new IllegalArgumentException("Illegal provider");
+
+    Provider p = Security.getProvider(provider);
+    if (p == null)
+      throw new NoSuchProviderException(provider);
+
+    return getInstance(algorithm, p);
+  }
+
+  /**
+   * Generates a <code>MessageDigest</code> object implementing the specified
+   * algorithm, as supplied from the specified provider, if such an algorithm
+   * is available from the provider. Note: the provider doesn't have to be
+   * registered.
+   *
+   * @param algorithm the name of the algorithm requested. See Appendix A in
+   * the Java Cryptography Architecture API Specification &amp; Reference for
+   * information about standard algorithm names.
+   * @param provider the provider.
+   * @return a Message Digest object implementing the specified algorithm.
+   * @throws NoSuchAlgorithmException if the <code>algorithm</code> is not
+   * available in the package supplied by the requested <code>provider</code>.
+   * @throws IllegalArgumentException if the <code>provider</code> is
+   * <code>null</code>.
+   * @since 1.4
+   * @see Provider
+   */
+  public static MessageDigest getInstance(String algorithm, Provider provider)
+    throws NoSuchAlgorithmException
+  {
+    if (provider == null)
+      throw new IllegalArgumentException("Illegal provider");
+
+    MessageDigest result = null;
+    Object o = null;
+    try
+      {
+        o = Engine.getInstance(MESSAGE_DIGEST, algorithm, provider);
+      }
+    catch (java.lang.reflect.InvocationTargetException ite)
+      {
+	throw new NoSuchAlgorithmException(algorithm);
+      }
+     
+    if (o instanceof MessageDigestSpi)
+      {
+	result = new DummyMessageDigest((MessageDigestSpi) o, algorithm);
+      }
+    else if (o instanceof MessageDigest)
+      {
+	result = (MessageDigest) o;
+	result.algorithm = algorithm;
+      }
+    else
+      {
+        throw new NoSuchAlgorithmException(algorithm);
+      }
+    result.provider = provider;
+    return result;
+  }
+
+  /**
+   * Returns the provider of this message digest object.
+   *
+   * @return the provider of this message digest object.
+   */
+  public final Provider getProvider()
+  {
+    return provider;
+  }
+
+  /**
+   * Updates the digest using the specified byte.
+   *
+   * @param input the byte with which to update the digest.
+   */
+  public void update(byte input)
+  {
+    engineUpdate(input);
+  }
+
+  /**
+   * Updates the digest using the specified array of bytes, starting at the
+   * specified offset.
+   *
+   * @param input the array of bytes.
+   * @param offset the offset to start from in the array of bytes.
+   * @param len the number of bytes to use, starting at offset.
+   */
+  public void update(byte[] input, int offset, int len)
+  {
+    engineUpdate(input, offset, len);
+  }
+
+  /**
+   * Updates the digest using the specified array of bytes.
+   *
+   * @param input the array of bytes.
+   */
+  public void update(byte[] input)
+  {
+    engineUpdate(input, 0, input.length);
+  }
+
+  /**
+   * Completes the hash computation by performing final operations such as
+   * padding. The digest is reset after this call is made.
+   *
+   * @return the array of bytes for the resulting hash value.
+   */
+  public byte[] digest()
+  {
+    return lastDigest = engineDigest();
+  }
+
+  /**
+   * Completes the hash computation by performing final operations such as
+   * padding. The digest is reset after this call is made.
+   *
+   * @param buf An output buffer for the computed digest.
+   * @param offset The offset into the output buffer to begin storing the digest.
+   * @param len The number of bytes within buf allotted for the digest.
+   * @return The number of bytes placed into buf.
+   * @throws DigestException if an error occurs.
+   */
+  public int digest(byte[] buf, int offset, int len) throws DigestException
+  {
+    return engineDigest(buf, offset, len);
+  }
+
+  /**
+   * Performs a final update on the digest using the specified array of bytes,
+   * then completes the digest computation. That is, this method first calls
+   * <code>update(input)</code>, passing the input array to the <code>update()
+   * </code> method, then calls <code>digest()</code>.
+   *
+   * @param input the input to be updated before the digest is completed.
+   * @return the array of bytes for the resulting hash value.
+   */
+  public byte[] digest(byte[] input)
+  {
+    update(input);
+    return digest();
+  }
+
+  /**
+   * Returns a string representation of this message digest object.
+   *
+   * @return a string representation of the object.
+   */
+  public String toString()
+  {
+    return (getClass()).getName() + " Message Digest <" + digestToString() + ">";
+  }
+
+  /**
+   * Compares two digests for equality. Does a simple byte compare.
+   *
+   * @param digesta one of the digests to compare.
+   * @param digestb the other digest to compare.
+   * @return <code>true</code> if the digests are equal, <code>false</code>
+   * otherwise.
+   */
+  public static boolean isEqual(byte[] digesta, byte[] digestb)
+  {
+    if (digesta.length != digestb.length)
+      return false;
+
+    for (int i = digesta.length - 1; i >= 0; --i)
+      if (digesta[i] != digestb[i])
+	return false;
+
+    return true;
+  }
+
+  /** Resets the digest for further use. */
+  public void reset()
+  {
+    engineReset();
+  }
+
+  /**
+   * Returns a string that identifies the algorithm, independent of
+   * implementation details. The name should be a standard Java Security name
+   * (such as <code>"SHA"</code>, <code>"MD5"</code>, and so on). See Appendix
+   * A in the Java Cryptography Architecture API Specification &amp; Reference
+   * for information about standard algorithm names.
+   *
+   * @return the name of the algorithm.
+   */
+  public final String getAlgorithm()
+  {
+    return algorithm;
+  }
+
+  /**
+   * Returns the length of the digest in bytes, or <code>0</code> if this
+   * operation is not supported by the provider and the implementation is not
+   * cloneable.
+   *
+   * @return the digest length in bytes, or <code>0</code> if this operation is
+   * not supported by the provider and the implementation is not cloneable.
+   * @since 1.2
+   */
+  public final int getDigestLength()
+  {
+    return engineGetDigestLength();
+  }
+
+  /**
+   * Returns a clone if the implementation is cloneable.
+   *
+   * @return a clone if the implementation is cloneable.
+   * @throws CloneNotSupportedException if this is called on an implementation
+   * that does not support {@link Cloneable}.
+   */
+  public Object clone() throws CloneNotSupportedException
+  {
+    if (this instanceof Cloneable)
+      return super.clone();
+    else
+      throw new CloneNotSupportedException();
+  }
+
+  private String digestToString()
+  {
+    byte[] digest = lastDigest;
+
+    if (digest == null)
+      return "incomplete";
+
+    StringBuffer buf = new StringBuffer();
+    int len = digest.length;
+    for (int i = 0; i < len; ++i)
+      {
+	byte b = digest[i];
+	byte high = (byte) ((b & 0xff) >>> 4);
+	byte low = (byte) (b & 0xf);
+
+	buf.append(high > 9 ? ('a' - 10) + high : '0' + high);
+	buf.append(low > 9 ? ('a' - 10) + low : '0' + low);
+      }
 
-package java.security;
-
-import java.util.Arrays;
-
-// Note: it is a historical screwup that this class extends MessageDigestSpi.
-// It should not but does. Unfortunately, MessageDigestSpi is abstract, and
-// this class inherits that abstractness. As a consequence, a number of classes
-// that should extend MessageDigestSpi extend MessageDigest instead.
-
-// On the other hand, *some* classes that should extend MessageDigestSpi
-// *do* extend it. We need to handle that too.
-
-// Therefore, this class proxies all calls to its engine-- but the engine is,
-// by default, 'this'. When we need to construct a MessageDigest object
-// wrapping a MessageDigestSpi object, we use a concrete subclass of
-// MessageDigest, NonSpiMessageDigest, and change its 'engine' field
-// to the actual MessageDigestSpi. Calling engine methods on a
-// NonSpiMessageDigest object throws an UnsupportedOperationException.
-
-public abstract class MessageDigest extends MessageDigestSpi {
-	private static final String ENGINE_CLASS = "MessageDigest";
-	private final String algorithm;
-        private MessageDigestSpi engine = this;
-	private Provider provider;
-
-	protected MessageDigest(String algorithm) {
-		this.algorithm = algorithm;
-	}
-
-	public static MessageDigest getInstance(String algorithm)
-			throws NoSuchAlgorithmException {
-		return getInstance(Security.getCryptInstance(
-			ENGINE_CLASS, algorithm));
-	}
-
-	public static MessageDigest getInstance(String algorithm, String prov)
-			throws NoSuchAlgorithmException,
-				NoSuchProviderException {
-		return getInstance(Security.getCryptInstance(
-			ENGINE_CLASS, algorithm, prov));
-	}
-
-	private static MessageDigest getInstance(Security.Engine e) {
-		MessageDigest md;
-		Object o = e.getEngine();
-		if(o instanceof MessageDigest) {
-			md = (MessageDigest)o;
-		} else {
-			md = new NonSpiMessageDigest(e.algorithm);
-			md.engine = (MessageDigestSpi)o;
-		}
-
-		md.provider = e.getProvider();
-		return md;
-	}
-
-	public final Provider getProvider() {
-		return provider;
-	}
-
-	public void update(byte input) {
-		engine.engineUpdate(input);
-	}
-
-	public void update(byte[] input, int offset, int len) {
-		engine.engineUpdate(input, offset, len);
-	}
-
-	public void update(byte[] input) {
-		update(input, 0, input.length);
-	}
-
-	public byte[] digest() {
-		byte[] rtn = engine.engineDigest();
-		engine.engineReset();
-		return rtn;
-	}
-
-	public int digest(byte[] buf, int offset, int len)
-			throws DigestException {
-		int digestLen = engine.engineGetDigestLength();
-		if (len < digestLen) {
-			throw new DigestException("buf.length < " + digestLen);
-		}
-		System.arraycopy(digest(), 0, buf, offset, digestLen);
-		return digestLen;
-	}
-
-	public byte[] digest(byte[] input) {
-		update(input);
-		return digest();
-	}
-
-	// XXX what should we do here?
-	public String toString() {
-		return super.toString();
-	}
-
-	public static boolean isEqual(byte[] digesta, byte[] digestb) {
-		return Arrays.equals(digesta, digestb);
-	}
-
-	public void reset() {
-		engine.engineReset();
-	}
-
-	public final String getAlgorithm() {
-		return algorithm;
-	}
-
-	public final int getDigestLength() {
-		return engine.engineGetDigestLength();
-	}
-
-	public Object clone() throws CloneNotSupportedException {
-		return super.clone();
-	}
-
-	private static String NONSPI_MSG =
-		"This MessageDigest is not a MessageDigestSpi. "+
-		"MessageDigestSpi methods should not be used "+
-		"on MessageDigest objects."; 
-
-	private static class NonSpiMessageDigest extends MessageDigest {
-		protected NonSpiMessageDigest(String algorithm) {
-			super(algorithm);
-		}
-		protected int engineGetDigestLength() {
-			throw new UnsupportedOperationException(NONSPI_MSG);
-		}
-		protected void engineUpdate(byte input) {
-			throw new UnsupportedOperationException(NONSPI_MSG);
-		}
-		protected void engineUpdate(byte[] input, int offset, int len) {
-			throw new UnsupportedOperationException(NONSPI_MSG);
-		}
-		protected byte[] engineDigest() {
-			throw new UnsupportedOperationException(NONSPI_MSG);
-		}
-		protected int engineDigest(byte[] buf, int offset, int len) {
-			throw new UnsupportedOperationException(NONSPI_MSG);
-		}
-		protected void engineReset() {
-			throw new UnsupportedOperationException(NONSPI_MSG);
-		}
-	}
+    return buf.toString();
+  }
 }
-
Index: kaffe/libraries/javalib/java/security/SignatureSpi.java
diff -u kaffe/libraries/javalib/java/security/SignatureSpi.java:1.2 kaffe/libraries/javalib/java/security/SignatureSpi.java:1.3
--- kaffe/libraries/javalib/java/security/SignatureSpi.java:1.2	Sun May 12 15:08:45 2002
+++ kaffe/libraries/javalib/java/security/SignatureSpi.java	Mon Aug 16 00:41:24 2004
@@ -1,71 +1,302 @@
+/* SignatureSpi.java --- Signature Service Provider Interface
+   Copyright (C) 1999, 2003, Free Software Foundation, Inc.
 
-/*
- * Java core library component.
- *
- * Copyright (c) 1999
- *	Archie L. Cobbs.  All rights reserved.
- * Copyright (c) 1999
- *	Transvirtual Technologies, Inc.  All rights reserved.
- *
- * See the file "license.terms" for information on usage and redistribution
- * of this file.
- *
- * Author: Archie L. Cobbs <archie at whistle.com>
- */
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
 
 package java.security;
 
 import java.security.spec.AlgorithmParameterSpec;
 
-public abstract class SignatureSpi {
-	protected SecureRandom appRandom;
-
-	public SignatureSpi() {
-	}
-
-	protected abstract void engineInitVerify(PublicKey publicKey)
-			throws InvalidKeyException;
-
-	protected abstract void engineInitSign(PrivateKey privateKey)
-			throws InvalidKeyException;
-
-	// non-abstract for backwards compatibility
-	protected void engineInitSign(PrivateKey privateKey, SecureRandom r)
-			throws InvalidKeyException {
-		throw new UnsupportedOperationException();
-	}
-
-	protected abstract void engineUpdate(byte b)
-			throws SignatureException;
-
-	protected abstract void engineUpdate(byte[] b, int off, int len)
-			throws SignatureException;
-
-	protected abstract byte[] engineSign() throws SignatureException;
-
-	// non-abstract for backwards compatibility
-	protected int engineSign(byte[] outbuf, int offset, int len)
-			throws SignatureException {
-		throw new UnsupportedOperationException();
-	}
-
-	protected abstract boolean engineVerify(byte[] sigBytes)
-			throws SignatureException;
-
-	protected abstract void engineSetParameter(String param, Object value)
-			throws InvalidParameterException;
-
-	// non-abstract for backwards compatibility
-	protected void engineSetParameter(AlgorithmParameterSpec params)
-		throws InvalidAlgorithmParameterException {
-		throw new UnsupportedOperationException();
-	}
-
-	protected abstract Object engineGetParameter(String param)
-			throws InvalidParameterException;
-
-	public Object clone() throws CloneNotSupportedException {
-		throw new CloneNotSupportedException();
-	}
+/**
+ * <p>This class defines the <i>Service Provider Interface (SPI)</i> for the
+ * {@link Signature} class, which is used to provide the functionality of a
+ * digital signature algorithm. Digital signatures are used for authentication
+ * and integrity assurance of digital data.</p>
+ *
+ * <p>All the abstract methods in this class must be implemented by each
+ * cryptographic service provider who wishes to supply the implementation of a
+ * particular signature algorithm.
+ *
+ * @author Mark Benvenuto <ivymccough at worldnet.att.net>
+ * @since 1.2
+ * @see Signature
+ */
+public abstract class SignatureSpi
+{
+  /** Application-specified source of randomness. */
+  protected SecureRandom appRandom;
+
+  public SignatureSpi()
+  {
+    appRandom = null;
+  }
+
+  /**
+   * Initializes this signature object with the specified public key for
+   * verification operations.
+   *
+   * @param publicKey the public key of the identity whose signature is going
+   * to be verified.
+   * @throws InvalidKeyException if the key is improperly encoded, parameters
+   * are missing, and so on.
+   */
+  protected abstract void engineInitVerify(PublicKey publicKey)
+    throws InvalidKeyException;
+
+  /**
+   * Initializes this signature object with the specified private key for
+   * signing operations.
+   *
+   * @param privateKey the private key of the identity whose signature will be
+   * generated.
+   * @throws InvalidKeyException if the key is improperly encoded, parameters
+   * are missing, and so on.
+   */
+  protected abstract void engineInitSign(PrivateKey privateKey)
+    throws InvalidKeyException;
+
+  /**
+   * <p>Initializes this signature object with the specified private key and
+   * source of randomness for signing operations.</p>
+   *
+   * <p>This concrete method has been added to this previously-defined abstract
+   * class. (For backwards compatibility, it cannot be abstract.)</p>

*** Patch too long, truncated ***




More information about the kaffe mailing list