iaik.cms
Class EncapsulatedContentInfoStream

java.lang.Object
  extended by iaik.cms.EncapsulatedContentInfoStream
Direct Known Subclasses:
EncapsulatedContentInfo

public class EncapsulatedContentInfoStream
extends java.lang.Object

This class represents the stream implemention of the CMS EncapsulatedContentInfo type.

The Cryptographic Message Syntax (CMS) ( RFC 5652) specifies the EncapsualtedContentInfo type for carrying the inherent content of an CMS object:

 EncapsulatedContentInfo ::= SEQUENCE {
      eContentType ContentType,
      eContent [0] EXPLICIT OCTET STRING OPTIONAL }

 ContentType ::= OBJECT IDENTIFIER

 

The eContentType field associates a content type with some particular content, encoded as OCTET STRING. The content field may be omitted to transmit the content by other means.

The non-stream supporting equivalent to this class is implemented by the EncapsualtedContentInfo class.

This class does NOT interpret the content to be transmitted, i.e. the content is only treated as byte material. When creating a new EncapsulatedContentInfo to be sent use the EncapsulatedContentInfoStream(InputStream content, ObjectID contentType) constructor for supplying content bytes and content type and subsequently call the toASN1Object or writeTo method, e.g.:

 // the content bytes to be read from a stream:
 InputStream content = ...;
 // the content type (e.g. cms data):
 ObjectID contentType = ObjectID.cms_data;
 // create a EncapsulatedContentInfoStream object and encode it to a stream:
 EncapsulatedContentInfoStream ecis = new EncapsulatedContentInfoStream(content, contentType);
 // use block encoding
 int blockSize = ...;
 ecis.setBlockSize(blockSize);
 // encode to an output stream
 OutputStream encoded_stream = ...;
 ecis.writeTo(encoded_stream);
 
When using method setBlockSize(int) setBlockSize for specifying a particular blockSize an indefinite constructed encoding is enforced for the inherent content instead of the default definite primitive encoding, e.g:
 0x24 0x80
           0x04 0x02 0x01 0xAB
           0x04 0x02 0x23 0x7F
           0x04 0x01 0xCA
 0x00 0x00 
 
instead of:
 0x04 0x05 0x01 0xAB 0x23 0x7F 0xCA
 
for encoding the five data bytes 0x01 0xAB 0x23 0x7F 0xCA.

If you want to use an EncapsulatedContentInfo without any content, you only have to supply the content type identifier when creating an EncapsulatedContentInfoStream object, e.g.:

 EncapsulatedContentInfoStream ecis = new EncapsulatedContentInfoStream(ObjectID.cms_data);
 ecis.writeTo(encoded_stream);
 
For parsing an already existing EncapsulatedContentInfo (given as BER encoding) use the EncapsulatedContentInfo(InputStream is) constructor.

However, GENERALLY there should be no need for an application to immediately access this class at all. This library implements the CMS types in a way that handles the EncapsulatedContentInfo type transparent inside the corresponding classes (e.g. SignedDataStream, ...).


Field Summary
protected  int blockSize_
          The block size for block encoding.
protected  java.io.InputStream contentData_
          The content data supplied from an input stream.
protected  ObjectID contentType_
          The content type.
 
Constructor Summary
protected EncapsulatedContentInfoStream()
          Default constructor.
  EncapsulatedContentInfoStream(java.io.InputStream is)
          Creates a new EncapsulatedContentInfo where the BER encoded data is read from the given InputStream.
  EncapsulatedContentInfoStream(java.io.InputStream content, ObjectID contentType)
          Creates a CMS EncapsulatedContentInfoStream from given content and content type.
  EncapsulatedContentInfoStream(ObjectID contentType)
          Creates an empty CMS EncapsulatedContentInfoStream from the given content type.
 
Method Summary
protected  void decode(DerInputStream is)
          Reads and decodes an encoded EncapsulatedContentInfo from an input stream.
 java.io.InputStream getContentInputStream()
          Returns an InputStream supplying the content bytes of this CMS EncapsulatedContentInfo.
 ObjectID getContentType()
          Returns the content type of this CMS EncapsulatedContentInfoStream.
 boolean hasContent()
          Returns true if this EncapsulatedContentInfoStream has a content.
 void setBlockSize(int blockSize)
          Sets the block size for defining the length of each definite primitive encoded octet string component.
 ASN1Object toASN1Object()
          Returns this CMS EncapsulatedContentInfoStream as ASN1Object.
 java.lang.String toString()
          Returns a string giving some information about this CMS EncapsulatedContentInfoStream.
 java.lang.String toString(boolean detailed)
          Returns a string giving some - if requested - detailed information about this CMS EncapsulatedContentInfoStream.
 void writeTo(java.io.OutputStream os)
          Writes the DER encoding of this object to the given OutputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

