1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.asn1.der;
19
20 import java.io.IOException;
21 import java.util.Enumeration;
22
23 /***
24 * BER TaggedObject
25 */
26 public class BERTaggedObject extends DERTaggedObject
27 {
28 /***
29 * @param tag the tag number for this object.
30 * @param obj the tagged object.
31 */
32 public BERTaggedObject( int tag, DEREncodable obj )
33 {
34 super( tag, obj );
35 }
36
37 /***
38 * @param true if an explicitly tagged object.
39 * @param tag the tag number for this object.
40 * @param obj the tagged object.
41 */
42 public BERTaggedObject( boolean explicit, int tag, DEREncodable obj )
43 {
44 super( explicit, tag, obj );
45 }
46
47 public void encode( ASN1OutputStream out )
48 throws IOException
49 {
50 out.write( DERObject.CONSTRUCTED | DERObject.TAGGED | tag );
51 out.write( DERObject.TAGGED );
52
53 if ( !empty )
54 {
55 if ( !explicit )
56 {
57 if ( obj instanceof DEROctetString )
58 {
59 Enumeration e;
60
61 if ( obj instanceof BERConstructedOctetString )
62 {
63 e = ( (BERConstructedOctetString)obj ).getObjects();
64 }
65 else
66 {
67 DEROctetString octs = (DEROctetString)obj;
68 BERConstructedOctetString berO = new BERConstructedOctetString( octs.getOctets() );
69
70 e = berO.getObjects();
71 }
72
73 while ( e.hasMoreElements() )
74 {
75 out.writeObject( e.nextElement() );
76 }
77 }
78 else if ( obj instanceof DERSequence )
79 {
80 Enumeration e = ( (DERSequence)obj ).getObjects();
81
82 while ( e.hasMoreElements() )
83 {
84 out.writeObject( e.nextElement() );
85 }
86 }
87 else
88 {
89 throw new RuntimeException( "Not implemented: " + obj.getClass().getName() );
90 }
91 }
92 else
93 {
94 out.writeObject( obj );
95 }
96 }
97
98 out.write( DERObject.TERMINATOR );
99 out.write( DERObject.TERMINATOR );
100 }
101 }
102