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
,
ASN
asnType, 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 |
---|---|
static void |
checkForMinumumLengthEncoding(boolean check)
Decide whether to check if the INTEGER value is encoded
in the minimum number of octets.
|
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.math.BigInteger |
getBigIntegerValue(boolean makePositive)
Returns the value as BigInteger.
|
java.lang.Object |
getValue()
Returns the value of this INTEGER as a BigInteger object.
|
void |
setIndefiniteLength(boolean indefiniteLength)
Does nothing (primitive INTEGER is encoded with definite length in any case).
|
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, clone, countComponents, encodeObject, getAsnType, getComponentAt, indefiniteLength, isA, isConstructed, isStringType
protected 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 static void checkForMinumumLengthEncoding(boolean check)
If the correctness of the encoding shall be checked an exception is thrown when decoding an INTEGER value containing more than only one octets and all bits of the first octet and bit 8 of the second octest are all zero bits or all one bits.
According to the ASN.1 specification (ITU-T X.690) minimum length
encoding is required for INTEGER values, both for BER and DER.
However, for compatibility reasons the minimum length value check
is disabled by default except for when using
with DerCoder#decode(byte[] coding, boolean ensureDER)
ensureDER
set to true
.
check
- whether to check for minumum length encoding (default: false)public java.lang.Object getValue()
getValue
in class ASN1Object
public java.math.BigInteger getBigIntegerValue(boolean makePositive)
makePositive
- whether to make the value positive (public void setValue(java.lang.Object value)
BigInteger
.setValue
in class ASN1Object
value
- the Java BigInteger value to be set for this INTEGER objectpublic void setIndefiniteLength(boolean indefiniteLength)
setIndefiniteLength
in class ASN1Object
indefiniteLength
- ignoredprotected 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.encode
in class ASN1Object
os
- 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 ASN1Object
length
- 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