Top Description Fields Constructors Methods
org.bouncycastle.asn1

public Class ASN1Integer

extends ASN1Primitive
Class Inheritance
Imports
java.io.IOException, java.math.BigInteger, org.bouncycastle.util.Arrays, .Properties

Class representing the ASN.1 INTEGER type.

Field Summary

Modifier and TypeField and Description
private final byte[]
pack-priv static final int
pack-priv static final int
private final int
pack-priv static final ASN1UniversalType

Constructor Summary

AccessConstructor and Description
public
ASN1Integer(long
the long representing the value desired.
value
)

Construct an INTEGER from the passed in long value.

public
ASN1Integer(BigInteger
the BigInteger representing the value desired.
value
)

Construct an INTEGER from the passed in BigInteger value.

public
ASN1Integer(byte[]
the byte array representing a 2's complement encoding of a BigInteger.
bytes
)

Construct an INTEGER from the passed in byte array.

pack-priv
ASN1Integer(byte[] bytes, boolean clone)

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
asn1Equals(ASN1Primitive o)

Implements abstract org.bouncycastle.asn1.ASN1Primitive.asn1Equals.

Equality (similarity) comparison for two ASN1Primitive objects.

pack-priv static ASN1Integer
createPrimitive(byte[] contents)

pack-priv void
encode(ASN1OutputStream out, boolean withTag)

Implements abstract org.bouncycastle.asn1.ASN1Primitive.encode.

pack-priv boolean
encodeConstructed()

Implements abstract org.bouncycastle.asn1.ASN1Primitive.encodeConstructed.

Return true if this objected is a CONSTRUCTED one, false otherwise.

pack-priv int
public static ASN1Integer

Returns:

an ASN1Integer instance.
getInstance
(Object
an ASN1Integer or an object that can be converted into one.
obj
)

Return an integer from the passed in object.

public static ASN1Integer

Returns:

an ASN1Integer instance.
getInstance
(ASN1TaggedObject
the tagged object holding the object we want
taggedObject
,
boolean
true if the object is meant to be explicitly tagged false otherwise.
explicit
)

Return an Integer from a tagged object.

public BigInteger

Returns:

the BigInteger that results from treating this ASN.1 INTEGER as unsigned.
getPositiveValue
()

in some cases positive values get crammed into a space, that's not quite big enough...

public BigInteger
public int
hashCode()

Implements abstract org.bouncycastle.asn1.ASN1Primitive.hashCode.

Returns a hash code value for this object.

public boolean
hasValue(int x)

public boolean
hasValue(long x)

public boolean
public int
pack-priv static int
intValue(byte[] bytes, int start, int signExt)

public int
pack-priv static boolean

Returns:

true if the (in)put fails this validation.
isMalformed
(byte[]
The raw encoding of the integer.
bytes
)

Apply the correct validation for an INTEGER primitive following the BER rules.

pack-priv static long
longValue(byte[] bytes, int start, int signExt)

public long
pack-priv static int
signBytesToSkip(byte[] bytes)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from org.bouncycastle.asn1.ASN1Primitive:
encodeToencodeToequalsequalsequalsfromByteArraytoASN1PrimitivetoDERObjecttoDLObject

Field Detail

bytesback to summary
private final byte[] bytes
SIGN_EXT_SIGNEDback to summary
pack-priv static final int SIGN_EXT_SIGNED
SIGN_EXT_UNSIGNEDback to summary
pack-priv static final int SIGN_EXT_UNSIGNED
startback to summary
private final int start
TYPEback to summary
pack-priv static final ASN1UniversalType TYPE

Constructor Detail

ASN1Integerback to summary
public ASN1Integer(long value)

Construct an INTEGER from the passed in long value.

Parameters
value:long

the long representing the value desired.

ASN1Integerback to summary
public ASN1Integer(BigInteger value)

Construct an INTEGER from the passed in BigInteger value.

Parameters
value:BigInteger

the BigInteger representing the value desired.

