1package org.bouncycastle.cms;
2
3import java.io.ByteArrayInputStream;
4import java.io.IOException;
5import java.io.InputStream;
6import java.io.OutputStream;
7
8import org.bouncycastle.asn1.ASN1ObjectIdentifier;
9import org.bouncycastle.asn1.cms.CMSObjectIdentifiers;
10import org.bouncycastle.util.Arrays;
11
12/**
13 * a holding class for a byte array of data to be processed.
14 */
15public class CMSProcessableByteArray
16    implements CMSTypedData, CMSReadable
17{
18    private final ASN1ObjectIdentifier type;
19    private final byte[]  bytes;
20
21    public CMSProcessableByteArray(
22        byte[]  bytes)
23    {
24        this(new ASN1ObjectIdentifier(CMSObjectIdentifiers.data.getId()), bytes);
25    }
26
27    public CMSProcessableByteArray(
28        ASN1ObjectIdentifier type,
29        byte[]  bytes)
30    {
31        this.type = type;
32        this.bytes = bytes;
33    }
34
35    public InputStream getInputStream()
36    {
37        return new ByteArrayInputStream(bytes);
38    }
39
40    public void write(OutputStream zOut)
41        throws IOException, CMSException
42    {
43        zOut.write(bytes);
44    }
45
46    public Object getContent()
47    {
48        return Arrays.clone(bytes);
49    }
50
51    public ASN1ObjectIdentifier getContentType()
52    {
53        return type;
54    }
55}
56