This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

java.security.DigestInputStream.java


RMS should have my employer waiver by now.  
Here's my first rev of java.security.DigestInputStream:

@ spa:libjava$;cvs -z9 diff -u Makefile.am Makefile.in
cvs -z9 diff -u Makefile.am Makefile.in

Index: Makefile.am

===================================================================

RCS file: /cvs/gcc/gcc/libjava/Makefile.am,v

retrieving revision 1.129.2.7

diff -u -r1.129.2.7 Makefile.am

--- Makefile.am	2001/04/12 09:27:03	1.129.2.7

+++ Makefile.am	2001/04/20 20:09:50

@@ -1092,6 +1092,7 @@

 java/security/AlgorithmParameterGeneratorSpi.java \

 java/security/BasicPermission.java \

 java/security/DigestException.java \

+java/security/DigestInputStream.java \

 java/security/DigestOutputStream.java \

 java/security/GeneralSecurityException.java \

 java/security/Guard.java \

Index: Makefile.in

===================================================================

RCS file: /cvs/gcc/gcc/libjava/Makefile.in,v

retrieving revision 1.139.2.7

diff -u -r1.139.2.7 Makefile.in

--- Makefile.in	2001/04/12 09:27:03	1.139.2.7

+++ Makefile.in	2001/04/20 20:09:51

@@ -816,6 +816,7 @@

 java/security/AlgorithmParameterGeneratorSpi.java \

 java/security/BasicPermission.java \

 java/security/DigestException.java \

+java/security/DigestInputStream.java \

 java/security/DigestOutputStream.java \

 java/security/GeneralSecurityException.java \

 java/security/Guard.java \

/* DigestOutputStream.java --- An output stream tied to a message digest
   Copyright (C) 2001 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.

As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */

package java.security;

import java.io.IOException;
import java.io.EOFException;
import java.io.InputStream;
import java.io.FilterInputStream;
import java.io.PrintStream;
import java.io.ByteArrayInputStream;

public class DigestInputStream extends FilterInputStream {

  /**
   *  The message digest for the DigestInputStream
   */
  protected MessageDigest digest;
  
  // Manages the on flag
  private boolean state = true;

  /**
   * Constructs a new DigestInputStream.  It associates a
   * MessageDigest with the stream to compute the stream as data is
   * written.
   *
   * @param stream An InputStream from which to get the data
   * @param digest A MessageDigest to associate with the stream
   */
  public DigestInputStream(InputStream stream, MessageDigest digest) {
    super(stream);
    this.digest = digest;
  }

  /**
   *  Returns the MessageDigest associated with this DigestInputStream
   *
   * @return The MessageDigest used to hash this stream
   */
  public MessageDigest getMessageDigest () {
    return digest;
  }
  
  /**
   * Sets the current MessageDigest to current parameter
   *
   * @param digest A MessageDigest to associate with this stream
   */
  public void setMessageDigest (MessageDigest digest) {
    this.digest = digest;
  }


  /**
   * Blocking read of one byte, with digest update (if digest is on()).
   *
   * @return the byte read, as an int.
   *
   * @exception IOException on I/O error.
   *
   * @see MessageDigest#update(byte)
   */
  public int read() throws IOException {
    byte[] b = new byte[1];
    if (read(b,0,1) == -1) 
      return -1;
    return (int)b[0];
  }
	
  /**
   * Blocking read of len bytes, with digest update (if digest is on()).
   *
   * @param b destination byte array.
   *
   * @param off offset in b of starting region.
   *
   * @param len maximum number of bytes to be read and placed in b
   *
   * @return the number of bytes read.
   *
   * @exception IOException on I/O error.
   *
   * @see MessageDigest#update(byte)
   */
  public int read(byte[] b, int off, int len) throws IOException {
    int result = in.read(b, off, len);
    if (this.state && result != -1) {
      digest.update(b, off, result);
    }
    return result;
  }

  /**
   * Enable/disable digest operation.
   *
   * @param on true to enable, false to disable digest operation.
   */
  public void on(boolean on) {
    this.state = on;
  }

  /**
   * Converts the input stream and underlying message digest to a string.
   *
   * @return A string representing the output stream and message digest.
   */
  public String toString() {
    return "[Digest Input Stream] " + digest.toString();
  }
}

/* Emacs: -*- java -*- 
 * Local Variables:
 * c-basic-offset: 2
 * End:
 */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]