public class INTEGER extends ASN1Object
When creating a new ASN.1 INTEGER object, an application may supply
the integer value either as Java int value or as Java
BigInteger object,e.g.:
int value = ...; INTEGER asn1Integer = new INTEGER(value); //or BigInteger value = ...; INTEGER asn1Integer = new INTEGER(value);When calling the
getValue method for getting the inherent value
from an ASN.1 INTEGER instance, a Java object of type BigInteger is returned:
BigInteger Value = (BigInteger)asn1Integer.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.ASN1Object,
ASNasnType, constructed, encode_listener, indefinite_length, isStringType, stream_mode| Modifier | Constructor and Description |
|---|---|
protected |
INTEGER()
Creates an empty INTEGER.
|
|
INTEGER(java.math.BigInteger value)
Creates a new ASN.1 INTEGER object for the given Java BigInteger value.
|
|
INTEGER(int value)
Creates a new ASN.1 INTEGER object for the given Java int value.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
decode(int length,
java.io.InputStream is)
Decodes an INTEGER value from the given InputStream.
|
protected void |
encode(java.io.OutputStream os)
DER encodes this INTEGER ASN1Object and writes the result to the given OutputStream.
|
java.lang.Object |
getValue()
Returns the value of this INTEGER as a BigInteger object.
|
void |
setValue(java.lang.Object value)
Sets the value of this INTEGER.
|
java.lang.String |
toString()
Returns a string that represents the contents of this INTEGER ASN1Object.
|
addComponent, addEncodeListener, countComponents, encodeObject, getAsnType, getComponentAt, indefiniteLength, isA, isConstructed, isStringType, setAutomaticRepair, setAutomaticRepairRecursive, setIndefiniteLength, setIndefiniteRecursiveprotected INTEGER()
public INTEGER(java.math.BigInteger value)
value - the BigInteger value this INTEGER object should representpublic INTEGER(int value)
value - the int value this INTEGER object should representpublic java.lang.Object getValue()
getValue in class ASN1Objectpublic void setValue(java.lang.Object value)
BigInteger.setValue in class ASN1Objectvalue - the Java BigInteger value to be set for this INTEGER objectprotected void encode(java.io.OutputStream os)
throws java.io.IOException
encode methods of the
DerCoder class for performing
the encoding, and the DerCoder internally will call this
encode method.
This class has the ability to automatically repair improperly DER encoded ASN.1 INTEGER objects. ITU-T X.690 states the following regarding the encoding of INTEGER structure:
8.3.2 If the contents octets of an integer value encoding consist of more than one octet, then the bits of the first octet and bit 8 of the second octet: a) shall not all be ones; and b) shall not all be zero. NOTE – These rules ensure that an integer value is always encoded in the smallest possible number of octets.
For this ASN.1 object, automatic repair addresses 8.3.2. By default, if a DER encoded INTEGER that does not meet 8.3.2 is decoded using this class, it will automatically repair the problem during any subsequent DER encodings by removing the unnecessary leading zero and one bits. This behaviour is desirable except when encoding/decoding signed structures. In this case, repairing the DER encoding problem would render the signature invalid (the DER byte representation would actually change). All ASN1Object implementations provide the ability to disable the automatic repair feature.
encode in class ASN1Objectos - the output stream to which to write the datajava.io.IOException - if an I/O error occurs while writing to the streamprotected void decode(int length,
java.io.InputStream is)
throws java.io.IOException
length bytes to be read represent the value of an
ASN.1 object of type INTEGER.
This is a protected method and will not be used by
an application for decoding a DER encoded INTEGER. 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 INTEGER
object and internally calls this decode
method for actually reading the value.
decode in class ASN1Objectlength - the already decoded length, i.e. number of the bytes representing the
value of the INTEGER to be decodedis - the input stream from which the DER decoded data is read injava.io.IOException - if there is a problem with the InputStreampublic java.lang.String toString()
toString in class ASN1Object