contentType_

protected ObjectID contentType_
The content type.


contentData_

protected java.io.InputStream contentData_
The content data supplied from an input stream.


blockSize_

protected int blockSize_
The block size for block encoding. (Default: 2048 to enforce indefinite constructed encoding).

Constructor Detail

EncapsulatedContentInfoStream

protected EncapsulatedContentInfoStream()
Default constructor. Creates an empty object. The block size is set to 2048 to enforce indefinite constructed encoding.


EncapsulatedContentInfoStream

public EncapsulatedContentInfoStream(java.io.InputStream content,
                                     ObjectID contentType)
Creates a CMS EncapsulatedContentInfoStream from given content and content type.

Parameters:
content - the content byte material supplied from an InputStream
contentType - the content type

EncapsulatedContentInfoStream

public EncapsulatedContentInfoStream(ObjectID contentType)
Creates an empty CMS EncapsulatedContentInfoStream from the given content type.

Since no content is specified, it is set to null. The content may be transmitted by other means.

Parameters:
contentType - the type of the content, as ObjectID

EncapsulatedContentInfoStream

public EncapsulatedContentInfoStream(java.io.InputStream is)
                              throws java.io.IOException,
                                     CMSParsingException
Creates a new EncapsulatedContentInfo where the BER encoded data is read from the given InputStream. The given input stream supplies the BER encoding of an alredy existing EncapsulatedContentInfo object which may have been written to a stream by using the writeTo method of this class.

Parameters:
is - the InputStream holding a BER encoded CMS EncapsulatedContentInfo object
Throws:
java.io.IOException - if an I/O error occurs during reading from the InputStream
CMSParsingException - if an error occurs while parsing the object
Method Detail

decode

protected void decode(DerInputStream is)
               throws java.io.IOException,
                      CMSParsingException
Reads and decodes an encoded EncapsulatedContentInfo from an input stream.

Parameters:
is - the InputStream holding a DER encoded CMS EncapsulatedContentInfo object
Throws:
java.io.IOException - if an I/O error occurs during reading from the InputStream
CMSParsingException - if an error occurs while parsing the object

toASN1Object

public ASN1Object toASN1Object()
                        throws CMSException
Returns this CMS EncapsulatedContentInfoStream as ASN1Object.

Returns:
this CMS EncapsulatedContentInfoStream as ASN1Object
Throws:
CMSException - if an ASN.1 parsing error occurs

writeTo

public void writeTo(java.io.OutputStream os)
             throws java.io.IOException,
                    CMSException
Writes the DER encoding of this object to the given OutputStream. The ContentInfo structure is encoded as ASN.1 SEQUENCE using the indefinite length encoding scheme:
 30 80
    ...
    ...
 00 00
 
If a particular block size has been specified by method setBlockSize and the content field is not empty, the content is ancoded using the indefinite constructed BER encoding scheme.

Parameters:
os - the OutputStream where the encoding shall be written to
Throws:
java.io.IOException - if an I/O error occurs during writing to the OutputStream
CMSException - if an error occurs while encoding the object

setBlockSize

public void setBlockSize(int blockSize)
Sets the block size for defining the length of each definite primitive encoded octet string component. If the value of blockSize is smaller or equal to zero the whole data is encoded as definite primitive octet string.

Parameters:
blockSize - for defining the encoding scheme and setting the octet string component length, if positive
See Also:
OCTET_STRING

hasContent

public boolean hasContent()
Returns true if this EncapsulatedContentInfoStream has a content.

Returns:
true if this EncapsulatedContentInfoStream has a content

getContentInputStream

public java.io.InputStream getContentInputStream()
Returns an InputStream supplying the content bytes of this CMS EncapsulatedContentInfo.

Returns:
the content value to be read from an InputStream or null if there is no content

getContentType

public ObjectID getContentType()
Returns the content type of this CMS EncapsulatedContentInfoStream.

Returns:
the content type, as ObjectID

toString

public java.lang.String toString()
Returns a string giving some information about this CMS EncapsulatedContentInfoStream.

Overrides:
toString in class java.lang.Object
Returns:
the string representation

toString

public java.lang.String toString(boolean detailed)
Returns a string giving some - if requested - detailed information about this CMS EncapsulatedContentInfoStream.

Parameters:
detailed - - whether or not to give detailed information
Returns:
the string representation

This Javadoc may contain text parts from text parts from IETF Internet Standard specifications (see copyright note).

IAIK-CMS 5.1, (c) 2002 IAIK, (c) 2003 - 2010 SIC