All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.oer.its.Uint16 Maven / Gradle / Ivy

Go to download

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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy