2 * Copyright 2011 BitMeister Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package jp.bitmeister.asn1.type;
18 import java.util.Arrays;
20 import jp.bitmeister.asn1.annotation.ASN1BuiltIn;
21 import jp.bitmeister.asn1.annotation.ASN1Identifier;
22 import jp.bitmeister.asn1.codec.ber.BerDecoder;
23 import jp.bitmeister.asn1.processor.ASN1Visitor;
26 * Represents a type that does not have definition.
29 * When a decoder meets a source data with a tag that is not registered to
30 * {@code ASN1Modules}, decoder decodes the data as an {@code UnknownType}. An
31 * instance of this class contains a tag class, a tag number and an array of
32 * {@code byte} represents row contents octets.
35 * @author WATANABE, Jun. <jwat at bitmeister.jp>
41 @ASN1Identifier("(unknown)")
42 public final class UnknownType extends ASN1Type {
44 private ASN1TagClass tagClass;
46 private int tagNumber;
51 * Instantiate with a tag class and a tag number.
58 public UnknownType(ASN1TagClass tagClass, int tagNumber) {
59 this.tagClass = tagClass;
60 this.tagNumber = tagNumber;
64 * Set contents octets.
67 * The contents octets.
69 public void set(byte[] value) {
74 * Returns contents octets.
76 * @return The contents octets.
78 public byte[] value() {
85 * @return The ASN.1 tag class.
87 public ASN1TagClass tagClass() {
94 * @return The ASN.1 tag number.
96 public int tagNumber() {
103 * @see jp.bitmeister.asn1.type.ASN1Type#clear()
106 public void clear() {
115 * @see jp.bitmeister.asn1.type.ASN1Type#hasValue()
118 public boolean hasValue() {
119 return value != null;
126 * jp.bitmeister.asn1.type.ASN1Type#accept(jp.bitmeister.asn1.processor.
130 public <R, E extends Throwable> R accept(ASN1Visitor<R, E> visitor) throws E {
131 return visitor.visit(this);
137 * @see jp.bitmeister.asn1.type.ASN1Type#valueEquals(java.lang.Object)
140 public boolean valueEquals(Object other) {
141 if (other instanceof UnknownType) {
142 UnknownType comparison = (UnknownType) other;
143 if (comparison.tagClass == tagClass
144 && comparison.tagNumber == tagNumber) {
145 if (Arrays.equals(comparison.value, value)) {
156 * @see jp.bitmeister.asn1.type.ASN1Type#hashCode()
159 public int hashCode() {
160 return value.hashCode();
166 * @see jp.bitmeister.asn1.type.ASN1Type#clone()
169 public Object clone() {
170 UnknownType clone = new UnknownType(tagClass, tagNumber);
171 clone.value = value.clone();