KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > util > asn1 > DERUnknownTag


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.util.asn1;
19
20 import java.io.IOException JavaDoc;
21
22 /**
23  * We insert one of these when we find a tag we don't recognise.
24  */

25 public class DERUnknownTag
26     extends DERObject
27 {
28     int tag;
29     byte[] data;
30
31     /**
32      * @param tag the tag value.
33      * @param data the octets making up the time.
34      */

35     public DERUnknownTag(
36         int tag,
37         byte[] data)
38     {
39         this.tag = tag;
40         this.data = data;
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 JavaDoc
56     {
57         out.writeEncoded(tag, data);
58     }
59
60     public boolean equals(
61         Object JavaDoc o)
62     {
63         if ((o == null) || !(o instanceof DERUnknownTag))
64         {
65             return false;
66         }
67
68         DERUnknownTag other = (DERUnknownTag)o;
69
70         if (tag != other.tag)
71         {
72             return false;
73         }
74
75         if (data.length != other.data.length)
76         {
77             return false;
78         }
79
80         for (int i = 0; i < data.length; i++)
81         {
82             if(data[i] != other.data[i])
83             {
84                 return false;
85             }
86         }
87
88         return true;
89     }
90
91     public int hashCode()
92     {
93         byte[] b = this.getData();
94         int value = 0;
95
96         for (int i = 0; i != b.length; i++)
97         {
98             value ^= (b[i] & 0xff) << (i % 4);
99         }
100
101         return value ^ this.getTag();
102     }
103 }
104
Popular Tags