Package org.bouncycastle.asn1
Class ASN1Integer
- java.lang.Object
-
- org.bouncycastle.asn1.ASN1Object
-
- org.bouncycastle.asn1.ASN1Primitive
-
- org.bouncycastle.asn1.ASN1Integer
-
- All Implemented Interfaces:
ASN1Encodable,Encodable
public class ASN1Integer extends ASN1Primitive
Class representing the ASN.1 INTEGER type.
-
-
Field Summary
Fields Modifier and Type Field Description static ASN1IntegerFIVEstatic ASN1IntegerFOURstatic ASN1IntegerONEstatic ASN1IntegerTHREEstatic ASN1IntegerTWOstatic ASN1IntegerZERO
-
Constructor Summary
Constructors Constructor Description ASN1Integer(byte[] bytes)Construct an INTEGER from the passed in byte array.ASN1Integer(int value)Construct an INTEGER from the passed in int value.ASN1Integer(long value)Construct an INTEGER from the passed in long value.ASN1Integer(java.math.BigInteger value)Construct an INTEGER from the passed in BigInteger value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ASN1IntegergetInstance(java.lang.Object obj)Return an integer from the passed in object.static ASN1IntegergetInstance(ASN1TaggedObject taggedObject, boolean declaredExplicit)Return an Integer from a tagged object.java.math.BigIntegergetPositiveValue()in some cases positive values get crammed into a space, that's not quite big enough...static ASN1IntegergetTagged(ASN1TaggedObject taggedObject, boolean declaredExplicit)java.math.BigIntegergetValue()inthashCode()booleanhasValue(int x)booleanhasValue(long x)booleanhasValue(java.math.BigInteger x)intintPositiveValueExact()intintValueExact()longlongValueExact()java.lang.StringtoString()static ASN1IntegervalueOf(int value)static ASN1IntegervalueOf(long value)-
Methods inherited from class org.bouncycastle.asn1.ASN1Primitive
encodeTo, encodeTo, equals, equals, equals, fromByteArray, toASN1Primitive
-
Methods inherited from class org.bouncycastle.asn1.ASN1Object
getEncoded, getEncoded, hasEncodedTagValue
-
-
-
-
Field Detail
-
ZERO
public static final ASN1Integer ZERO
-
ONE
public static final ASN1Integer ONE
-
TWO
public static final ASN1Integer TWO
-
THREE
public static final ASN1Integer THREE
-
FOUR
public static final ASN1Integer FOUR
-
FIVE
public static final ASN1Integer FIVE
-
-
Constructor Detail
-
ASN1Integer
public ASN1Integer(int value)
Construct an INTEGER from the passed in int value.- Parameters:
value- the int representing the value desired.
-
ASN1Integer
public ASN1Integer(long value)
Construct an INTEGER from the passed in long value.- Parameters:
value- the long representing the value desired.
-
ASN1Integer
public ASN1Integer(java.math.BigInteger value)
Construct an INTEGER from the passed in BigInteger value.- Parameters:
value- the BigInteger representing the value desired.
-
ASN1Integer
public ASN1Integer(byte[] bytes)
Construct an INTEGER from the passed in byte array.NB: 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- the byte array representing a 2's complement encoding of a BigInteger.
-
-
Method Detail
-
getInstance
public static ASN1Integer getInstance(java.lang.Object obj)
Return an integer from the passed in object.- Parameters:
obj- an ASN1Integer or an object that can be converted into one.- Returns:
- an ASN1Integer instance.
- Throws:
java.lang.IllegalArgumentException- if the object cannot be converted.
-
getInstance
public static ASN1Integer getInstance(ASN1TaggedObject taggedObject, boolean declaredExplicit)
Return an Integer from a tagged object.- Parameters:
taggedObject- the tagged object holding the object we wantdeclaredExplicit- true if the object is meant to be explicitly tagged false otherwise.- Returns:
- an ASN1Integer instance.
- Throws:
java.lang.IllegalArgumentException- if the tagged object cannot be converted.
-
getTagged
public static ASN1Integer getTagged(ASN1TaggedObject taggedObject, boolean declaredExplicit)
-
valueOf
public static ASN1Integer valueOf(int value)
-
valueOf
public static ASN1Integer valueOf(long value)
-
getPositiveValue
public java.math.BigInteger getPositiveValue()
in some cases positive values get crammed into a space, that's not quite big enough...- Returns:
- the BigInteger that results from treating this ASN.1 INTEGER as unsigned.
-
getValue
public java.math.BigInteger getValue()
-
hasValue
public boolean hasValue(int x)
-
hasValue
public boolean hasValue(long x)
-
hasValue
public boolean hasValue(java.math.BigInteger x)
-
intPositiveValueExact
public int intPositiveValueExact()
-
intValueExact
public int intValueExact()
-
longValueExact
public long longValueExact()
-
hashCode
public int hashCode()
- Specified by:
hashCodein classASN1Primitive
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-