|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
|
+--iaik.asn1.ASN1Object
|
+--iaik.asn1.ConstructedType
This class is the super class for all structured ASN.1 types.
Within the ASN.1 architecture of the IAIK-JCE library, this ConstructedType
class rather models ASN.1 types which have to be encoded constructed, and not only
native structured ASN.1 types. The ASN.1 type OCTET_STRING,
for instance, in its nature represents a simple ASN.1 type and therefore has to be DER
encoded by using the primitive definite method where the number of data octets
explicitly has to be specified just behind the identifier octet. However sometimes it
may be preferable to use the indefinite constructed method for BER encoding an
octet string, in particular when dealing with large amounts of raw data. For that reason,
also the OCTET_STRING class inherits from this ConstructedType class.
Indefinite length encoding is indicated by the length octet 0x80, and the data octets
are concluded by two consecutive octets of all zero (0x00 0x00).
As an example, the raw data bytes 0x12 0xAB 0x34 may be encoded definite primitive,
e.g.:
0x04 0x03 0x12 0xAB 0x34or they may be encoded indefinite constructed, e.g.:
0x24 0x80
0x04 0x02 0x12 0xAB
0x04 0x01 0x34
0x00 0x00
An application never directly will instantiate this ConstructedType class,
rather it will instantiate a proper subclass, e.g. SEQUENCE
or SET. Components may be added by means of a proper
addComponent method, e.g.:
byte[] value = {(byte)0x12, (byte)0xAB, (byte)0x34 };
OCTET_STRING oct = new OCTET_STRING(value);
INTEGER i = new INTEGER(3);
SEQUENCE seq = new SEQUENCE();
seq.addComponent(oct);
seq.addComponent(i);
A component may be removed by using one of the removeComponent methods, or they may be replaced by calling the
setComponent method.
For building SEQUENCE OF respectively SET OF structures of
ASN1Type implementing class instances, use the
createSequenceOf respectively
createSetOf methods of the
ASN class.
SEQUENCE,
SET,
OCTET_STRING,
ASN1Object| Field Summary | |
protected int |
content_count
The number of components in the buffer. |
protected ASN1Object[] |
content_data
The buffer where the components are stored. |
| Fields inherited from class iaik.asn1.ASN1Object |
asnType,
encode_listener,
stream_mode |
| Constructor Summary | |
ConstructedType()
Creates a new ConstructedType object. |
|
| Method Summary | |
void |
addComponent(ASN1Object component)
Adds a new ASN1Object component to the end of this ConstructedType. |
void |
addComponent(ASN1Object component,
int index)
Inserts a new component to a given location within the ConstructedType. |
int |
countComponents()
Returns the number of component objects. |
protected void |
decode(int length,
java.io.InputStream is)
Decodes the next available data from the InputStream. |
protected void |
encode(java.io.OutputStream os)
DER encodes this ASN1Object and writes the result to the supplied OutputStream. |
ASN1Object |
getComponentAt(int index)
Returns the component at the given location within a ConstructedType. |
java.util.Enumeration |
getComponents()
Returns an Enumeration that iterates over the component objects. |
java.lang.Object |
getValue()
Returns the value of this ConstructedType as an array of ASN1Objects. |
void |
removeComponent(ASN1Object component)
Removes a component from a ConstructedType. |
void |
removeComponent(int index)
Removes a component at the given location within a ConstructedType. |
void |
setComponent(int index,
ASN1Object value)
Sets the component at the given location within a ConstructedType. |
void |
setValue(java.lang.Object object)
Sets the value of this ConstructedType. |
| Methods inherited from class iaik.asn1.ASN1Object |
addEncodeListener,
encodeObject,
getAsnType,
indefiniteLength,
isA,
isConstructed,
setIndefiniteLength,
setIndefiniteRecursive,
toString |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
| Field Detail |
protected ASN1Object[] content_data
protected int content_count
| Constructor Detail |
public ConstructedType()
addComponent methods.
An application will not directly use this constructor for creating
a constructed ASN1Object, rather it will instantiate a proper subclass,
e.g. SEQUENCE or SET.| Method Detail |
public java.lang.Object getValue()
OCTET_STRING may change the exact meaning
of this method according to specific requirements.public void setValue(java.lang.Object object)
OCTET_STRING may change the exact meaning
of this method according to specific requirements.object - the value to be set as an array of ASN1Objectspublic void addComponent(ASN1Object component)
component - the ASN1Object component to be added; not usedConstructedType
public void addComponent(ASN1Object component,
int index)
component - the ASN1Object component to be insertedindex - the index where to insert the new componentpublic void removeComponent(ASN1Object component)
component - the ASN1Object component to be removedpublic void removeComponent(int index)
index - the index of the component to be removedpublic ASN1Object getComponentAt(int index)
index - the desired position
public void setComponent(int index,
ASN1Object value)
index - the location of the ConstructedType to which the
given ASN1Object shall be writtenvalue - the ASN1Object component to be setpublic int countComponents()
public java.util.Enumeration getComponents()
protected void encode(java.io.OutputStream os)
throws java.io.IOException
os - the output stream to which to write the data
protected void decode(int length,
java.io.InputStream is)
throws CodingException,
java.io.IOException
length bytes represent the encoding of this
ASN1Object to be decoded. If length < 0,
the supplied ASN1Object has been encoded by means of the
indefinite length encoding method, and so the encoding has to be parsed
for two consecutive EOC octets of all zeros. Indefinite length
encoding only is appropriate (and therefore allowed) for constructed
ASN.1 types.
This is a protected method and will not be used by
an application for DER decoding an encoded ASN1Object. An application
will call one of the decode methods of the
DerCoder class for performing
the decoding. The DerCoder then determines the number of
bytes (length) obtained by the particular
ASN1Object and internally calls the decode
method of that ASN1Object.
length - the length of the ASN1Object which shall be decoded, i.e. the
number of the bytes representing the ASN1Object to be decodedis - the input stream from which the data is read in
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||