|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object iaik.cms.CompressedDataStream iaik.cms.CompressedData
public class CompressedData
This class represents the stream-supporting implementation of the CMS content
type CompressedData
.
The compressed-data content type is identified by the following object identifier:
id-ct-compressedData OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs-9(9) smime(16) ct(1) 9 }
which corresponds to the OID string "1.2.840.113549.1.9.16.1.9".
The CompressedData type provides a syntax for compressing/decompressing the content of a CMS message. An algorithm identifier identifies the compression algorithm to be used ( RFC 3274 refers the ZLIB compression algorithm [RFC1950], [RFC1951]) for compressing the encapsulated content:
CompressedData ::= SEQUENCE { version CMSVersion, compressionAlgorithm CompressionAlgorithmIdentifier, encapContentInfo EncapsulatedContentInfo }
When creating
a CompressedData object an application has to decide whether the
compressed content shall be incldued (IMPLICIT
mode) into
the CompressedData message or shall be transmitted by other means
(EXPLICIT
mode):
int mode = CompressedData.IMPLICIT; // include contentor
int mode = CompressedData.EXPLICIT; // do not include contentHowever, in both cases the content data has to be supplied when creating the
CompressedData
object to perform the compression with some
particular compression algorithm, e.g.:
// transmission mode (EXPLICIT or IMPLICIT) int mode = ...; // the content data byte[] content = ...; // compression algorithm AlgorithmID compressionAlg = CMSAlgorithmID.zlib_compress; // create the CompressedData object: CompressedData compressedData = new CompressedData(content, compressionAlg, mode);If the content shall not be included in the CompressedData object (
EXPLICIT
mode) you may get the compressed content byte calling method
getContent)
to transmit it by other means, e.g.:
// in explicit mode get the compressed content to transmit it by other means byte[] compressedContent = null; if (mode == CompressedData.EXPLICIT) { compressedContent = compressedData.getcontent(); }Finally the CompressedData object has to be prepared for transmission by transforming it into an ASN1Object or immediately DER encoding it. The former is done by calling method
toASN1Object
, the latter by using method getEncoded
method:
ASN1Object asn1CompressedData = compressedData.toASN1Object();or
byte[] encoding = compressedData.getEncoded();You alternatively may use a proper
writeTo
method of the parent
CompressedDataStream
class for immediately
encoding this CompressedData object to an output stream. When using writeTo
in
implicit mode, you additionally have the possibility of specifying a particular blockSize
for forcing an indefinite constructed encoding of the inherent compressed content data bytes,
instead of of the default definite primitive encoding, e.g:
0x24 0x80 0x04 0x02 0x01 0xAB 0x04 0x02 0x23 0x7F 0x04 0x01 0xCA 0x00 0x00instead of:
0x04 0x05 0x01 0xAB 0x23 0x7F 0xCAfor encoding the five bytes
0x01 0xAB 0x23 0x7F 0xCA
.
When receiving an CompressedData message use the CompressedData(InputStream)
constructor for parsing the CompressedData
from its DER encoding:
// the input stream supplying the DER encoded CompressedData InputStream encodedStream = ...; // parse the CompressedData CompressedData compressedData = new CompressedData(encodedStream);If the compressed content has been transmitted by other means (
EXPLICIT
mode) it
now has to be supplied by calling method setContent
since it is required for being decompressed:
if (compressedData.getMode() == AuthenticatedData.EXPLICIT) { // in explicit mode explicitly supply the compressed content for being decompressed authenticatedData.setContent(compressedContent); }Finally get the (decompressed) content by calling method
getContent
:
byte[] content = compressedData.getContent();
Field Summary |
---|
Fields inherited from class iaik.cms.CompressedDataStream |
---|
blockSize_, compressionAlgorithm_, contentType, encapContentType_, EXPLICIT, IMPLICIT, inputStream_, version_ |
Constructor Summary | |
---|---|
protected |
CompressedData()
Default constructor for dynamic object creation. |
|
CompressedData(byte[] content,
AlgorithmID compressionAlgorithm,
int mode)
Creates a new CompressedData object for compressing the given content
with the given compression algorithm. |
|
CompressedData(java.io.InputStream is)
Creates a CompressedData object from a DER encoded CompressedData object which is read from the given input stream. |
|
CompressedData(ObjectID contentType,
byte[] content,
AlgorithmID compressionAlgorithm,
int mode)
Creates a new CompressedData object for compressing the given content
with the given compression algorithm. |
|
CompressedData(ObjectID contentType,
byte[] content,
AlgorithmID compressionAlgorithm,
int mode,
SecurityProvider securityProvider)
Creates a new CompressedData object for compressing the given content
with the given compression algorithm. |
Method Summary | |
---|---|
void |
decode(ASN1Object obj)
Decodes the given CompressedData ASN1 object. |
byte[] |
getContent()
Gets the compressed (or decompressed) content. |
byte[] |
getEncoded()
Returns this CompressedData as DER encoded byte array. |
java.io.InputStream |
getInputStream()
Returns an input stream from which the compressed (or decompressed) content can be read. |
void |
setContent(byte[] content)
Sets the content to be compressed/decompressed. |
void |
setInputStream(java.io.InputStream is)
Sets an input stream suppliyng the content to be compressed/decompressed. |
protected ASN1Object |
toASN1Object(int blockSize)
Returns this CompressedData as ASN1Object where a constructed OCTET STRING is used for encoding the content. |
Methods inherited from class iaik.cms.CompressedDataStream |
---|
decode, getBlockSize, getCompressionAlgorithm, getContentType, getEncapsulatedContentType, getMode, getSecurityProvider, getVersion, setBlockSize, setSecurityProvider, toASN1Object, toString, toString, writeTo, writeTo |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface iaik.cms.ContentStream |
---|
decode, getBlockSize, getContentType, setBlockSize, toASN1Object, toString |
Constructor Detail |
---|
protected CompressedData()
public CompressedData(byte[] content, AlgorithmID compressionAlgorithm, int mode) throws java.security.NoSuchAlgorithmException, java.io.IOException
CompressedData
object for compressing the given content
with the given compression algorithm.
The mode
parameter specifies whether to include the compressed data
(mode = CompressedData.IMPLICIT) or not include it (mode = CompressedData.EXPLICIT).
This constrcutor already performs the content compression.
content
- the content data to be compressedcompressionAlgorithm
- the compression algorithm to be usedmode
- either CompressedData.IMPLICIT for including the data, or
CompressedData.EXPLICIT for not including it
java.security.NoSuchAlgorithmException
- if the requested compression algorithm is not supported
java.io.IOException
- if an I/O error occurspublic CompressedData(ObjectID contentType, byte[] content, AlgorithmID compressionAlgorithm, int mode) throws java.security.NoSuchAlgorithmException, java.io.IOException
CompressedData
object for compressing the given content
with the given compression algorithm.
The mode
parameter specifies whether to include the compressed data
(mode = CompressedData.IMPLICIT) or not include it (mode = CompressedData.EXPLICIT).
This constrcutor already performs the content compression.
contentType
- the content type of the data to be compressedcontent
- the content data to be compressedcompressionAlgorithm
- the compression algorithm to be usedmode
- either CompressedData.IMPLICIT for including the data, or
CompressedData.EXPLICIT for not including it
java.security.NoSuchAlgorithmException
- if the requested compression algorithm is not supported
java.io.IOException
- if an I/O error occurspublic CompressedData(ObjectID contentType, byte[] content, AlgorithmID compressionAlgorithm, int mode, SecurityProvider securityProvider) throws java.security.NoSuchAlgorithmException, java.io.IOException
CompressedData
object for compressing the given content
with the given compression algorithm.
The mode
parameter specifies whether to include the compressed data
(mode = CompressedData.IMPLICIT) or not include it (mode = CompressedData.EXPLICIT).
This constrcutor already performs the content compression.
contentType
- the content type of the data to be compressedcontent
- the content data to be compressedcompressionAlgorithm
- the compression algorithm to be usedmode
- either CompressedData.IMPLICIT for including the data, or
CompressedData.EXPLICIT for not including itsecurityProvider
- the SecurityProvider to be used for data compression
java.security.NoSuchAlgorithmException
- if the requested compression algorithm is not supported
java.io.IOException
- if an I/O error occurspublic CompressedData(java.io.InputStream is) throws java.io.IOException, CMSParsingException
The given input stream supplies the DER encoding of an already existing CMS CompressedData object.
is
- the InputStream holding the DER encoded CMS CompressedData object
java.io.IOException
- if an error occurs when reading from the stream
CMSParsingException
- if the object can not be parsedMethod Detail |
---|
public void decode(ASN1Object obj) throws CMSParsingException
decode
in interface Content
obj
- the ASN1Object the ASN.1 CompressedData object
CMSParsingException
- if an error occurs when parsing the given ASN1Objectpublic java.io.InputStream getInputStream() throws java.security.NoSuchAlgorithmException, java.io.IOException
When having created a new CompressedData object this method returns the
compressed content.
When parsing an existing CompressedData from its ASN.1 or DER representation,
this method returns the decompressed content.
getInputStream
in class CompressedDataStream
java.security.NoSuchAlgorithmException
- if the requested compression algorithm is not supported
java.io.IOException
- if an I/O error occurspublic byte[] getContent() throws java.security.NoSuchAlgorithmException, java.io.IOException
When having created a new CompressedData object this method returns the
compressed content.
When parsing an existing CompressedData from its ASN.1 or DER representation,
this method returns the decompressed content.
java.security.NoSuchAlgorithmException
- if the requested compression algorithm is not supported
java.io.IOException
- if an I/O error occurspublic void setContent(byte[] content) throws java.security.NoSuchAlgorithmException, java.io.IOException
When having created a new CompressedData object and setting the content
now this method will the compress the content.
When parsing an existing CompressedData from its ASN.1 or DER representation
and setting the compressed content now, this method will decompress the compressed
content.
content
- the raw/compressed content
java.security.NoSuchAlgorithmException
- if the requested compression algorithm is not supported
java.io.IOException
- if an I/O error occurspublic void setInputStream(java.io.InputStream is) throws java.security.NoSuchAlgorithmException, java.io.IOException
When having created a new CompressedData object and setting the content
now this method will the compress the content.
When parsing an existing CompressedData from its ASN.1 or DER representation
and setting the compressed content now, this method will decompress the compressed
content.
setInputStream
in class CompressedDataStream
is
- the raw/compressed content supplied from an input stream
java.security.NoSuchAlgorithmException
- if the requested compression algorithm is not supported
java.io.IOException
- if an I/O error occursprotected ASN1Object toASN1Object(int blockSize) throws CMSException
toASN1Object
in class CompressedDataStream
blockSize
- the block size defining the encoding scheme - and specifying the
length of each primitive encoded octet string component, if positive
CMSException
- if the ASN1Object cannot be createdpublic byte[] getEncoded() throws CMSException
CMSException
- if an error occurs during the encoding procedure
|
This Javadoc may contain text parts from text parts from IETF Internet Standard specifications (see copyright note). | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |