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: /**
019: * @author Vladimir N. Molotkov, Stepan M. Mishura
020: * @version $Revision$
021: */package org.apache.harmony.security.asn1;
022:
023: import java.io.IOException;
024:
025: import org.apache.harmony.security.internal.nls.Messages;
026:
027: /**
028: * This class represents explicitly tagged ASN.1 type.
029: *
030: * @see http://asn1.elibel.tm.fr/en/standards/index.htm
031: */
032:
033: public final class ASN1Explicit extends ASN1Constructured {
034:
035: /**
036: * Tagged type
037: */
038: public final ASN1Type type;
039:
040: /**
041: * Constructs explicitly tagged ASN.1 type
042: * with context-specific tag class and specified tag number.
043: *
044: * @param tagNumber - ASN.1 tag number
045: * @param type - ASN.1 type to be tagged
046: * @throws IllegalArgumentException - if tagNumber is invalid
047: */
048: public ASN1Explicit(int tagNumber, ASN1Type type) {
049: this (CLASS_CONTEXTSPECIFIC, tagNumber, type);
050: }
051:
052: /**
053: * Constructs explicitly tagged ASN.1 type.
054: *
055: * @param tagClass - ASN.1 tag class.
056: * @param tagNumber - ASN.1 tag number
057: * @param type - ASN.1 type to be tagged
058: * @throws IllegalArgumentException - if tagClass or tagNumber is invalid
059: */
060: public ASN1Explicit(int tagClass, int tagNumber, ASN1Type type) {
061: super (tagClass, tagNumber);
062:
063: this .type = type;
064: }
065:
066: //
067: //
068: // Decode
069: //
070: //
071:
072: public Object decode(BerInputStream in) throws IOException {
073: if (constrId != in.tag) {
074: throw new ASN1Exception(Messages.getString("security.13F", //$NON-NLS-1$
075: new Object[] { in.tagOffset,
076: Integer.toHexString(constrId),
077: Integer.toHexString(in.tag) }));
078: }
079: in.next();
080:
081: in.content = type.decode(in);
082:
083: if (in.isVerify) {
084: return null;
085: }
086: return getDecodedObject(in);
087: }
088:
089: //
090: //
091: // Encode
092: //
093: //
094:
095: public void encodeContent(BerOutputStream out) {
096: out.encodeExplicit(this );
097: }
098:
099: public void setEncodingContent(BerOutputStream out) {
100: out.getExplicitLength(this );
101: }
102:
103: public String toString() {
104: //FIXME fix performance
105: return super .toString() + " for type " + type; //$NON-NLS-1$
106: }
107: }
|