package org.bouncycastle.cms;
import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.asn1.cms.CompressedData;
import org.bouncycastle.asn1.cms.ContentInfo;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.InflaterInputStream;
/**
* containing class for an CMS Compressed Data object
*/
public class CMSCompressedData
{
ContentInfo contentInfo;
public CMSCompressedData(
byte[] compressedData)
throws CMSException
{
this(CMSUtils.readContentInfo(compressedData));
}
public CMSCompressedData(
InputStream compressedData)
throws CMSException
{
this(CMSUtils.readContentInfo(compressedData));
}
public CMSCompressedData(
ContentInfo contentInfo)
throws CMSException
{
this.contentInfo = contentInfo;
}
public byte[] getContent()
throws CMSException
{
CompressedData comData = CompressedData.getInstance(contentInfo.getContent());
ContentInfo content = comData.getEncapContentInfo();
ASN1OctetString bytes = (ASN1OctetString)content.getContent();
InflaterInputStream zIn = new InflaterInputStream(new ByteArrayInputStream(bytes.getOctets()));
try
{
return CMSUtils.streamToByteArray(zIn);
}
catch (IOException e)
{
throw new CMSException("exception reading compressed stream.", e);
}
}
/**
* return the ContentInfo
*/
public ContentInfo getContentInfo()
{
return contentInfo;
}
/**
* return the ASN.1 encoded representation of this object.
*/
public byte[] getEncoded()
throws IOException
{
return contentInfo.getEncoded();
}
}