1 /*
2  * @(#) $Id: ASN1Explicit.java,v 1.2 2003/07/08 08:13:52 pankaj Exp $
3  *
4  * Copyright (c) 2002-03 by Pankaj Kumar (http://www.pankaj-k.net). 
5  * All rights reserved.
6  *
7  * The license governing the use of this file can be found in the 
8  * root directory of the containing software.
9  */
10package org.jstk.asn1;
11
12import java.io.IOException;
13public class ASN1Explicit extends ASN1Type {
14    private ASN1Type instance = null;
15    public ASN1Explicit(){
16        super(UNIVERSAL, NONE, ANY, ANY);
17    }
18    public ASN1Explicit(byte tagClass, int taggingMethod, int tagNumber){
19        super(tagClass, taggingMethod, tagNumber, ANY);
20        consMask = CONSTRUCTED;
21    }
22    public void decode(ASN1PullParser parser) throws ASN1PullParserException, IOException {
23        int event = parser.next();
24
25        if ((event != tagNumber) || (parser.getTagClass() != tagClass)){
26            parser.prev();      //skip
27            return;
28        }
29        length = parser.getLength();
30        if (length > 0){
31            instance = new ASN1Any();
32            instance.decode(parser);
33        }
34    }
35
36    public byte[] encode(){
37        logger.entering(getClass().getName(), "encode");
38        if (instance == null)
39            setValue(null);
40        else
41            setValue(instance.encode());
42        byte[] bytes = encode1();
43        logger.exiting(getClass().getName(), "encode");
44        return bytes;
45    }
46
47    public void setInstance(ASN1Type instance){
48        this.instance = instance;
49    }
50
51    public ASN1Type getInstance(){
52        return instance;
53    }
54}