ASN1Integerback to summary
public ASN1Integer(byte[] bytes)

Construct an INTEGER from the passed in byte array.

Note

Strict Validation applied by default.

It has turned out that there are still a few applications that struggle with the ASN.1 BER encoding rules for an INTEGER as described in: https://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf Section 8.3.2.

Users can set the 'org.bouncycastle.asn1.allow_unsafe_integer' to 'true' and a looser validation will be applied. Users must recognise that this is not ideal and may pave the way for an exploit based around a faulty encoding in the future.

Parameters
bytes:byte[]

the byte array representing a 2's complement encoding of a BigInteger.

ASN1Integerback to summary
pack-priv ASN1Integer(byte[] bytes, boolean clone)

Method Detail

asn1Equalsback to summary
pack-priv boolean asn1Equals(ASN1Primitive o)

Implements abstract org.bouncycastle.asn1.ASN1Primitive.asn1Equals.

Doc from org.bouncycastle.asn1.ASN1Primitive.asn1Equals.

Equality (similarity) comparison for two ASN1Primitive objects.

createPrimitiveback to summary
pack-priv static ASN1Integer createPrimitive(byte[] contents)
encodeback to summary
pack-priv void encode(ASN1OutputStream out, boolean withTag) throws IOException

Implements abstract org.bouncycastle.asn1.ASN1Primitive.encode.

encodeConstructedback to summary
pack-priv boolean encodeConstructed()

Implements abstract org.bouncycastle.asn1.ASN1Primitive.encodeConstructed.

Doc from org.bouncycastle.asn1.ASN1Primitive.encodeConstructed.

Return true if this objected is a CONSTRUCTED one, false otherwise.

Returns:boolean

true if CONSTRUCTED bit set on object's tag, false otherwise.

encodedLengthback to summary
pack-priv int encodedLength(boolean withTag)

Implements abstract org.bouncycastle.asn1.ASN1Primitive.encodedLength.

getInstanceback to summary
public static ASN1Integer getInstance(Object obj)

Return an integer from the passed in object.

Parameters
obj:Object

an ASN1Integer or an object that can be converted into one.

Returns:ASN1Integer

an ASN1Integer instance.

Exceptions
IllegalArgumentException:
if the object cannot be converted.
getInstanceback to summary
public static ASN1Integer getInstance(ASN1TaggedObject taggedObject, boolean explicit)

Return an Integer from a tagged object.

Parameters
taggedObject:ASN1TaggedObject

the tagged object holding the object we want

explicit:boolean

true if the object is meant to be explicitly tagged false otherwise.

Returns:ASN1Integer

an ASN1Integer instance.

Exceptions
IllegalArgumentException:
if the tagged object cannot be converted.
getPositiveValueback to summary
public BigInteger getPositiveValue()

in some cases positive values get crammed into a space, that's not quite big enough...

Returns:BigInteger

the BigInteger that results from treating this ASN.1 INTEGER as unsigned.

getValueback to summary
public BigInteger getValue()
hashCodeback to summary
public int hashCode()

Implements abstract org.bouncycastle.asn1.ASN1Primitive.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

hasValueback to summary
public boolean hasValue(int x)
hasValueback to summary
public boolean hasValue(long x)
hasValueback to summary
public boolean hasValue(BigInteger x)
intPositiveValueExactback to summary
public int intPositiveValueExact()
intValueback to summary
pack-priv static int intValue(byte[] bytes, int start, int signExt)
intValueExactback to summary
public int intValueExact()
isMalformedback to summary
pack-priv static boolean isMalformed(byte[] bytes)

Apply the correct validation for an INTEGER primitive following the BER rules.

Parameters
bytes:byte[]

The raw encoding of the integer.

Returns:boolean

true if the (in)put fails this validation.

longValueback to summary
pack-priv static long longValue(byte[] bytes, int start, int signExt)
longValueExactback to summary
public long longValueExact()
signBytesToSkipback to summary
pack-priv static int signBytesToSkip(byte[] bytes)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object