1 package org.bouncycastle.asn1;
5 public class DERBoolean
10 public static final DERBoolean FALSE = new DERBoolean(false);
11 public static final DERBoolean TRUE = new DERBoolean(true);
14 * return a boolean from the passed in object.
16 * @exception IllegalArgumentException if the object cannot be converted.
18 public static DERBoolean getInstance(
21 if (obj == null || obj instanceof DERBoolean)
23 return (DERBoolean)obj;
26 if (obj instanceof ASN1OctetString)
28 return new DERBoolean(((ASN1OctetString)obj).getOctets());
31 if (obj instanceof ASN1TaggedObject)
33 return getInstance(((ASN1TaggedObject)obj).getObject());
36 throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
40 * return a DERBoolean from the passed in boolean.
42 public static DERBoolean getInstance(
45 return (value ? TRUE : FALSE);
49 * return a Boolean from a tagged object.
51 * @param obj the tagged object holding the object we want
52 * @param explicit true if the object is meant to be explicitly
53 * tagged false otherwise.
54 * @exception IllegalArgumentException if the tagged object cannot
57 public static DERBoolean getInstance(
61 return getInstance(obj.getObject());
67 this.value = value[0];
73 this.value = (value) ? (byte)0xff : (byte)0;
76 public boolean isTrue()
85 byte[] bytes = new byte[1];
89 out.writeEncoded(BOOLEAN, bytes);
92 public boolean equals(
95 if ((o == null) || !(o instanceof DERBoolean))
100 return (value == ((DERBoolean)o).value);