1 package com.lowagie.bc.asn1; 2 3 import java.io.IOException; 4 import java.util.Enumeration; 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 ASN1OctetString) 62 { 63 Enumeration e; 64 65 if (obj instanceof BERConstructedOctetString) 66 { 67 e = ((BERConstructedOctetString)obj).getObjects(); 68 } 69 else 70 { 71 ASN1OctetString octs = (ASN1OctetString)obj; 72 BERConstructedOctetString berO = new BERConstructedOctetString(octs.getOctets()); 73 74 e = berO.getObjects(); 75 } 76 77 while (e.hasMoreElements()) 78 { 79 out.writeObject(e.nextElement()); 80 } 81 } 82 else if (obj instanceof ASN1Sequence) 83 { 84 Enumeration e = ((ASN1Sequence)obj).getObjects(); 85 86 while (e.hasMoreElements()) 87 { 88 out.writeObject(e.nextElement()); 89 } 90 } 91 else if (obj instanceof ASN1Set) 92 { 93 Enumeration e = ((ASN1Set)obj).getObjects(); 94 95 while (e.hasMoreElements()) 96 { 97 out.writeObject(e.nextElement()); 98 } 99 } 100 else 101 { 102 throw new RuntimeException("not implemented: " + obj.getClass().getName()); 103 } 104 } 105 else 106 { 107 out.writeObject(obj); 108 } 109 } 110 111 out.write(0x00); 112 out.write(0x00); 113 } 114 else 115 { 116 super.encode(out); 117 } 118 } 119 } 120 | Popular Tags |