1 package org.bouncycastle.asn1;
4 import java.math.BigInteger;
6 public class DEREnumerated
12 * return an integer from the passed in object
14 * @exception IllegalArgumentException if the object cannot be converted.
16 public static DEREnumerated getInstance(
19 if (obj == null || obj instanceof DEREnumerated)
21 return (DEREnumerated)obj;
24 if (obj instanceof ASN1OctetString)
26 return new DEREnumerated(((ASN1OctetString)obj).getOctets());
29 if (obj instanceof ASN1TaggedObject)
31 return getInstance(((ASN1TaggedObject)obj).getObject());
34 throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
38 * return an Enumerated from a tagged object.
40 * @param obj the tagged object holding the object we want
41 * @param explicit true if the object is meant to be explicitly
42 * tagged false otherwise.
43 * @exception IllegalArgumentException if the tagged object cannot
46 public static DEREnumerated getInstance(
50 return getInstance(obj.getObject());
56 bytes = BigInteger.valueOf(value).toByteArray();
62 bytes = value.toByteArray();
71 public BigInteger getValue()
73 return new BigInteger(bytes);
80 out.writeEncoded(ENUMERATED, bytes);
83 public boolean equals(
86 if (o == null || !(o instanceof DEREnumerated))
91 DEREnumerated other = (DEREnumerated)o;
93 if (bytes.length != other.bytes.length)
98 for (int i = 0; i != bytes.length; i++)
100 if (bytes[i] != other.bytes[i])