1 19 20 package com.maverick.crypto.asn1; 21 22 import java.io.IOException ; 23 import java.util.Enumeration ; 24 25 30 public class BERTaggedObject 31 extends DERTaggedObject 32 { 33 37 public BERTaggedObject( 38 int tagNo, 39 DEREncodable obj) 40 { 41 super(tagNo, obj); 42 } 43 44 49 public BERTaggedObject( 50 boolean explicit, 51 int tagNo, 52 DEREncodable obj) 53 { 54 super(explicit, tagNo, obj); 55 } 56 57 61 public BERTaggedObject( 62 int tagNo) 63 { 64 super(false, tagNo, new BERConstructedSequence()); 65 } 66 67 void encode( 68 DEROutputStream out) 69 throws IOException 70 { 71 if (out instanceof ASN1OutputStream || out instanceof BEROutputStream) 72 { 73 out.write(CONSTRUCTED | TAGGED | tagNo); 74 out.write(0x80); 75 76 if (!empty) 77 { 78 if (!explicit) 79 { 80 if (obj instanceof ASN1OctetString) 81 { 82 Enumeration e; 83 84 if (obj instanceof BERConstructedOctetString) 85 { 86 e = ((BERConstructedOctetString)obj).getObjects(); 87 } 88 else 89 { 90 ASN1OctetString octs = (ASN1OctetString)obj; 91 BERConstructedOctetString berO = new BERConstructedOctetString(octs.getOctets()); 92 93 e = berO.getObjects(); 94 } 95 96 while (e.hasMoreElements()) 97 { 98 out.writeObject(e.nextElement()); 99 } 100 } 101 else if (obj instanceof ASN1Sequence) 102 { 103 Enumeration e = ((ASN1Sequence)obj).getObjects(); 104 105 while (e.hasMoreElements()) 106 { 107 out.writeObject(e.nextElement()); 108 } 109 } 110 else if (obj instanceof ASN1Set) 111 { 112 Enumeration e = ((ASN1Set)obj).getObjects(); 113 114 while (e.hasMoreElements()) 115 { 116 out.writeObject(e.nextElement()); 117 } 118 } 119 else 120 { 121 throw new RuntimeException ("not implemented: " + obj.getClass().getName()); 122 } 123 } 124 else 125 { 126 out.writeObject(obj); 127 } 128 } 129 130 out.write(0x00); 131 out.write(0x00); 132 } 133 else 134 { 135 super.encode(out); 136 } 137 } 138 } 139 | Popular Tags |