1 19 20 package com.maverick.crypto.asn1; 21 22 import java.io.IOException ; 23 24 29 public abstract class ASN1TaggedObject 30 extends DERObject 31 { 32 int tagNo; 33 boolean empty = false; 34 boolean explicit = true; 35 DEREncodable obj = null; 36 37 static public ASN1TaggedObject getInstance( 38 ASN1TaggedObject obj, 39 boolean explicit) 40 { 41 if (explicit) 42 { 43 return (ASN1TaggedObject)obj.getObject(); 44 } 45 46 throw new IllegalArgumentException ("implicitly tagged tagged object"); 47 } 48 49 53 public ASN1TaggedObject( 54 int tagNo, 55 DEREncodable obj) 56 { 57 this.explicit = true; 58 this.tagNo = tagNo; 59 this.obj = obj; 60 } 61 62 67 public ASN1TaggedObject( 68 boolean explicit, 69 int tagNo, 70 DEREncodable obj) 71 { 72 this.explicit = explicit; 73 this.tagNo = tagNo; 74 this.obj = obj; 75 } 76 77 public boolean equals( 78 Object o) 79 { 80 if (o == null || !(o instanceof ASN1TaggedObject)) 81 { 82 return false; 83 } 84 85 ASN1TaggedObject other = (ASN1TaggedObject)o; 86 87 if (tagNo != other.tagNo || empty != other.empty || explicit != other.explicit) 88 { 89 return false; 90 } 91 92 if(obj == null) 93 { 94 if(other.obj != null) 95 { 96 return false; 97 } 98 } 99 else 100 { 101 if(!(obj.equals(other.obj))) 102 { 103 return false; 104 } 105 } 106 107 return true; 108 } 109 110 public int hashCode() 111 { 112 int code = tagNo; 113 114 if (obj != null) 115 { 116 code ^= obj.hashCode(); 117 } 118 119 return code; 120 } 121 122 public int getTagNo() 123 { 124 return tagNo; 125 } 126 127 136 public boolean isExplicit() 137 { 138 return explicit; 139 } 140 141 public boolean isEmpty() 142 { 143 return empty; 144 } 145 146 153 public DERObject getObject() 154 { 155 if (obj != null) 156 { 157 return obj.getDERObject(); 158 } 159 160 return null; 161 } 162 163 abstract void encode(DEROutputStream out) 164 throws IOException ; 165 } 166 | Popular Tags |