1 17 18 package org.apache.geronimo.util.asn1; 19 20 import java.io.IOException ; 21 22 public class DERBoolean 23 extends DERObject 24 { 25 byte value; 26 27 public static final DERBoolean FALSE = new DERBoolean(false); 28 public static final DERBoolean TRUE = new DERBoolean(true); 29 30 35 public static DERBoolean getInstance( 36 Object obj) 37 { 38 if (obj == null || obj instanceof DERBoolean) 39 { 40 return (DERBoolean)obj; 41 } 42 43 if (obj instanceof ASN1OctetString) 44 { 45 return new DERBoolean(((ASN1OctetString)obj).getOctets()); 46 } 47 48 if (obj instanceof ASN1TaggedObject) 49 { 50 return getInstance(((ASN1TaggedObject)obj).getObject()); 51 } 52 53 throw new IllegalArgumentException ("illegal object in getInstance: " + obj.getClass().getName()); 54 } 55 56 59 public static DERBoolean getInstance( 60 boolean value) 61 { 62 return (value ? TRUE : FALSE); 63 } 64 65 74 public static DERBoolean getInstance( 75 ASN1TaggedObject obj, 76 boolean explicit) 77 { 78 return getInstance(obj.getObject()); 79 } 80 81 public DERBoolean( 82 byte[] value) 83 { 84 this.value = value[0]; 85 } 86 87 public DERBoolean( 88 boolean value) 89 { 90 this.value = (value) ? (byte)0xff : (byte)0; 91 } 92 93 public boolean isTrue() 94 { 95 return (value != 0); 96 } 97 98 void encode( 99 DEROutputStream out) 100 throws IOException 101 { 102 byte[] bytes = new byte[1]; 103 104 bytes[0] = value; 105 106 out.writeEncoded(BOOLEAN, bytes); 107 } 108 109 public boolean equals( 110 Object o) 111 { 112 if ((o == null) || !(o instanceof DERBoolean)) 113 { 114 return false; 115 } 116 117 return (value == ((DERBoolean)o).value); 118 } 119 120 public int hashCode() 121 { 122 return value; 123 } 124 125 } 126 | Popular Tags |