iaik.cms
Class EncapsulatedContentInfo

java.lang.Object
  extended by iaik.cms.EncapsulatedContentInfoStream
      extended by iaik.cms.EncapsulatedContentInfo

public class EncapsulatedContentInfo
extends EncapsulatedContentInfoStream

This class represents the non-stream implementation 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 stream-supporting equivalent to this class is implemented by the EncapsulatedContentInfoStream 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 EncapsulatedContentInfo(byte[] content, ObjectID contentType) constructor for supplying content bytes and content type and subsequently call the toASN1Object or writeTo method, e.g.:

 // the content bytes
 byte[] content = ...;
 // the content type (e.g. cms data):
 ObjectID contentType = ObjectID.cms_data;
 ...
 // create a EncapsulatedContentInfo object and encode it to a stream:
 EncapsulatedContentInfo eci = new EncapsulatedContentInfo(content, contentType);
 OutputStream encoded_stream = ...;
 eci.writeTo(encoded_stream);
 
If you want to use an EncapsulatedContentInfo without any content, you only have to supply the content type identifier when creating an EncapsulatedContentInfo object, e.g.:
 EncapsulatedContentInfo eci = new EncapsulatedContentInfo(ObjectID.cms_data);
 eci.writeTo(encoded_stream);
 
For parsing an already existing EncapsulatedContentInfo (given as ASN1Object or DER encoding) use the EncapsulatedContentInfo(ASN1Object obj) or 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. SignedData, ...).


Field Summary
 
Fields inherited from class iaik.cms.EncapsulatedContentInfoStream
blockSize_, contentData_, contentType_
 
Constructor Summary
protected EncapsulatedContentInfo()
          Default constructor.
  EncapsulatedContentInfo(ASN1Object obj)
          Creates a CMS EncapsulatedContentInfo from an ASN1Object.
  EncapsulatedContentInfo(byte[] content, ObjectID contentType)
          Creates a CMS EncapsulatedContentInfo from given content value and content type.
  EncapsulatedContentInfo(java.io.InputStream is)
          Creates a new EncapsulatedContentInfo where the DER encoded data is read from the given InputStream.
  EncapsulatedContentInfo(ObjectID contentType)
          Creates an CMS EncapsulatedContentInfo from the given content type.
 
Method Summary
protected  void decode(DerInputStream is)
          Reads and decodes an encoded EncapsulatedContentInfo from a input stream.
 byte[] getContent()
          Returns the content of this CMS EncapsulatedContentInfo.
 java.io.InputStream getContentInputStream()
          Returns an InputStream supplying the content bytes of this CMS EncapsulatedContentInfo.
 ObjectID getContentType()
          Returns the content type of this CMS EncapsulatedContentInfo.
 boolean hasContent()
          Returns true if this EncapsulatedContentInfo has a content.
 ASN1Object toASN1Object()
          Returns this CMS EncapsulatedContentInfo as ASN1Object.
 byte[] toByteArray()
          Returns this CMS EncapsulatedContentInfo as DER encoded byte array.
 java.lang.String toString()
          Returns a string giving some information about this CMS EncapsulatedContentInfo.
 java.lang.String toString(boolean detailed)
          Returns a string giving some - if requested - detailed information about this CMS EncapsulatedContentInfo.
 void writeTo(java.io.OutputStream os)
          Writes the DER encoding of this object to the given OutputStream.
 
Methods inherited from class iaik.cms.EncapsulatedContentInfoStream
setBlockSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EncapsulatedContentInfo

protected EncapsulatedContentInfo()
Default constructor. Creates an empty object. The block size is set to -1 to enforce definite primitive encoding.


EncapsulatedContentInfo

public EncapsulatedContentInfo(byte[] content,
                               ObjectID contentType)
Creates a CMS EncapsulatedContentInfo from given content value and content type.

Parameters:
content - the content byte material
contentType - the content type

EncapsulatedContentInfo

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

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

Parameters:
contentType - the type of the content

EncapsulatedContentInfo

public EncapsulatedContentInfo(ASN1Object obj)
                        throws CMSParsingException
Creates a CMS EncapsulatedContentInfo from an ASN1Object. The given ASN1Object represents an alredy existing EncapsulatedContentInfo object which may have been created by using the toASN1Object method of this class.

Parameters:
obj - the CMS EncapsulatedContentInfo as an ASN1Object
Throws:
CMSParsingException - if the ASN1Object could not be parsed

EncapsulatedContentInfo

public EncapsulatedContentInfo(java.io.InputStream is)
                        throws java.io.IOException,
                               CMSParsingException
Creates a new EncapsulatedContentInfo where the DER encoded data is read from the given InputStream. The given input stream represents the DER 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 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
Method Detail

decode

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

Overrides:
decode in class EncapsulatedContentInfoStream
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 EncapsulatedContentInfo as ASN1Object. The ASN1Object returned by this method may be used as parameter value when creating a CMS EncapsulatedContentInfo from an ASN1Object by calling the EncapsulatedContentInfo(ASN1Object obj) constructor.

Overrides:
toASN1Object in class EncapsulatedContentInfoStream
Returns:
this CMS EncapsulatedContentInfo as ASN1Object
Throws:
CMSException - if an ASN.1 parsing error occurs

toByteArray

public byte[] toByteArray()
                   throws CMSException
Returns this CMS EncapsulatedContentInfo as DER encoded byte array.

Returns:
this CMS EncapsulatedContentInfo as DER encoded byte array
Throws:
CMSException - if an error occurs while encoding the object

writeTo

public void writeTo(java.io.OutputStream os)
             throws java.io.IOException,
                    CMSException
Writes the DER encoding of this object to the given OutputStream.

Overrides:
writeTo in class EncapsulatedContentInfoStream
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

hasContent

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

Overrides:
hasContent in class EncapsulatedContentInfoStream
Returns:
true if this EncapsulatedContentInfo has a content

getContent

public byte[] getContent()
Returns the content of this CMS EncapsulatedContentInfo.

Returns:
the content value as byte array or null if there is no content

getContentInputStream

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

Overrides:
getContentInputStream in class EncapsulatedContentInfoStream
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 EncapsulatedContentInfo.

Overrides:
getContentType in class EncapsulatedContentInfoStream
Returns:
the content type, as ObjectID

toString

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

Overrides:
toString in class EncapsulatedContentInfoStream
Returns:
the string representation

toString

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

Overrides:
toString in class 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 6.0, (c) 2002 IAIK, (c) 2003, 2023 SIC