allow a digest in Stream
authoradam <adam@megacz.com>
Sun, 8 Jul 2007 22:50:33 +0000 (22:50 +0000)
committeradam <adam@megacz.com>
Sun, 8 Jul 2007 22:50:33 +0000 (22:50 +0000)
darcs-hash:20070708225033-5007d-a757b5725305d335ef78660467655225db9d66f2.gz

src/org/ibex/io/ByteBufInputStream.java
src/org/ibex/io/Stream.java

index bede9d2..064b7bd 100644 (file)
@@ -4,6 +4,7 @@
 
 package org.ibex.io;
 import java.io.*;
+import org.ibex.crypto.*;
 
 /** package-private class */
 abstract class ByteBufInputStream extends InputStream {
@@ -13,6 +14,7 @@ abstract class ByteBufInputStream extends InputStream {
     private byte[] buf = new byte[8192];
     private int start = 0;
     private int end = 0;
+    public  Digest digest = null;
     
     public ByteBufInputStream(InputStream is) {
         this.is = is;
@@ -41,6 +43,8 @@ abstract class ByteBufInputStream extends InputStream {
                         start = end = 0;
                         continue;
                     }
+                } else {
+                    if (digest != null) digest.update(buf, 0, end);
                 }
             } while(end==0);
             if (end == -1) { end = 0; return -1; }
index ab52f8a..2cc2e14 100644 (file)
@@ -9,6 +9,7 @@ import java.net.*;
 import java.util.*;
 import java.util.zip.*;
 import org.ibex.util.*;
+import org.ibex.crypto.*;
 
 // Features:
 //   - automatically flush writer before reading on linked read/write pairs
@@ -55,6 +56,8 @@ public class Stream {
     public void   setNewline(String s)             { newLine = s; }
     public InputStream getInputStream() { return in; }
 
+    public void   setInputDigest(Digest d) { in.bbis.digest = d; }
+
     private static class Out extends BufferedOutputStream {
         private Writer writer = new OutputStreamWriter(this);
         public Out(OutputStream out) { super(out); }