|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--iaik.asn1.ASN1Object
This abstract class defines the external interface for ASN.1 object, both primitive and constructed. The subclasses of this class are assumed to define the application specific methods for setting/accessing the contents of the particular ASN.1 data structure.
For DER en/decoding ASN.1 objects an application shall use the
corresponding en/decode
methods of the DerCoder
class. For decoding large ASN.1 objects
supplied from some stream, the DerInputStream
utility may be used.
ASN.1 objects can be devided into simple types (e.g. BOOLEAN, INTEGER, ...),
and structured types (e.g. SEQUENCE, SET, ...). Simple types always
have to be encoded by using the primitive definite encoding method
where the number of data octets explicitly has to be specified just behind
the identifier octet. In this way, an encoding of, for instance, 0x04 0x03
will introduce an ASN.1 object of type OCTET_STRING (identifier field 0x04)
containing three (length field 0x03) data octets. For stuctured types always
the constructed encoding method is used, but the length field may
by specified either in definite or indefinite form.
Indefinite length encoding has to be used when the actual number
of content octets to be transmitted is not known at the beginning of the
data transfer.
Indefinite length encoding may be enforced by means of the setIndefiniteLength
method.
ASN
Field Summary | |
protected ASN |
asnType
The ASN.1 type of this ASN.1 object. |
protected boolean |
constructed
Is this ASN1Object constructed or primitive?. |
protected iaik.asn1.EncodeListenerEntry[] |
encode_listener
Objects which want to be notified when the encoding of an ASN1Object is performed. |
protected boolean |
indefinite_length
Is the length of this ASN1Object encoded as indefinite or definite length?. |
protected boolean |
isStringType
Is this ASN1Object a String type? |
protected boolean |
stream_mode
In stream mode the components are written in correct order when the encoding is performed. |
Constructor Summary | |
protected |
ASN1Object()
Empty default constructor. |
Method Summary | |
void |
addComponent(ASN1Object component)
Throws a CodingException. |
void |
addEncodeListener(EncodeListener encodeListener,
int id)
Adds one EncodeListener which wants to be notified when the encoding of this ASN1Object has to be performed. |
Object |
clone()
Returns a clone of this ObjectID. |
int |
countComponents()
Throws a CodingException. |
protected abstract void |
decode(int length,
InputStream is)
Decodes an ASN1Object represented by the next length
bytes of the given input stream. |
protected abstract void |
encode(OutputStream os)
DER encodes this ASN1Object and writes the result to the given output stream. |
protected void |
encodeObject(OutputStream os,
boolean streamMode)
DER encodes this ASN1Object and writes the output to the specified OutputStream. |
ASN |
getAsnType()
Returns the ASN.1 type of this ASN.1 object. |
ASN1Object |
getComponentAt(int index)
Throws a CodingException. |
abstract Object |
getValue()
Returns the value of this ASN1Object. |
boolean |
indefiniteLength()
Returns whether this ASN1Object will be encoded by using the definite or indefinite encoding method. |
boolean |
isA(ASN type)
Tests if this object is an instance of given ASN.1 type. |
boolean |
isConstructed()
Returns whether this ASN1Object is constructed or primitive. |
boolean |
isStringType()
Asks if this ASN1Object represents a String type. |
void |
setIndefiniteLength(boolean indefiniteLength)
Switches indefinite length encoding on or off for this ASN1Object. |
abstract void |
setValue(Object object)
Sets the value of this ASN1Object. |
String |
toString()
Returns a string that represents the contents of this ASN1Object. |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected boolean constructed
protected boolean indefinite_length
protected ASN asnType
protected boolean isStringType
protected iaik.asn1.EncodeListenerEntry[] encode_listener
EncodeListeners are instances of classes that implement the EncodeListener
interface. Use the addEncodeListener
method for
registering an EncodeListener to be notified when the encoding of some particular
ASN1Object has to be performed. The program execution then will jump to the
encodeCalled
method of the particular EncodeListener implementation.
protected boolean stream_mode
Constructor Detail |
protected ASN1Object()
Method Detail |
public Object clone()
clone
in class Object
public ASN getAsnType()
ASN
public boolean indefiniteLength()
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). The indefinite length encoding method only can be used along with the encoding of contsructed ASN.1 objects. Primitive together with indefinite length encoding is forbidden since wrong encoding results would be prodruced anytime when two consecutive zero octets are included within the data stream.
true
, if indefinite length encoding is used,
false
otherwisepublic void setIndefiniteLength(boolean indefiniteLength)
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). The indefinite length encoding method only can be used along with the encoding of contsructed ASN.1 objects. Primitive together with indefinite length encoding is forbidden since wrong encoding results would be prodruced anytime when two consecutive zero octets are included within the data stream.
When dealing with large amounts of data, the indefinite length method shall be used for allowing to split the encoding in small chunks that can be handled within the memory.
indefiniteLength
- true
, if this ASN1Object shall be encoded
using the indefinite length encoding method,
false
if it shall be encoded with definite lengthpublic boolean isConstructed()
true
, if constructed, false
otherwisepublic void addEncodeListener(EncodeListener encodeListener, int id)
EncodeListener
interface. The actual registration for encoding notification is done when
calling this 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.encodeListener
- the EncodeListenerid
- an id which lets listeners distinguish between objectsEncodeListener
protected void encodeObject(OutputStream os, boolean streamMode) throws IOException
encode
method of the sub-class is called.os
- the output stream to which to write the datastreamMode
- true
, if the contents of this ASN1Object shall be written
directly to the output stream and the encoding shall not built within memory
in reverse orderIOException
- if there is a problem while writing to the output stream or an
EncodeListener throws an exceptionpublic boolean isA(ASN type)
type
- the ASN.1 type this object should be checked of being an instance oftrue
if this object is an instance of the given ASN.1 type
false
otherwiseASN
public ASN1Object getComponentAt(int index) throws CodingException
ConstructedType
class, use the
getComponentAt
method
of that class for obtaining some specific component of a constructed ASN.1
object.index
- the position of the component to be obtained from the constructed
ASN.1 object; not usedCodingException
- since not supported for this classConstructedType
public int countComponents() throws CodingException
ConstructedType
class, use the
countComponents()
method
of that class for obtaining the number of components included into a constructed ASN.1
object.CodingException
- since not supported for this classConstructedType
public void addComponent(ASN1Object component) throws CodingException
ConstructedType
class, use the
addComponent
method of that class for adding a component to a constructed ASN.1
object.component
- the ASN1Object component to be added; not usedCodingException
- since not supported for this classConstructedType
public abstract Object getValue()
public abstract void setValue(Object object)
object
- the value to be set for this ASN1Objectprotected abstract void encode(OutputStream os) throws IOException
encode
methods of the
DerCoder
class for performing
the encoding. The corresponding encode
method
of the particular ASN1Object will be called internally from the
DerCoder.os
- the output stream to which to write the DER encoded dataIOException
- if an I/O error occurs while writing to the streamprotected abstract void decode(int length, InputStream is) throws CodingException, IOException
length
bytes of the given input stream. Implemented by any subclass.
The supplied input stream carries DER encoded data. The next
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 already decoded length, i.e. number of the bytes representing the
ASN1Object to be decodedis
- the InputStream supplying the encoded ASN1ObjectCodingException
- if the ASN1Object can not be decodedIOException
- if an error occurs while reading from the streampublic boolean isStringType()
true
if this ASN1Object is a String type,
false
if notpublic String toString()
toString
in class Object
|
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 |