1 package org.bouncycastle.crypto.io; 2 3 import java.io.*; 4 5 import org.bouncycastle.crypto.Digest; 6 7 public class DigestInputStream 8 extends FilterInputStream 9 { 10 protected Digest digest; 11 12 public DigestInputStream( 13 InputStream stream, 14 Digest digest) 15 { 16 super(stream); 17 this.digest = digest; 18 } 19 20 public int read() 21 throws IOException 22 { 23 int b = in.read(); 24 25 if (b >= 0) 26 { 27 digest.update((byte)b); 28 } 29 return b; 30 } 31 32 public int read( 33 byte[] b, 34 int off, 35 int len) 36 throws IOException 37 { 38 int n = in.read(b, off, len); 39 if (n > 0) 40 { 41 digest.update(b, off, n); 42 } 43 return n; 44 } 45 46 public Digest getDigest() 47 { 48 return digest; 49 } 50 } 51