01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.harmony.security.asn1;
22:
23: import java.io.IOException;
24:
25: import org.apache.harmony.security.x501.AttributeType;
26:
27: /**
28: * Represents ASN.1 open type that is defined by Oid
29: *
30: * @see http://asn1.elibel.tm.fr/en/standards/index.htm
31: */
32:
33: public class ASN1OpenType extends ASN1Any {
34:
35: private final Id key;
36:
37: private final InformationObjectSet pool;
38:
39: public ASN1OpenType(Id key, InformationObjectSet pool) {
40: this .key = key;
41: this .pool = pool;
42: }
43:
44: public Object decode(BerInputStream in) throws IOException {
45:
46: int[] oid = (int[]) in.get(key);
47: if (oid == null) {
48: throw new RuntimeException("");//FIXME message & type //$NON-NLS-1$
49: }
50:
51: AttributeType attr = (AttributeType) pool.get(oid);
52: if (attr == null || (!attr.type.checkTag(in.tag))) {
53: in.content = (byte[]) super .getDecodedObject(in);
54: } else {
55: in.content = attr.type.decode(in);
56: }
57: return in.content;
58: }
59:
60: public Object getDecodedObject(BerInputStream in)
61: throws IOException {
62: return in.content;
63: }
64:
65: public static class Id extends ASN1Oid {
66:
67: public Object decode(BerInputStream in) throws IOException {
68: Object oid = super .decode(in);
69:
70: if (oid == null) {
71: in.put(this , super .getDecodedObject(in));
72: } else {
73: in.put(this , oid);
74: }
75: return oid;
76: }
77:
78: public Object getDecodedObject(BerInputStream in)
79: throws IOException {
80: return in.get(this);
81: }
82: }
83: }
|