diff options
author | Sergio Giro <sgiro@google.com> | 2016-02-01 18:52:42 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2016-02-01 18:52:42 +0000 |
commit | 9218edabd1ef9852bc2f13115dcadc81b442dd6c (patch) | |
tree | 8229ff72c8cbb06f49dce3a8382930919fa6fc2b /bcpkix/src/main/java/org/bouncycastle/cms/CMSCompressedDataParser.java | |
parent | 9b30eb05e5be69d51881a0d1b31e503e97acd784 (diff) | |
parent | 397d32894b89b506dc318e0f83446187c9b76ebe (diff) | |
download | android_external_bouncycastle-9218edabd1ef9852bc2f13115dcadc81b442dd6c.tar.gz android_external_bouncycastle-9218edabd1ef9852bc2f13115dcadc81b442dd6c.tar.bz2 android_external_bouncycastle-9218edabd1ef9852bc2f13115dcadc81b442dd6c.zip |
Merge "Merge remote-tracking branch 'aosp/upstream-master' into merge-152-from-upstream"
Diffstat (limited to 'bcpkix/src/main/java/org/bouncycastle/cms/CMSCompressedDataParser.java')
-rw-r--r-- | bcpkix/src/main/java/org/bouncycastle/cms/CMSCompressedDataParser.java | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/bcpkix/src/main/java/org/bouncycastle/cms/CMSCompressedDataParser.java b/bcpkix/src/main/java/org/bouncycastle/cms/CMSCompressedDataParser.java new file mode 100644 index 0000000..c3da87b --- /dev/null +++ b/bcpkix/src/main/java/org/bouncycastle/cms/CMSCompressedDataParser.java @@ -0,0 +1,72 @@ +package org.bouncycastle.cms; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import org.bouncycastle.asn1.ASN1OctetStringParser; +import org.bouncycastle.asn1.ASN1SequenceParser; +import org.bouncycastle.asn1.BERTags; +import org.bouncycastle.asn1.cms.CompressedDataParser; +import org.bouncycastle.asn1.cms.ContentInfoParser; +import org.bouncycastle.operator.InputExpander; +import org.bouncycastle.operator.InputExpanderProvider; + +/** + * Class for reading a CMS Compressed Data stream. + * <pre> + * CMSCompressedDataParser cp = new CMSCompressedDataParser(inputStream); + * + * process(cp.getContent(new ZlibExpanderProvider()).getContentStream()); + * </pre> + * Note: this class does not introduce buffering - if you are processing large files you should create + * the parser with: + * <pre> + * CMSCompressedDataParser ep = new CMSCompressedDataParser(new BufferedInputStream(inputStream, bufSize)); + * </pre> + * where bufSize is a suitably large buffer size. + */ +public class CMSCompressedDataParser + extends CMSContentInfoParser +{ + public CMSCompressedDataParser( + byte[] compressedData) + throws CMSException + { + this(new ByteArrayInputStream(compressedData)); + } + + public CMSCompressedDataParser( + InputStream compressedData) + throws CMSException + { + super(compressedData); + } + + /** + * Return a typed stream which will allow the reading of the compressed content in + * expanded form. + * + * @param expanderProvider a provider of expander algorithm implementations. + * @return a type stream which will yield the un-compressed content. + * @throws CMSException if there is an exception parsing the CompressedData object. + */ + public CMSTypedStream getContent(InputExpanderProvider expanderProvider) + throws CMSException + { + try + { + CompressedDataParser comData = new CompressedDataParser((ASN1SequenceParser)_contentInfo.getContent(BERTags.SEQUENCE)); + ContentInfoParser content = comData.getEncapContentInfo(); + InputExpander expander = expanderProvider.get(comData.getCompressionAlgorithmIdentifier()); + + ASN1OctetStringParser bytes = (ASN1OctetStringParser)content.getContent(BERTags.OCTET_STRING); + + return new CMSTypedStream(content.getContentType().getId(), expander.getInputStream(bytes.getOctetStream())); + } + catch (IOException e) + { + throw new CMSException("IOException reading compressed content.", e); + } + } +} |