aboutsummaryrefslogtreecommitdiffstats
path: root/libraries/spongycastle/core/src/main/java/org/spongycastle/crypto/io/SignerInputStream.java
blob: f7f6935fa10fcb1f5e611ac8f46a934192c67702 (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.spongycastle.crypto.io;

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

import org.spongycastle.crypto.Signer;

public class SignerInputStream
    extends FilterInputStream
{
    protected Signer signer;

    public SignerInputStream(
        InputStream stream,
        Signer      signer)
    {
        super(stream);
        this.signer = signer;
    }

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

        if (b >= 0)
        {
            signer.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)
        {
            signer.update(b, off, n);
        }
        return n;
    }

    public Signer getSigner()
    {
        return signer;
    }
}