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

BufferingContentSigner.java « operator « bouncycastle « org « java « main « src « pkix - gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d174367299861d914b65ee253ab884b6f20843dd (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package org.bouncycastle.operator;

import java.io.OutputStream;

import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.util.io.BufferingOutputStream;

/**
 * A class that explicitly buffers the data to be signed, sending it in one
 * block when ready for signing.
 */
public class BufferingContentSigner
    implements ContentSigner
{
    private final ContentSigner contentSigner;
    private final OutputStream  output;

    /**
     * Base constructor.
     *
     * @param contentSigner the content signer to be wrapped.
     */
    public BufferingContentSigner(ContentSigner contentSigner)
    {
        this.contentSigner = contentSigner;
        this.output = new BufferingOutputStream(contentSigner.getOutputStream());
    }

    /**
     * Base constructor.
     *
     * @param contentSigner the content signer to be wrapped.
     * @param bufferSize the size of the internal buffer to use.
     */
    public BufferingContentSigner(ContentSigner contentSigner, int bufferSize)
    {
        this.contentSigner = contentSigner;
        this.output = new BufferingOutputStream(contentSigner.getOutputStream(), bufferSize);
    }

    /**
     * Return the algorithm identifier supported by this signer.
     *
     * @return algorithm identifier for the signature generated.
     */
    public AlgorithmIdentifier getAlgorithmIdentifier()
    {
        return contentSigner.getAlgorithmIdentifier();
    }

    /**
     * Return the buffering stream.
     *
     * @return the output stream used to accumulate the data.
     */
    public OutputStream getOutputStream()
    {
        return output;
    }

    /**
     * Generate signature from internally buffered data.
     *
     * @return the signature calculated from the bytes written to the buffering stream.
     */
    public byte[] getSignature()
    {
        return contentSigner.getSignature();
    }
}