    001package org.apache.commons.ssl.asn1;
    002
    003import java.io.IOException;
    004
    005/** We insert one of these when we find a tag we don't recognise. */
    006public class DERUnknownTag
    007    extends DERObject {
    008    int tag;
    009    byte[] data;
    010
    011    /**
    012     * @param tag  the tag value.
    013     * @param data the octets making up the time.
    014     */
    015    public DERUnknownTag(
    016        int tag,
    017        byte[] data) {
    018        this.tag = tag;
    019        this.data = data;
    020    }
    021
    022    public int getTag() {
    023        return tag;
    024    }
    025
    026    public byte[] getData() {
    027        return data;
    028    }
    029
    030    void encode(
    031        DEROutputStream out)
    032        throws IOException {
    033        out.writeEncoded(tag, data);
    034    }
    035
    036    public boolean equals(
    037        Object o) {
    038        if (!(o instanceof DERUnknownTag)) {
    039            return false;
    040        }
    041
    042        DERUnknownTag other = (DERUnknownTag) o;
    043
    044        if (tag != other.tag) {
    045            return false;
    046        }
    047
    048        if (data.length != other.data.length) {
    049            return false;
    050        }
    051
    052        for (int i = 0; i < data.length; i++) {
    053            if (data[i] != other.data[i]) {
    054                return false;
    055            }
    056        }
    057
    058        return true;
    059    }
    060
    061    public int hashCode() {
    062        byte[] b = this.getData();
    063        int value = 0;
    064
    065        for (int i = 0; i != b.length; i++) {
    066            value ^= (b[i] & 0xff) << (i % 4);
    067        }
    068
    069        return value ^ this.getTag();
    070    }
    071}