1 17 18 package org.apache.geronimo.util.asn1; 19 20 import java.io.ByteArrayInputStream ; 21 import java.io.ByteArrayOutputStream ; 22 import java.io.IOException ; 23 24 27 public class DERApplicationSpecific 28 extends DERObject 29 { 30 private int tag; 31 private byte[] octets; 32 33 public DERApplicationSpecific( 34 int tag, 35 byte[] octets) 36 { 37 this.tag = tag; 38 this.octets = octets; 39 } 40 41 public DERApplicationSpecific( 42 int tag, 43 DEREncodable object) 44 throws IOException 45 { 46 this.tag = tag | DERTags.CONSTRUCTED; 47 48 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 49 DEROutputStream dos = new DEROutputStream(baos); 50 51 dos.writeObject(object); 52 53 this.octets = baos.toByteArray(); 54 } 55 56 public boolean isConstructed() 57 { 58 return (tag & DERTags.CONSTRUCTED) != 0; 59 } 60 61 public byte[] getContents() 62 { 63 return octets; 64 } 65 66 public int getApplicationTag() 67 { 68 return tag & 0x1F; 69 } 70 71 public DERObject getObject() 72 throws IOException 73 { 74 return new ASN1InputStream(new ByteArrayInputStream (getContents())).readObject(); 75 } 76 77 80 void encode(DEROutputStream out) throws IOException 81 { 82 out.writeEncoded(DERTags.APPLICATION | tag, octets); 83 } 84 85 public boolean equals( 86 Object o) 87 { 88 if ((o == null) || !(o instanceof DERApplicationSpecific)) 89 { 90 return false; 91 } 92 93 DERApplicationSpecific other = (DERApplicationSpecific)o; 94 95 if (tag != other.tag) 96 { 97 return false; 98 } 99 100 if (octets.length != other.octets.length) 101 { 102 return false; 103 } 104 105 for (int i = 0; i < octets.length; i++) 106 { 107 if (octets[i] != other.octets[i]) 108 { 109 return false; 110 } 111 } 112 113 return true; 114 } 115 116 public int hashCode() 117 { 118 byte[] b = this.getContents(); 119 int value = 0; 120 121 for (int i = 0; i != b.length; i++) 122 { 123 value ^= (b[i] & 0xff) << (i % 4); 124 } 125 126 return value ^ this.getApplicationTag(); 127 } 128 } 129 | Popular Tags |