|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object iaik.cms.DataStream iaik.cms.Data
public class Data
This class represents the non-stream implementation of the CMS content type
Data
.
Each CMS 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.113549.1.7.1".
The Cryptographic Message Syntax (CMS) (RFC 5652)
specifies the Data
content type as base type without any cryptographic enhancements.
Please note that in difference to PKCS#7, CMS specifies the Data
as arbitrary octet strings,
such as ASCII text files; the interpretation is left to the application. From this
point of view the CMS type Data
itself does not have an ASN.1
respresentation in contrast to its PKCS#7 equivalent where Data
is defined as ASN.1 OCTET STRING:
Data ::= OCTET STRING
This class only may be used for compatibility to PKCS#7 for allowing to
include Data objects into ContentInfos
. Within
SignedData
or EnvelopedData
objects the internal content always is wrapped by an
EncapsulatedContentInfo
object.
Since an EncapsulatedContentInfo anytime is encoded as OCTET STRING
backwards compatibility to PKCS#7 is preserved even when the inner
content type is Data
Use the Data(byte[] content)
constructor to create a new Data
object for the given raw data
bytes:
byte[] value = ...; Data data = new Data(value);Some applications use the indefinite constructed encoding method for generating an octet string that is composed of a certain number of definite primitive encoded octet strings:
0x24 0x80 0x04 <blocksize> <data> 0x04 <blocksize> <data> 0x04 <blocksize> <data> ... 0x00 0x00For being compatible to such applications, this class provides a constructor where a particular blocksize may be specified to give an encoding result as described above:
Data data = new Data(value, blockSize);
In contrast to the stream-variant of the CMS Data type (implemented by the
DataStream
), where the raw data is
supplied from an input stream and therefore can be read only once, it may be
obtained arbitrarily often from a non-stream Data
object by
utilizing the getData
method.
After transforming a Data
object to an ASN1Object by means of the
toASN1Object
method, it may be parsed back again by
using the Data(ASN1Object obj)
constructor.
In general, the getEncoded
method returns this
Data
object as definite primitive encoded octet string:
0x04 <length> <data>However, if a positive blocksize has been specified when creating this
Data
object, the encoding will be indefinite constructed.
For handling large amounts of data, the parent DataStream
class should be used.
Content
,
ContentInfo
Field Summary |
---|
Fields inherited from class iaik.cms.DataStream |
---|
blockSize_, inputStream_ |
Constructor Summary | |
---|---|
protected |
Data()
Default constructor for dynamic object creation in ContentInfo. |
|
Data(ASN1Object obj)
Creates a CMS Data object from an ASN1Object. |
|
Data(byte[] content)
Creates a CMS Data object from a byte array supplying
the data value. |
|
Data(byte[] content,
int blockSize)
Creates a CMS Data object from a byte array supplying
the data value and a blockSize specifying the encoding scheme. |
|
Data(java.io.InputStream is)
Creates a new CMS Data from a DER encoded Data object read from the given input stream. |
Method Summary | |
---|---|
void |
decode(ASN1Object obj)
Reads and decodes the Data from an ASN1Object. |
void |
decode(java.io.InputStream is)
Reads and decodes the DER encoded Data from the given input stream. |
byte[] |
getData()
Returns a byte array holding the value of this Data object. |
byte[] |
getEncoded()
Returns the DER encoding of this Data object as byte array. |
java.io.InputStream |
getInputStream()
Returns an InputStream from which the contents of this object can be read. |
ASN1Object |
toASN1Object()
Returns this CMS Data as ASN1Object. |
java.lang.String |
toString(boolean detailed)
Returns a string giving some - if requested - detailed information about this Data object. |
Methods inherited from class iaik.cms.DataStream |
---|
getBlockSize, getContentType, setBlockSize, toString, 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 |
---|
getBlockSize, getContentType, setBlockSize |
Constructor Detail |
---|
protected Data()
public Data(byte[] content)
Data
object from a byte array supplying
the data value.
Use this constructor for supplying the content value, e.g.:
Data data = new Data("Test data".getBytes());
content
- the data value in a byte arraypublic Data(byte[] content, int blockSize)
Data
object from a byte array supplying
the data value and a blockSize specifying the encoding scheme.
If blockSize
is not positive this Data object will be
encoded as definite primitive octet string:
0x04 <length> <data>If
blockSize
is positive this Data object will be encoded
as indefinite constructed octet string being composed of a certain number
of definite primitive octet strings of blockSize
length:
0x24 0x80 0x04 <blocksize> <data> 0x04 <blocksize> <data> 0x04 <blocksize> <data> ... 0x00 0x00
content
- the data value in a byte arrayblockSize
- for defining the encoding scheme - and specifiying the octet
string component length, if positivepublic Data(ASN1Object obj) throws CMSParsingException
Data
object, supplied as ASN1Object that may have been
created by calling toASN1Object
.
Use the Data(byte[] content)
constructor for supplying the content value when creating a
Data
object.
obj
- the CMS Data
as ASN1Object
CMSParsingException
- if an parsing error occurspublic Data(java.io.InputStream is) throws java.io.IOException, CMSParsingException
Data
object, supplied as DER encoding from an input stream.
is
- the input stream supplying the DER encoded Data
java.io.IOException
- if an I/O error occurs during reading from the InputStream
CMSParsingException
- if an error occurs while parsing the objectMethod Detail |
---|
public void decode(java.io.InputStream is) throws java.io.IOException, CMSParsingException
decode
in interface ContentStream
decode
in class DataStream
is
- the InputStream holding a DER encoded CMS Data object
java.io.IOException
- if an I/O error occurs during reading from the InputStream
CMSParsingException
- if an error occurs while parsing the objectpublic void decode(ASN1Object obj) throws CMSParsingException
decode
in interface Content
obj
- the CMS Data object as ASN1Object
CMSParsingException
- if an error occurs while parsing the objectpublic byte[] getData()
Data
object.
Data
object, as byte arraypublic java.io.InputStream getInputStream()
This method only overrides the corresponding getInputStream
method
of the parent DataStream
class for returning the content of this Data
object. There should be
no real necessity for using this method since the raw data bytes immediately
can be obtained by the getData
method.
However, in contrast to the equivalent getInputStream
method of the
parent DataStream
class, this method may be called arbitrarly often;
it only returns a ByteArrayInputStream that is initialized with the raw content bytes.
getInputStream
in class DataStream
Data
objectpublic ASN1Object toASN1Object() throws CMSException
Data
as ASN1Object.
From the internal value an ASN.1 OCTET STRING object is created.
toASN1Object
in interface ContentStream
toASN1Object
in class DataStream
Data
as ASN1Object (OCTET_STRING)
CMSException
- if an ASN.1 parsing error occurspublic byte[] getEncoded() throws CMSException
Data
object as byte array.
In general, the data is returned as primitive definte encoded octet string:
0x04 <length> <data>However, if a positive blocksize has been specified when creating this
Data
object, the encoding will be indefinite constructed:
0x24 0x80 0x04 <blocksize> <data> 0x04 <blocksize> <data> 0x04 <blocksize> <data> ... 0x00 0x00
CMSException
- if an encoding error occurspublic java.lang.String toString(boolean detailed)
Data
object.
toString
in interface ContentStream
toString
in class DataStream
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 |