KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ca > commons > security > asn1 > ASN1Type


1
2 package com.ca.commons.security.asn1;
3
4 import java.util.Hashtable JavaDoc;
5
6 /**
7  * This class is the collection of all necessary ASN.1 types that are
8  * used in this package and other packages.
9  */

10 public class ASN1Type implements java.io.Serializable JavaDoc
11 {
12
13     private int tag;
14     private String JavaDoc name;
15     
16     private static Hashtable JavaDoc asn1Types = new Hashtable JavaDoc(27);
17     
18     /* UNIVERSAL class types */
19     
20     public static final ASN1Type BOOLEAN = new ASN1Type(1,
21                                            "BOOLEAN");
22     public static final ASN1Type INTEGER = new ASN1Type(2,
23                                            "INTEGER");
24     public static final ASN1Type BIT_STRING = new ASN1Type(3,
25             "BIT STRING");
26     public static final ASN1Type OCTET_STRING = new ASN1Type(4,
27             "OCTET STRING");
28     public static final ASN1Type NULL = new ASN1Type(5,
29                                         "NULL");
30     public static final ASN1Type OBJECT_ID = new ASN1Type(6,
31             "OBJECT IDENTIFIER");
32     public static final ASN1Type ENUMERATED = new ASN1Type(10,
33             "ENUMERATED");
34     public static final ASN1Type PrintableString = new ASN1Type(19,
35             "PrintableString");
36     public static final ASN1Type T61String = new ASN1Type(20,
37             "T61String");
38     public static final ASN1Type IA5String = new ASN1Type(22,
39             "IA5String");
40     public static final ASN1Type UTCTime = new ASN1Type(23,
41                                            "UTCTime");
42     public static final ASN1Type GENERALIZEDTIME = new ASN1Type(24,
43             "GeneralizedTime");
44     public static final ASN1Type UniversalString = new ASN1Type(28,
45             "UniversalString");
46     public static final ASN1Type BMPString = new ASN1Type(30,
47             "BMPString");
48     public static final ASN1Type SEQUENCE = new ASN1Type(48,
49                                             "SEQUENCE");
50     public static final ASN1Type SET = new ASN1Type(49,
51                                        "SET");
52     public static final ASN1Type ContextSpecific = new ASN1Type(128,
53             "ContextSpecific");
54             
55     /**
56      * Creates and registers a new ASN1Type.
57      * @param t the tag of the ASN1Type
58      * @param n the name of the ASN1Type
59      */

60     public ASN1Type(int t, String JavaDoc n)
61     {
62         tag = t;
63         name = n;
64         asn1Types.put(new Integer JavaDoc(tag), name);
65     }
66     
67     /**
68      * Creates an ASN1Type instance with the given tag 't'.
69      */

70     public ASN1Type(int t)
71     {
72         tag = t;
73         name = asn1Name(t);
74     }
75     
76     /**
77      * Gets the name of the ASN1Type.
78      */

79     public String JavaDoc getName()
80     {
81         return name;
82     }
83     
84     /**
85      * Gets the tag of the ASN1Type.
86      */

87     public int getTag()
88     {
89         return tag;
90     }
91     
92     /**
93      * Gets the hashcode of the ASN1Type.
94      */

95     public int hashCode()
96     {
97         return tag;
98     }
99     
100     /**
101      * Tests whether the given object represents the same ASN.1 type
102      * as this ASN1Type.
103      */

104     public boolean equals(Object JavaDoc o)
105     {
106         if (!(o instanceof ASN1Type))
107         {
108             return false;
109         }
110         ASN1Type a = (ASN1Type) o;
111         if (a.tag == this.tag)
112         {
113             return true;
114         }
115         else
116         {
117             return false;
118         }
119     }
120     
121     /**
122      * Gets the string representation of the ASN1Type.
123      */

124     public String JavaDoc toString()
125     {
126         return "ASN.1 type " + name + " (" + asn1Name(tag) + ") [" +
127                tag + "] ";
128     }
129     
130     /**
131      * Gets the ASN1Type name corresponding to the given tag.
132      */

133     public static String JavaDoc asn1Name(int t)
134     {
135         String JavaDoc n = (String JavaDoc) asn1Types.get(new Integer JavaDoc(t));
136         if (n == null)
137         {
138             return "Unknown";
139         }
140         else
141         {
142             return n;
143         }
144     }
145 }
146
Popular Tags