Welcome to mirror list, hosted at ThFree Co, Russian Federation.

DigestInputStream.java « io « crypto « bouncycastle « org « java « main « src « core - gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ef0b03e26b940cb96a2adc46f19fb26c513f7662 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package org.bouncycastle.crypto.io;

import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.bouncycastle.crypto.Digest;

public class DigestInputStream
    extends FilterInputStream
{
    protected Digest digest;

    public DigestInputStream(
        InputStream stream,
        Digest      digest)
    {
        super(stream);
        this.digest = digest;
    }

    public int read()
        throws IOException
    {
        int b = in.read();

        if (b >= 0)
        {
            digest.update((byte)b);
        }
        return b;
    }

    public int read(
        byte[] b,
        int off,
        int len)
        throws IOException
    {
        int n = in.read(b, off, len);
        if (n > 0)
        {
            digest.update(b, off, n);
        }
        return n;
    }

    public Digest getDigest()
    {
        return digest;
    }
}