iaik.asn1
Class ENUMERATED

java.lang.Object
  |
  +--iaik.asn1.ASN1Object
        |
        +--iaik.asn1.ENUMERATED
All Implemented Interfaces:
Cloneable

public class ENUMERATED
extends ASN1Object

This class implements the native ASN.1 type "ENUMERATED". ENUMERATED is a new ASN.1 type introduced by the CCITT Recommendation X.208. ENUMERATED is a simple non-string ASN.1 type identified by the UNIVERSAL TAG number 10.

An ASN.1 ENUMERATED object represents an integer value out of a predefined quantity of integers. In this way, an application can define its own enumeration types whenever it intends to restrict the number of values a particular component may occupy, e.g.:

 Seasons ::= ENUMERATED {
     spring (0),
     summer (1),
     autumn (2),
     winter (3)
 }
 
In this example, a representant of the Seasons enumerated type only may take one of four valid values: 0 (for spring), 1 (for summer), 2 (for autumn), and 3 (for winter).

When creating a new ENUMERATED object, the integer value it represents has to be specified, e.g.:

 ENUMERATED seasonsValue = new ENUMERATED(2);
 
An application using the ENUMERATED type, itself has to take care for checking if the supplied value exists in the predefined quantity. This class only provides an utility for creating a representant of the particular type and encoding it as ENUMERATED.

When calling the getValue method for getting the inherent value from an ASN.1 ENUMERATED instance, a Java object of type Integer is returned:

 Integer Value = (Integer)enumerated.getValue();
 int value = Value.intValue();
 
DER en/decoding generally is done by means of the several methods of the DerCoder class; decoding alternatively may be performed by using the DerInputStream utility.

Version:
File Revision 16
See Also:
ASN1Object, ASN

Fields inherited from class iaik.asn1.ASN1Object
asnType, constructed, encode_listener, indefinite_length, isStringType, stream_mode
 
Constructor Summary
protected ENUMERATED()
          Create an empty ENUMERATED.
  ENUMERATED(int value)
          Creates an ENUMERATED object for representing the given int value.
 
Method Summary
protected  void decode(int length, InputStream is)
          Decodes an ENUMERATED value from the given InputStream.
protected  void encode(OutputStream os)
          DER encodes this ENUMERATED ASN1Object and writes the result to the given output stream.
 Object getValue()
          Returns the value of this ENUMERATED as an Integer object.
 void setValue(Object object)
          Sets the value of this ENUMERATED.
 String toString()
          Returns a string that represents the contents of this ENUMERATED ASN1Object.
 
Methods inherited from class iaik.asn1.ASN1Object
addComponent, addEncodeListener, clone, countComponents, encodeObject, getAsnType, getComponentAt, indefiniteLength, isA, isConstructed, isStringType, setIndefiniteLength
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ENUMERATED

protected ENUMERATED()
Create an empty ENUMERATED.

ENUMERATED

public ENUMERATED(int value)
Creates an ENUMERATED object for representing the given int value.
Parameters:
value - the int value this ENUMERATED object should represent
Method Detail

getValue

public Object getValue()
Returns the value of this ENUMERATED as an Integer object.
Overrides:
getValue in class ASN1Object
Returns:
the value of this ENUMERATED as an Integer object

setValue

public void setValue(Object object)
Sets the value of this ENUMERATED. The supplied value has to be a Java object of type Integer.
Overrides:
setValue in class ASN1Object
Parameters:
value - the Java Integer value to be set for this ENUMERATED object

encode

protected void encode(OutputStream os)
               throws IOException
DER encodes this ENUMERATED ASN1Object and writes the result to the given output stream. This is a protected method and will not be used by an application for DER encoding an ENUMERATED object. An application will call one of the encode methods of the DerCoder class for performing the encoding, and the DerCoder internally will call this encode method.
Overrides:
encode in class ASN1Object
Parameters:
os - the output stream to which to write the data
Throws:
IOException - if an I/O error occurs while writing to the stream

decode

protected void decode(int length,
                      InputStream is)
               throws IOException,
                      CodingException
Decodes an ENUMERATED value from the given InputStream. The given input stream carries DER encoded data, and the next length bytes to be read represent the value of an ASN.1 object of type ENUMERATED.

This is a protected method and will not be used by an application for decoding a DER encoded ENUMERATED. 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) occupied by the value of this ENUMERATED object and internally calls this decode method for actually reading the value.

Overrides:
decode in class ASN1Object
Parameters:
length - the already decoded length, i.e. number of the bytes representing the value of the ENUMERATED to be decoded
is - the input stream from which the DER encoded data is read in
Throws:
IOException - if there is a problem with the InputStream
CodingException - if a decodeding error occurs

toString

public String toString()
Returns a string that represents the contents of this ENUMERATED ASN1Object.
Overrides:
toString in class ASN1Object
Returns:
the string representation
See Also:
ASN1Object.toString()

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).

IAIK-JCE 3.1 with IAIK-JCE CC Core 3.1, (c) 1997-2004 IAIK