Home | History | Annotate | Download | only in asn1
      1 package org.bouncycastle.asn1;
      2 
      3 import java.io.IOException;
      4 
      5 import org.bouncycastle.util.Arrays;
      6 
      7 /**
      8  * We insert one of these when we find a tag we don't recognise.
      9  */
     10 public class DERUnknownTag
     11     extends DERObject
     12 {
     13     private boolean   isConstructed;
     14     private int       tag;
     15     private byte[]    data;
     16 
     17     /**
     18      * @param tag the tag value.
     19      * @param data the contents octets.
     20      */
     21     public DERUnknownTag(
     22         int     tag,
     23         byte[]  data)
     24     {
     25         this(false, tag, data);
     26     }
     27 
     28     public DERUnknownTag(
     29         boolean isConstructed,
     30         int     tag,
     31         byte[]  data)
     32     {
     33         this.isConstructed = isConstructed;
     34         this.tag = tag;
     35         this.data = data;
     36     }
     37 
     38     public boolean isConstructed()
     39     {
     40         return isConstructed;
     41     }
     42 
     43     public int getTag()
     44     {
     45         return tag;
     46     }
     47 
     48     public byte[] getData()
     49     {
     50         return data;
     51     }
     52 
     53     void encode(
     54         DEROutputStream  out)
     55         throws IOException
     56     {
     57         out.writeEncoded(isConstructed ? DERTags.CONSTRUCTED : 0, tag, data);
     58     }
     59 
     60     public boolean equals(
     61         Object o)
     62     {
     63         if (!(o instanceof DERUnknownTag))
     64         {
     65             return false;
     66         }
     67 
     68         DERUnknownTag other = (DERUnknownTag)o;
     69 
     70         return isConstructed == other.isConstructed
     71             && tag == other.tag
     72             && Arrays.areEqual(data, other.data);
     73     }
     74 
     75     public int hashCode()
     76     {
     77         return (isConstructed ? ~0 : 0) ^ tag ^ Arrays.hashCode(data);
     78     }
     79 }
     80