1 /**
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one or more
4 * contributor license agreements. See the NOTICE file distributed with
5 * this work for additional information regarding copyright ownership.
6 * The ASF licenses this file to You under the Apache License, Version 2.0
7 * (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 package org.apache.geronimo.util.asn1;
20
21 import java.io.IOException;
22
23 /**
24 * We insert one of these when we find a tag we don't recognise.
25 */
26 public class DERUnknownTag
27 extends DERObject
28 {
29 int tag;
30 byte[] data;
31
32 /**
33 * @param tag the tag value.
34 * @param data the octets making up the time.
35 */
36 public DERUnknownTag(
37 int tag,
38 byte[] data)
39 {
40 this.tag = tag;
41 this.data = data;
42 }
43
44 public int getTag()
45 {
46 return tag;
47 }
48
49 public byte[] getData()
50 {
51 return data;
52 }
53
54 void encode(
55 DEROutputStream out)
56 throws IOException
57 {
58 out.writeEncoded(tag, data);
59 }
60
61 public boolean equals(
62 Object o)
63 {
64 if ((o == null) || !(o instanceof DERUnknownTag))
65 {
66 return false;
67 }
68
69 DERUnknownTag other = (DERUnknownTag)o;
70
71 if (tag != other.tag)
72 {
73 return false;
74 }
75
76 if (data.length != other.data.length)
77 {
78 return false;
79 }
80
81 for (int i = 0; i < data.length; i++)
82 {
83 if(data[i] != other.data[i])
84 {
85 return false;
86 }
87 }
88
89 return true;
90 }
91
92 public int hashCode()
93 {
94 byte[] b = this.getData();
95 int value = 0;
96
97 for (int i = 0; i != b.length; i++)
98 {
99 value ^= (b[i] & 0xff) << (i % 4);
100 }
101
102 return value ^ this.getTag();
103 }
104 }