1 package com.lowagie.bc.asn1; 2 3 import java.io.IOException; 4 5 10 public abstract class ASN1TaggedObject 11 extends DERObject 12 { 13 int tagNo; 14 boolean empty = false; 15 boolean explicit = true; 16 DEREncodable obj = null; 17 18 static public ASN1TaggedObject getInstance( 19 ASN1TaggedObject obj, 20 boolean explicit) 21 { 22 if (explicit) 23 { 24 return (ASN1TaggedObject)obj.getObject(); 25 } 26 27 throw new IllegalArgumentException("implicitly tagged tagged object"); 28 } 29 30 34 public ASN1TaggedObject( 35 int tagNo, 36 DEREncodable obj) 37 { 38 this.explicit = true; 39 this.tagNo = tagNo; 40 this.obj = obj; 41 } 42 43 48 public ASN1TaggedObject( 49 boolean explicit, 50 int tagNo, 51 DEREncodable obj) 52 { 53 this.explicit = explicit; 54 this.tagNo = tagNo; 55 this.obj = obj; 56 } 57 58 public boolean equals( 59 Object o) 60 { 61 if (o == null || !(o instanceof ASN1TaggedObject)) 62 { 63 return false; 64 } 65 66 ASN1TaggedObject other = (ASN1TaggedObject)o; 67 68 if (tagNo != other.tagNo || empty != other.empty || explicit != other.explicit) 69 { 70 return false; 71 } 72 73 if(obj == null) 74 { 75 if(other.obj != null) 76 { 77 return false; 78 } 79 } 80 else 81 { 82 if(!(obj.equals(other.obj))) 83 { 84 return false; 85 } 86 } 87 88 return true; 89 } 90 91 public int hashCode() 92 { 93 int code = tagNo; 94 95 if (obj != null) 96 { 97 code ^= obj.hashCode(); 98 } 99 100 return code; 101 } 102 103 public int getTagNo() 104 { 105 return tagNo; 106 } 107 108 117 public boolean isExplicit() 118 { 119 return explicit; 120 } 121 122 public boolean isEmpty() 123 { 124 return empty; 125 } 126 127 134 public DERObject getObject() 135 { 136 if (obj != null) 137 { 138 return obj.getDERObject(); 139 } 140 141 return null; 142 } 143 144 abstract void encode(DEROutputStream out) 145 throws IOException; 146 } 147 | Popular Tags |