org.bouncycastle.asn1.cmc.BodyPartID Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcutil-fips Show documentation
Show all versions of bcutil-fips Show documentation
The Bouncy Castle Java APIs for ASN.1 extension and utility APIs used to support bcpkix and bctls with the BC FIPS provider. The APIs may also be used with other providers although if being used in a FIPS context it is the responsibility of the user to ensure that any other providers used are FIPS certified and used appropriately.
The newest version!
package org.bouncycastle.asn1.cmc;
import java.math.BigInteger;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1Primitive;
/**
*
* bodyIdMax INTEGER ::= 4294967295
*
* BodyPartID ::= INTEGER(0..bodyIdMax)
*
*/
public class BodyPartID
extends ASN1Object
{
public static final long bodyIdMax = 4294967295L;
private final long id;
public BodyPartID(long id)
{
if (id < 0 || id > bodyIdMax)
{
throw new IllegalArgumentException("id out of range");
}
this.id = id;
}
private static long convert(BigInteger value)
{
if (value.bitLength() > 32)
{
throw new IllegalArgumentException("id out of range");
}
return value.longValue();
}
private BodyPartID(ASN1Integer id)
{
this(convert(id.getValue()));
}
public static BodyPartID getInstance(Object o)
{
if (o instanceof BodyPartID)
{
return (BodyPartID)o;
}
if (o != null)
{
return new BodyPartID(ASN1Integer.getInstance(o));
}
return null;
}
public long getID()
{
return id;
}
public ASN1Primitive toASN1Primitive()
{
return new ASN1Integer(id);
}
}