|
|||||||||
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 0x00An 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, constructed, encode_listener, indefinite_length, isStringType, 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. |
void |
addEncodeListener(EncodeListener encodeListener,
int id,
int afterComponent)
Adds a component encode listener which wants to be notified when the encoding of this constructed ASN1Object has to be performed. |
Object |
clone()
Returns a clone of this ConstructedType. |
int |
countComponents()
Returns the number of component objects. |
protected void |
decode(int length,
InputStream is)
Decodes the next available data from the InputStream. |
protected void |
encode(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. |
Enumeration |
getComponents()
Returns an Enumeration that iterates over the component objects. |
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(Object object)
Sets the value of this ConstructedType. |
Methods inherited from class iaik.asn1.ASN1Object |
addEncodeListener, encodeObject, getAsnType, indefiniteLength, isA, isConstructed, isStringType, setIndefiniteLength, toString |
Methods inherited from class java.lang.Object |
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 Object clone()
clone
in class ASN1Object
public Object getValue()
OCTET_STRING
may change the exact meaning
of this method according to specific requirements.getValue
in class ASN1Object
public void setValue(Object object)
OCTET_STRING
may change the exact meaning
of this method according to specific requirements.setValue
in class ASN1Object
object
- the value to be set as an array of ASN1Objectspublic void addComponent(ASN1Object component)
addComponent
in class ASN1Object
iaik.asn1.ASN1Object
component
- the ASN1Object component to be added; not usedCodingException
- since not supported for this classConstructedType
public void addComponent(ASN1Object component, int index)
component
- the ASN1Object component to be insertedindex
- the index where to insert the new componentArrayIndexOutOfBoundsException
- if the index is invalidpublic void removeComponent(ASN1Object component)
component
- the ASN1Object component to be removedpublic void removeComponent(int index)
index
- the index of the component to be removedArrayIndexOutOfBoundsException
- if the index is invalidpublic ASN1Object getComponentAt(int index)
getComponentAt
in class ASN1Object
index
- the desired positionArrayIndexOutOfBoundsException
- if the index is invalidpublic 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 setArrayIndexOutOfBoundsException
- if the index is invalidpublic int countComponents()
countComponents
in class ASN1Object
public Enumeration getComponents()
protected void encode(OutputStream os) throws IOException
encode
in class ASN1Object
os
- the output stream to which to write the dataIOException
- if an error occurs while reading from the streamprotected void decode(int length, InputStream is) throws CodingException, 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.
decode
in class 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 inIOException
- if an error occurs while reading from the streamCodingException
- if a decoding error occurspublic void addEncodeListener(EncodeListener encodeListener, int id, int afterComponent)
EncodeListener
interface. The actual registration for encoding notification is done when
calling an addEncodeListener
method on a particular ASN1Object.
Later, when the encoding of the current ASN1Object is performed, the program
execution jumps to the encodeCalled
method of each registrated EncodeListener implementation for querying
for information that is needed for the encoding procedure. After having executed the
encodeCalled
methods of all registered listeners, the particular
encode
method of the ASN1Object is executed. In contrast to the
addEncodeListener
method of parent class ASN1Object
, for an constructed
now you can specify the component after which the encoding process shall "pause" to
get the values for the remaining components. Imagine, for instance, a SEQUENCE
being composed of five components for which you do not know the values of
the last 3 components actually before the first componentes have been encoded.
In this case you may register an EncodeListener to execute its encodeCalled
method after 2 components have been encoded, e.g.:
SEQUENCE seq = ...; seq.addEncodeListener(myEncodeListener, 1, 2);Attention! Adding an component encode listener only makes sense if this constructed ASN1Object is to be encoded using stream mode.
encodeListener
- the EncodeListenerid
- an id which lets listeners distinguish between objectsafterComponent
- the number of component after which the EncodeListener should
be calledEncodeListener
|
This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note). | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |