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/** 19* @author Stepan M. Mishura 20* @version $Revision$ 21*/ 22 23package org.apache.harmony.security.asn1; 24 25import java.io.IOException; 26 27import org.apache.harmony.security.x501.AttributeType; 28 29 30 31/** 32 * Represents ASN.1 open type that is defined by Oid 33 * 34 * @see <a href="http://asn1.elibel.tm.fr/en/standards/index.htm">ASN.1</a> 35 */ 36 37public class ASN1OpenType extends ASN1Any { 38 39 private final Id key; 40 41 private final InformationObjectSet pool; 42 43 public ASN1OpenType(Id key, InformationObjectSet pool) { 44 this.key = key; 45 this.pool = pool; 46 } 47 48 public Object decode(BerInputStream in) throws IOException { 49 50 int[] oid = (int[]) in.get(key); 51 if (oid == null) { 52 throw new RuntimeException("");//FIXME message & type //$NON-NLS-1$ 53 } 54 55 AttributeType attr = (AttributeType) pool.get(oid); 56 if (attr == null || (!attr.type.checkTag(in.tag))) { 57 in.content = (byte[]) super.getDecodedObject(in); 58 } else { 59 in.content = attr.type.decode(in); 60 } 61 return in.content; 62 } 63 64 public Object getDecodedObject(BerInputStream in) throws IOException { 65 return in.content; 66 } 67 68 public static class Id extends ASN1Oid { 69 70 public Object decode(BerInputStream in) throws IOException { 71 Object oid = super.decode(in); 72 73 if (oid == null) { 74 in.put(this, super.getDecodedObject(in)); 75 } else { 76 in.put(this, oid); 77 } 78 return oid; 79 } 80 81 public Object getDecodedObject(BerInputStream in) throws IOException { 82 return in.get(this); 83 } 84 } 85} 86