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