1 package org.bouncycastle.asn1;
2
3 import java.io.*;
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
22 public ASN1TaggedObject(
23 int tagNo,
24 DEREncodable obj)
25 {
26 this.explicit = true;
27 this.tagNo = tagNo;
28 this.obj = obj;
29 }
30
31
36 public ASN1TaggedObject(
37 boolean explicit,
38 int tagNo,
39 DEREncodable obj)
40 {
41 this.explicit = explicit;
42 this.tagNo = tagNo;
43 this.obj = obj;
44 }
45
46 public boolean equals(
47 Object o)
48 {
49 if (o == null || !(o instanceof ASN1TaggedObject))
50 {
51 return false;
52 }
53
54 ASN1TaggedObject other = (ASN1TaggedObject)o;
55
56 if(tagNo != other.tagNo || empty != other.empty || explicit != other.explicit)
57 {
58 return false;
59 }
60
61 if(obj == null)
62 {
63 if(other.obj != null)
64 {
65 return false;
66 }
67 }
68 else
69 {
70 if(!(obj.equals(other.obj)))
71 {
72 return false;
73 }
74 }
75
76 return true;
77 }
78
79 public int getTagNo()
80 {
81 return tagNo;
82 }
83
84
93 public boolean isExplicit()
94 {
95 return explicit;
96 }
97
98 public boolean isEmpty()
99 {
100 return empty;
101 }
102
103
110 public DERObject getObject()
111 {
112 if (obj != null)
113 {
114 return obj.getDERObject();
115 }
116
117 return null;
118 }
119
120 abstract void encode(DEROutputStream out)
121 throws IOException;
122 }
123