001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package org.apache.geronimo.util.asn1; 019 020 import java.io.IOException; 021 022 /** 023 * We insert one of these when we find a tag we don't recognise. 024 */ 025 public class DERUnknownTag 026 extends DERObject 027 { 028 int tag; 029 byte[] data; 030 031 /** 032 * @param tag the tag value. 033 * @param data the octets making up the time. 034 */ 035 public DERUnknownTag( 036 int tag, 037 byte[] data) 038 { 039 this.tag = tag; 040 this.data = data; 041 } 042 043 public int getTag() 044 { 045 return tag; 046 } 047 048 public byte[] getData() 049 { 050 return data; 051 } 052 053 void encode( 054 DEROutputStream out) 055 throws IOException 056 { 057 out.writeEncoded(tag, data); 058 } 059 060 public boolean equals( 061 Object o) 062 { 063 if ((o == null) || !(o instanceof DERUnknownTag)) 064 { 065 return false; 066 } 067 068 DERUnknownTag other = (DERUnknownTag)o; 069 070 if (tag != other.tag) 071 { 072 return false; 073 } 074 075 if (data.length != other.data.length) 076 { 077 return false; 078 } 079 080 for (int i = 0; i < data.length; i++) 081 { 082 if(data[i] != other.data[i]) 083 { 084 return false; 085 } 086 } 087 088 return true; 089 } 090 091 public int hashCode() 092 { 093 byte[] b = this.getData(); 094 int value = 0; 095 096 for (int i = 0; i != b.length; i++) 097 { 098 value ^= (b[i] & 0xff) << (i % 4); 099 } 100 101 return value ^ this.getTag(); 102 } 103 }