|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object iaik.cms.EncapsulatedContentInfoStream
public class EncapsulatedContentInfoStream
This class represents the 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 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 0x00instead of:
0x04 0x05 0x01 0xAB 0x23 0x7F 0xCAfor 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 |
---|
protected ObjectID contentType_
protected java.io.InputStream contentData_
protected int blockSize_
Constructor Detail |
---|
protected EncapsulatedContentInfoStream()
public EncapsulatedContentInfoStream(java.io.InputStream content, ObjectID contentType)
EncapsulatedContentInfoStream
from given content
and content type.
content
- the content byte material supplied from an InputStreamcontentType
- the content typepublic EncapsulatedContentInfoStream(ObjectID contentType)
EncapsulatedContentInfoStream
from the given
content type.
Since no content is specified, it is set to null
. The content
may be transmitted by other means.
contentType
- the type of the content, as ObjectIDpublic EncapsulatedContentInfoStream(java.io.InputStream is) throws java.io.IOException, CMSParsingException
EncapsulatedContentInfo
object which may have been written
to a stream by using the writeTo
method
of this class.
is
- the InputStream holding a BER encoded CMS EncapsulatedContentInfo object
java.io.IOException
- if an I/O error occurs during reading from the InputStream
CMSParsingException
- if an error occurs while parsing the objectMethod Detail |
---|
protected void decode(DerInputStream is) throws java.io.IOException, CMSParsingException
is
- the InputStream holding a DER encoded CMS EncapsulatedContentInfo object
java.io.IOException
- if an I/O error occurs during reading from the InputStream
CMSParsingException
- if an error occurs while parsing the objectpublic ASN1Object toASN1Object() throws CMSException
CMSException
- if an ASN.1 parsing error occurspublic void writeTo(java.io.OutputStream os) throws java.io.IOException, CMSException
ContentInfo
structure is encoded as ASN.1 SEQUENCE
using the indefinite length encoding scheme:
30 80 ... ... 00 00If 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.
os
- the OutputStream where the encoding shall be written to
java.io.IOException
- if an I/O error occurs during writing to the OutputStream
CMSException
- if an error occurs while encoding the objectpublic void setBlockSize(int blockSize)
blockSize
is smaller or equal to zero the
whole data is encoded as definite primitive octet string.
blockSize
- for defining the encoding scheme and setting the octet
string component length, if positiveOCTET_STRING
public boolean hasContent()
true
if this EncapsulatedContentInfoStream has a content.
true
if this EncapsulatedContentInfoStream has a contentpublic java.io.InputStream getContentInputStream()
null
if there is no contentpublic ObjectID getContentType()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(boolean detailed)
detailed
- - whether or not to give detailed information
|
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 |