1 package org.bouncycastle.asn1;
2
3 import java.io.*;
4 import java.util.*;
5
6
11 public class BERTaggedObject
12 extends DERTaggedObject
13 {
14
18 public BERTaggedObject(
19 int tagNo,
20 DEREncodable obj)
21 {
22 super(tagNo, obj);
23 }
24
25
30 public BERTaggedObject(
31 boolean explicit,
32 int tagNo,
33 DEREncodable obj)
34 {
35 super(explicit, tagNo, obj);
36 }
37
38
42 public BERTaggedObject(
43 int tagNo)
44 {
45 super(false, tagNo, new BERConstructedSequence());
46 }
47
48 void encode(
49 DEROutputStream out)
50 throws IOException
51 {
52 if (out instanceof ASN1OutputStream || out instanceof BEROutputStream)
53 {
54 out.write(CONSTRUCTED | TAGGED | tagNo);
55 out.write(0x80);
56
57 if (!empty)
58 {
59 if (!explicit)
60 {
61 if (obj instanceof BERConstructedOctetString)
62 {
63 Enumeration e = ((BERConstructedOctetString)obj).getObjects();
64
65 while (e.hasMoreElements())
66 {
67 out.writeObject(e.nextElement());
68 }
69 }
70 else if (obj instanceof ASN1Sequence)
71 {
72 Enumeration e = ((ASN1Sequence)obj).getObjects();
73
74 while (e.hasMoreElements())
75 {
76 out.writeObject(e.nextElement());
77 }
78 }
79 else if (obj instanceof ASN1Set)
80 {
81 Enumeration e = ((ASN1Set)obj).getObjects();
82
83 while (e.hasMoreElements())
84 {
85 out.writeObject(e.nextElement());
86 }
87 }
88 else
89 {
90 throw new RuntimeException("not implemented: " + obj.getClass().getName());
91 }
92 }
93 else
94 {
95 out.writeObject(obj);
96 }
97 }
98
99 out.write(0x00);
100 out.write(0x00);
101 }
102 else
103 {
104 super.encode(out);
105 }
106 }
107 }
108