View Javadoc

1   /*
2    *   Copyright 2005 The Apache Software Foundation
3    *
4    *   Licensed under the Apache License, Version 2.0 (the "License");
5    *   you may not use this file except in compliance with the License.
6    *   You may obtain a copy of the License at
7    *
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *   Unless required by applicable law or agreed to in writing, software
11   *   distributed under the License is distributed on an "AS IS" BASIS,
12   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *   See the License for the specific language governing permissions and
14   *   limitations under the License.
15   *
16   */
17  package org.apache.asn1new.ber.tlv;
18  
19  /***
20   * Enum for ASN.1 UNIVERSAL class tags.  The tags values are
21   * constructed using the SNACC representation for tags without the
22   * primitive/constructed bit.  This is done because several bit, octet and
23   * character string types can be encoded as primitives or as constructed types
24   * to chunk the value out.
25   *
26   * <p>These tags can have one of the following values:</p>
27   *
28   * <p></p>
29   *
30   * <table border="1" cellspacing="1" width="60%">
31   *   <tr>
32   *     <th>Id</th>
33   *     <th>Usage</th>
34   *   </tr>
35   *
36   *   <tr>
37   *     <td>[UNIVERSAL 0]</td>
38   *     <td>reserved for BER</td>
39   *   </tr>
40   *
41   *   <tr>
42   *     <td>[UNIVERSAL 1]</td>
43   *     <td>BOOLEAN</td>
44   *   </tr>
45   *
46   *   <tr>
47   *     <td>[UNIVERSAL 2]</td>
48   *     <td>INTEGER</td>
49   *   </tr>
50   *
51   *   <tr>
52   *     <td>[UNIVERSAL 3]</td>
53   *     <td>BIT STRING</td>
54   *   </tr>
55   *
56   *   <tr>
57   *     <td>[UNIVERSAL 4]</td>
58   *     <td>OCTET STRING</td>
59   *   </tr>
60   *
61   *   <tr>
62   *     <td>[UNIVERSAL 5]</td>
63   *     <td>NULL</td>
64   *   </tr>
65   *
66   *   <tr>
67   *     <td>[UNIVERSAL 6]</td>
68   *     <td>OBJECT IDENTIFIER</td>
69   *   </tr>
70   *
71   *   <tr>
72   *     <td>[UNIVERSAL 7]</td>
73   *     <td>ObjectDescriptor</td>
74   *   </tr>
75   *
76   *   <tr>
77   *     <td>[UNIVERSAL 8]</td>
78   *     <td>EXTERNAL, INSTANCE OF</td>
79   *   </tr>
80   *
81   *   <tr>
82   *     <td>[UNIVERSAL 9]</td>
83   *     <td>REAL</td>
84   *   </tr>
85   *
86   *   <tr>
87   *     <td>[UNIVERSAL 10]</td>
88   *     <td>ENUMERATED</td>
89   *   </tr>
90   *
91   *   <tr>
92   *     <td>[UNIVERSAL 11]</td>
93   *     <td>EMBEDDED PDV</td>
94   *   </tr>
95   *
96   *   <tr>
97   *     <td>[UNIVERSAL 12]</td>
98   *     <td>UTF8String</td>
99   *   </tr>
100  *
101  *   <tr>
102  *     <td>[UNIVERSAL 13]</td>
103  *     <td>RELATIVE-OID</td>
104  *   </tr>
105  *
106  *   <tr>
107  *     <td>[UNIVERSAL 14]</td>
108  *     <td>reserved for future use</td>
109  *   </tr>
110  *
111  *   <tr>
112  *     <td>[UNIVERSAL 15]</td>
113  *     <td>reserved for future use</td>
114  *   </tr>
115  *
116  *   <tr>
117  *     <td>[UNIVERSAL 16]</td>
118  *     <td>SEQUENCE, SEQUENCE OF</td>
119  *   </tr>
120  *
121  *   <tr>
122  *     <td>[UNIVERSAL 17]</td>
123  *     <td>SET, SET OF</td>
124  *   </tr>
125  *
126  *   <tr>
127  *     <td>[UNIVERSAL 18]</td>
128  *     <td>NumericString</td>
129  *   </tr>
130  *
131  *   <tr>
132  *     <td>[UNIVERSAL 19]</td>
133  *     <td>PrintableString</td>
134  *   </tr>
135  *
136  *   <tr>
137  *     <td>[UNIVERSAL 20]</td>
138  *     <td>TeletexString, T61String</td>
139  *   </tr>
140  *
141  *   <tr>
142  *     <td>[UNIVERSAL 21]</td>
143  *     <td>VideotexString</td>
144  *   </tr>
145  *
146  *   <tr>
147  *     <td>[UNIVERSAL 22]</td>
148  *     <td>IA5String</td>
149  *   </tr>
150  *
151  *   <tr>
152  *     <td>[UNIVERSAL 23]</td>
153  *     <td>UTCTime</td>
154  *   </tr>
155  *
156  *   <tr>
157  *     <td>[UNIVERSAL 24]</td>
158  *     <td>GeneralizedTime</td>
159  *   </tr>
160  *
161  *   <tr>
162  *     <td>[UNIVERSAL 25]</td>
163  *     <td>GraphicString</td>
164  *   </tr>
165  *
166  *   <tr>
167  *     <td>[UNIVERSAL 26]</td>
168  *     <td>VisibleString, ISO646String</td>
169  *   </tr>
170  *
171  *   <tr>
172  *     <td>[UNIVERSAL 27]</td>
173  *     <td>GeneralString</td>
174  *   </tr>
175  *
176  *   <tr>
177  *     <td>[UNIVERSAL 28]</td>
178  *     <td>UniversalString</td>
179  *   </tr>
180  *
181  *   <tr>
182  *     <td>[UNIVERSAL 29]</td>
183  *     <td>CHARACTER STRING</td>
184  *   </tr>
185  *
186  *   <tr>
187  *     <td>[UNIVERSAL 30]</td>
188  *     <td>BMPString</td>
189  *   </tr>
190  *
191  *   <tr>
192  *     <td>[UNIVERSAL 31]</td>
193  *     <td>reserved for future use</td>
194  *   </tr>
195  * </table>
196  *
197  * @author   <a href="mailto:dev@directory.apache.org">Apache
198  *           Directory Project</a>
199  */
200 public class UniversalTag
201 {
202     //~ Static fields/initializers -----------------------------------------------------------------
203 
204     /*** value for the tag */
205     public static final int RESERVED_0 = 0;
206 
207     /*** value for the tag */
208     public static final int BOOLEAN = 1;
209 
210     /*** value for the tag */
211     public static final int INTEGER = 2;
212 
213     /*** value for the tag */
214     public static final int BIT_STRING = 3;
215 
216     /*** value for the tag */
217     public static final int OCTET_STRING = 4;
218 
219     /*** value for the tag */
220     public static final int NULL = 5;
221 
222     /*** value for the tag */
223     public static final int OBJECT_IDENTIFIER = 6;
224 
225     /*** value for the tag */
226     public static final int OBJECT_DESCRIPTOR = 7;
227 
228     /*** value for the tag */
229     public static final int EXTERNAL_INSTANCE_OF = 8;
230 
231     /*** value for the tag */
232     public static final int REAL = 9;
233 
234     /*** value for the tag */
235     public static final int ENUMERATED = 10;
236 
237     /*** value for the tag */
238     public static final int EMBEDDED_PDV = 11;
239 
240     /*** value for the tag */
241     public static final int UTF8_STRING = 12;
242 
243     /*** value for the tag */
244     public static final int RELATIVE_OID = 13;
245 
246     /*** value for the tag */
247     public static final int RESERVED_14 = 14;
248 
249     /*** value for the tag */
250     public static final int RESERVED_15 = 15;
251 
252     /*** value for the tag */
253     public static final int SEQUENCE_SEQUENCE_OF = 16;
254 
255     /*** value for the tag */
256     public static final int SET_SET_OF = 17;
257 
258     /*** value for the tag */
259     public static final int NUMERIC_STRING = 18;
260 
261     /*** value for the tag */
262     public static final int PRINTABLE_STRING = 19;
263 
264     /*** value for the tag */
265     public static final int TELETEX_STRING = 20;
266 
267     /*** value for the tag */
268     public static final int VIDEOTEX_STRING = 21;
269 
270     /*** value for the tag */
271     public static final int IA5_STRING = 22;
272 
273     /*** value for the tag */
274     public static final int UTC_TIME = 23;
275 
276     /*** value for the tag */
277     public static final int GENERALIZED_TIME = 24;
278 
279     /*** value for the tag */
280     public static final int GRAPHIC_STRING = 25;
281 
282     /*** value for the tag */
283     public static final int VISIBLE_STRING = 26;
284 
285     /*** value for the tag */
286     public static final int GENERAL_STRING = 27;
287 
288     /*** value for the tag */
289     public static final int UNIVERSAL_STRING = 28;
290 
291     /*** value for the tag */
292     public static final int CHARACTER_STRING = 29;
293 
294     /*** value for the tag */
295     public static final int BMP_STRING = 30;
296 
297     /*** value for the tag */
298     public static final int       RESERVED_31          = 31;
299 
300     /*** String representation of the tags */
301     private static final String[] UNIVERSAL_TAG_STRING =
302     {
303         "RESERVED_0", 
304 		"BOOLEAN", 
305 		"INTEGER", 
306 		"BIT_STRING", 
307 		"OCTET_STRING", 
308 		"NULL",
309         "OBJECT_IDENTIFIER", 
310 		"OBJECT_DESCRIPTOR", 
311 		"EXTERNAL_INSTANCE_OF", 
312 		"REAL", 
313 		"ENUMERATED",
314         "EMBEDDED_PDV", 
315 		"UTF8_STRING", 
316 		"RELATIVE_OID", 
317 		"RESERVED_14", 
318 		"RESERVED_15",
319         "SEQUENCE_SEQUENCE_OF", 
320 		"SET_SET_OF", 
321 		"NUMERIC_STRING", 
322 		"PRINTABLE_STRING",
323         "TELETEX_STRING", 
324 		"VIDEOTEX_STRING", 
325 		"IA5_STRING", 
326 		"UTC_TIME", 
327 		"GENERALIZED_TIME",
328         "GRAPHIC_STRING", 
329 		"VISIBLE_STRING", 
330 		"GENERAL_STRING", 
331 		"UNIVERSAL_STRING",
332         "CHARACTER_STRING", 
333 		"BMP_STRING", 
334 		"RESERVED_31"
335     };
336 
337     /*** ASN.1 primitive tag values */
338     public static final byte BOOLEAN_TAG      = 0x01;
339     public static final byte INTEGER_TAG      = 0x02;
340 
341     public static final byte OCTET_STRING_TAG = 0x04;
342     
343     public static final byte ENUMERATED_TAG   = 0x0A;
344     
345     public static final byte SEQUENCE_TAG     = 0x30;
346     public static final byte SET_TAG          = 0x31;
347 
348     //~ Methods ------------------------------------------------------------------------------------
349 
350     // -----------------------------------------------------------------------
351     // Members
352     // -----------------------------------------------------------------------
353     /***
354      * Gets the ASN.1 UNIVERSAL type tag's enum using a tag value.
355      *
356      * @param   tag  the first octet of the TLV
357      *
358      * @return  the valued enum for the ASN.1 UNIVERSAL type tag
359      */
360     public static String toString( int tag )
361     {
362         return UNIVERSAL_TAG_STRING[tag & 0x1F];
363     }
364 } // end class UniversalTag