org.bouncycastle.oer.its.Uint16 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcutil-jdk15on Show documentation
Show all versions of bcutil-jdk15on Show documentation
The Bouncy Castle Java APIs for ASN.1 extension and utility APIs used to support bcpkix and bctls. This jar contains APIs for JDK 1.5 and up.
The newest version!
package org.bouncycastle.oer.its;
import java.math.BigInteger;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1Primitive;
public class Uint16
extends ASN1Object
{
private final int value;
public Uint16(int value)
{
this.value = verify(value);
}
public Uint16(BigInteger value)
{
this.value = value.intValue();
}
public static Uint16 getInstance(Object o)
{
if (o instanceof Uint16)
{
return (Uint16)o;
}
else
{
return new Uint16(ASN1Integer.getInstance(o).getValue());
}
}
protected int verify(int value)
{
if (value < 0)
{
throw new IllegalArgumentException("Uint16 must be >= 0");
}
if (value > 0xFFFF)
{
throw new IllegalArgumentException("Uint16 must be <= 0xFFFF");
}
return value;
}
public ASN1Primitive toASN1Primitive()
{
return new ASN1Integer(value);
}
}