1 19 20 package com.maverick.crypto.asn1; 21 22 import java.io.ByteArrayOutputStream ; 23 import java.io.IOException ; 24 25 30 public class DERTaggedObject 31 extends ASN1TaggedObject 32 { 33 37 public DERTaggedObject( 38 int tagNo, 39 DEREncodable obj) 40 { 41 super(tagNo, obj); 42 } 43 44 49 public DERTaggedObject( 50 boolean explicit, 51 int tagNo, 52 DEREncodable obj) 53 { 54 super(explicit, tagNo, obj); 55 } 56 57 61 public DERTaggedObject( 62 int tagNo) 63 { 64 super(false, tagNo, new DERSequence()); 65 } 66 67 void encode( 68 DEROutputStream out) 69 throws IOException 70 { 71 if (!empty) 72 { 73 ByteArrayOutputStream bOut = new ByteArrayOutputStream (); 74 DEROutputStream dOut = new DEROutputStream(bOut); 75 76 dOut.writeObject(obj); 77 dOut.close(); 78 79 byte[] bytes = bOut.toByteArray(); 80 81 if (explicit) 82 { 83 out.writeEncoded(CONSTRUCTED | TAGGED | tagNo, bytes); 84 } 85 else 86 { 87 if ((bytes[0] & CONSTRUCTED) != 0) 91 { 92 bytes[0] = (byte)(CONSTRUCTED | TAGGED | tagNo); 93 } 94 else 95 { 96 bytes[0] = (byte)(TAGGED | tagNo); 97 } 98 99 out.write(bytes); 100 } 101 } 102 else 103 { 104 out.writeEncoded(CONSTRUCTED | TAGGED | tagNo, new byte[0]); 105 } 106 } 107 } 108 | Popular Tags |