public class DataStream extends java.lang.Object implements ContentStream
Data.
Each PKCS#7 content type is associated with a specific object identifier, derived from:
pkcs-7 OBJECT IDENTIFIER ::=
{ iso(1) member-body(2) US(840) rsadsi(113549)
pkcs(1) 7 }
The object identifier for the Data content type is defined as:
data OBJECT IDENTIFIER ::= { pkcs-7 1 }
which corresponds to the OID string "1.2.840.1.113549.1.7.1".
PKCS#7
specifies the Data content type as base type without any
cryptographic enhancements:
Data ::= OCTET STRING
Use the DataStream(InputStream is, int
blockSize) constructor to create a new DataStream object for
the given raw data supplying input stream:
InputStream input_stream = ...; int blockSize = ...; DataStream data_stream = new DataStream(InputStream, blockSize);If
blockSize is set to a positive value, the data is BER encoded
as indefinite constructed octet string being composed of a series of definite
primitive encoded octet strings of blockSize length:
0x24 0x80
0x04 <blocksize> <data>
0x04 <blocksize> <data>
0x04 <blocksize> <data>
...
0x00 0x00
However, if blockSize is not positive, whole the data is encoded
as one single primitive definite octet string, which may cause a memory
overflow when dealing with large data volumes (consult the documentation of
the ContentStream class for more
information about the difference between the two encoding schemes).
In contrast to the non-stream variant of the PKCS#7 Data type (implemented by
the Data class), where the raw data is supplied
as byte array and therefore can be accessed arbitrarily often, it is
important to keep in mind that now for the DataStream class, the
raw data carrying input stream only can be read once, which shall not be done
before actually performing the encoding (again, see
ContentStream)!
After writing a DataStream object BER encoded to an output
stream by calling the writeTo method, it may
be read back, decoded and re-parsed again by means of the
DataStream(InputStream is) constructor. In
this case, the getInputStream method may be used
for reading the raw data included in the received DataStream
object.
ContentStream,
ContentInfoStream,
OCTET_STRING| Modifier | Constructor and Description |
|---|---|
protected |
DataStream()
Default constructor for dynamic object creation in ContentInfo.
|
|
DataStream(java.io.InputStream is)
Creates a new PKCS#7 data from a BER encoded InputStream.
|
|
DataStream(java.io.InputStream is,
int blockSize)
Creates a new PKCS#7 Data from an InputStream supplying the raw content
data.
|
| Modifier and Type | Method and Description |
|---|---|
void |
decode(java.io.InputStream is)
Reads and decodes the Data from a DerInputStream.
|
int |
getBlockSize()
Gets the block size defining the length of each definite primitive encoded
octet string component.
|
ObjectID |
getContentType()
Returns the object identifier of this PKCS#7
Data. |
java.io.InputStream |
getInputStream()
Returns an InputStream where the contents of this object can be read.
|
void |
setBlockSize(int blockSize)
Sets the block size for defining the length of each definite primitive
encoded octet string component.
|
ASN1Object |
toASN1Object()
Returns this PKCS#7
Data as ASN1Object. |
java.lang.String |
toString()
Returns a string giving some information about this
DataStream
object. |
java.lang.String |
toString(boolean detailed)
Returns a string giving some - if requested - detailed information about
this
DataStream object. |
void |
writeTo(java.io.OutputStream os)
Writes this PKCS#7
DataStream object BER encoded to the given
output stream. |
protected DataStream()
public DataStream(java.io.InputStream is,
int blockSize)
blockSize is smaller or equal to zero,
the data will be DER encoded as primitive definite OCTET STRING when
writing it to a stream by means of the writeTo method. However, if blockSize is set to a positive
value, the data will be BER encoded as indefinite constructed octet string
being composed of a series of definite primitive encoded octet strings of
blockSize length:
0x24 0x80
0x04 <blocksize> <data>
0x04 <blocksize> <data>
0x04 <blocksize> <data>
...
0x00 0x00
is - the stream containing the contentblockSize - the block size defining the length of each primitive definite
encoded octet string component; or initiating an entire primitive
definite encoding, when being not positiveOCTET_STRINGpublic DataStream(java.io.InputStream is)
throws java.io.IOException,
PKCSParsingException
DataStream object, supplied as BER encoded input stream that
may have been created by calling writeTo.
Use the DataStream(InputStream is, int
blockSize) constructor for supplying the content data when creating a
DataStream object.
java.io.IOException - if an I/O error occurs during reading from the InputStreamPKCSParsingException - if an error occurs while parsing the objectpublic void decode(java.io.InputStream is)
throws java.io.IOException,
PKCSParsingException
DerInputStream, internally a DerInputStream is created before parsing the
data.decode in interface ContentStreamis - the InputStream holding a DER encoded PKCS#7 Data objectjava.io.IOException - if an I/O error occurs during reading from the InputStreamPKCSParsingException - if an error occurs while parsing the objectDerInputStreampublic void setBlockSize(int blockSize)
blockSize is
smaller or equal to zero the whole data is encoded as definite primitive
octet string.setBlockSize in interface ContentStreamblockSize - for defining the encoding scheme and setting the octet string
component length, if positiveOCTET_STRINGpublic int getBlockSize()
blockSize is smaller
or equal to zero the whole data is encoded as definite primitive octet
string. This method may be used for enforcing block encoding when wrapping
the EncryptedData into a ContentInfo.getBlockSize in interface ContentStreamOCTET_STRINGpublic ObjectID getContentType()
Data.getContentType in interface ContentStreamObjectID.pkcs7_dataObjectIDpublic java.io.InputStream getInputStream()
When having created a new DataStream object to be encoded to a
stream, this method should not be utilized at all, since the stream
automatically will be read during performing the encoding (which is done
when calling the writeTo method).
When having decoded and parsed a DataStream object coming from
some stream, this method may be used for reading the raw data.
public ASN1Object toASN1Object() throws PKCSException
Data as ASN1Object.
From the internal value an ASN.1 OCTET STRING object is created. If block
size has a value > 0 a constructed OCTET STRING is created.toASN1Object in interface ContentStreamData as ASN1ObjectPKCSException - if the ASN1Object could not be createdOCTET_STRINGpublic void writeTo(java.io.OutputStream os)
throws PKCSException,
java.io.IOException
DataStream object BER encoded to the given
output stream.
From the internal value an ASN.1 OCTET STRING object is created, BER
encoded and written to the stream. If block size has a value > 0 a
constructed OCTET STRING is created. In this case the encoding is splitted
according to the defined block size:
0x24 0x80
0x04 <blocksize> <data>
0x04 <blocksize> <data>
0x04 <blocksize> <data>
...
0x00 0x00
If the block size is not positive, whole the data is encoded as one single
primitive definite octet string:
0x04 <length> <data>
os - the output stream to which to encode the dataPKCSException - if an encoding error occursjava.io.IOException - if an error occurs during writing to the streamOCTET_STRINGpublic java.lang.String toString()
DataStream
object.toString in class java.lang.Objectpublic java.lang.String toString(boolean detailed)
DataStream object.toString in interface ContentStreamdetailed - - whether or not to give detailed information