001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020 package org.apache.directory.shared.asn1.ber.tlv; 021 022 023 /** 024 * Enum for ASN.1 UNIVERSAL class tags. The tags values are constructed using 025 * the SNACC representation for tags without the primitive/constructed bit. This 026 * is done because several bit, octet and character string types can be encoded 027 * as primitives or as constructed types to chunk the value out. 028 * <p> 029 * These tags can have one of the following values: 030 * </p> 031 * <p> 032 * </p> 033 * <table border="1" cellspacing="1" width="60%"> 034 * <tr> 035 * <th>Id</th> 036 * <th>Usage</th> 037 * </tr> 038 * <tr> 039 * <td>[UNIVERSAL 0]</td> 040 * <td>reserved for BER</td> 041 * </tr> 042 * <tr> 043 * <td>[UNIVERSAL 1]</td> 044 * <td>BOOLEAN</td> 045 * </tr> 046 * <tr> 047 * <td>[UNIVERSAL 2]</td> 048 * <td>INTEGER</td> 049 * </tr> 050 * <tr> 051 * <td>[UNIVERSAL 3]</td> 052 * <td>BIT STRING</td> 053 * </tr> 054 * <tr> 055 * <td>[UNIVERSAL 4]</td> 056 * <td>OCTET STRING</td> 057 * </tr> 058 * <tr> 059 * <td>[UNIVERSAL 5]</td> 060 * <td>NULL</td> 061 * </tr> 062 * <tr> 063 * <td>[UNIVERSAL 6]</td> 064 * <td>OBJECT IDENTIFIER</td> 065 * </tr> 066 * <tr> 067 * <td>[UNIVERSAL 7]</td> 068 * <td>ObjectDescriptor</td> 069 * </tr> 070 * <tr> 071 * <td>[UNIVERSAL 8]</td> 072 * <td>EXTERNAL, INSTANCE OF</td> 073 * </tr> 074 * <tr> 075 * <td>[UNIVERSAL 9]</td> 076 * <td>REAL</td> 077 * </tr> 078 * <tr> 079 * <td>[UNIVERSAL 10]</td> 080 * <td>ENUMERATED</td> 081 * </tr> 082 * <tr> 083 * <td>[UNIVERSAL 11]</td> 084 * <td>EMBEDDED PDV</td> 085 * </tr> 086 * <tr> 087 * <td>[UNIVERSAL 12]</td> 088 * <td>UTF8String</td> 089 * </tr> 090 * <tr> 091 * <td>[UNIVERSAL 13]</td> 092 * <td>RELATIVE-OID</td> 093 * </tr> 094 * <tr> 095 * <td>[UNIVERSAL 14]</td> 096 * <td>reserved for future use</td> 097 * </tr> 098 * <tr> 099 * <td>[UNIVERSAL 15]</td> 100 * <td>reserved for future use</td> 101 * </tr> 102 * <tr> 103 * <td>[UNIVERSAL 16]</td> 104 * <td>SEQUENCE, SEQUENCE OF</td> 105 * </tr> 106 * <tr> 107 * <td>[UNIVERSAL 17]</td> 108 * <td>SET, SET OF</td> 109 * </tr> 110 * <tr> 111 * <td>[UNIVERSAL 18]</td> 112 * <td>NumericString</td> 113 * </tr> 114 * <tr> 115 * <td>[UNIVERSAL 19]</td> 116 * <td>PrintableString</td> 117 * </tr> 118 * <tr> 119 * <td>[UNIVERSAL 20]</td> 120 * <td>TeletexString, T61String</td> 121 * </tr> 122 * <tr> 123 * <td>[UNIVERSAL 21]</td> 124 * <td>VideotexString</td> 125 * </tr> 126 * <tr> 127 * <td>[UNIVERSAL 22]</td> 128 * <td>IA5String</td> 129 * </tr> 130 * <tr> 131 * <td>[UNIVERSAL 23]</td> 132 * <td>UTCTime</td> 133 * </tr> 134 * <tr> 135 * <td>[UNIVERSAL 24]</td> 136 * <td>GeneralizedTime</td> 137 * </tr> 138 * <tr> 139 * <td>[UNIVERSAL 25]</td> 140 * <td>GraphicString</td> 141 * </tr> 142 * <tr> 143 * <td>[UNIVERSAL 26]</td> 144 * <td>VisibleString, ISO646String</td> 145 * </tr> 146 * <tr> 147 * <td>[UNIVERSAL 27]</td> 148 * <td>GeneralString</td> 149 * </tr> 150 * <tr> 151 * <td>[UNIVERSAL 28]</td> 152 * <td>UniversalString</td> 153 * </tr> 154 * <tr> 155 * <td>[UNIVERSAL 29]</td> 156 * <td>CHARACTER STRING</td> 157 * </tr> 158 * <tr> 159 * <td>[UNIVERSAL 30]</td> 160 * <td>BMPString</td> 161 * </tr> 162 * <tr> 163 * <td>[UNIVERSAL 31]</td> 164 * <td>reserved for future use</td> 165 * </tr> 166 * </table> 167 * 168 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 169 * @version $Rev: 664290 $, $Date: 2008-06-07 08:28:06 +0200 (Sat, 07 Jun 2008) $ 170 */ 171 public class UniversalTag 172 { 173 // ~ Static fields/initializers 174 // ----------------------------------------------------------------- 175 176 /** value for the tag */ 177 public static final int RESERVED_0 = 0; 178 179 /** value for the tag */ 180 public static final int BOOLEAN = 1; 181 182 /** value for the tag */ 183 public static final int INTEGER = 2; 184 185 /** value for the tag */ 186 public static final int BIT_STRING = 3; 187 188 /** value for the tag */ 189 public static final int OCTET_STRING = 4; 190 191 /** value for the tag */ 192 public static final int NULL = 5; 193 194 /** value for the tag */ 195 public static final int OBJECT_IDENTIFIER = 6; 196 197 /** value for the tag */ 198 public static final int OBJECT_DESCRIPTOR = 7; 199 200 /** value for the tag */ 201 public static final int EXTERNAL_INSTANCE_OF = 8; 202 203 /** value for the tag */ 204 public static final int REAL = 9; 205 206 /** value for the tag */ 207 public static final int ENUMERATED = 10; 208 209 /** value for the tag */ 210 public static final int EMBEDDED_PDV = 11; 211 212 /** value for the tag */ 213 public static final int UTF8_STRING = 12; 214 215 /** value for the tag */ 216 public static final int RELATIVE_OID = 13; 217 218 /** value for the tag */ 219 public static final int RESERVED_14 = 14; 220 221 /** value for the tag */ 222 public static final int RESERVED_15 = 15; 223 224 /** value for the tag */ 225 public static final int SEQUENCE_SEQUENCE_OF = 16; 226 227 /** value for the tag */ 228 public static final int SET_SET_OF = 17; 229 230 /** value for the tag */ 231 public static final int NUMERIC_STRING = 18; 232 233 /** value for the tag */ 234 public static final int PRINTABLE_STRING = 19; 235 236 /** value for the tag */ 237 public static final int TELETEX_STRING = 20; 238 239 /** value for the tag */ 240 public static final int VIDEOTEX_STRING = 21; 241 242 /** value for the tag */ 243 public static final int IA5_STRING = 22; 244 245 /** value for the tag */ 246 public static final int UTC_TIME = 23; 247 248 /** value for the tag */ 249 public static final int GENERALIZED_TIME = 24; 250 251 /** value for the tag */ 252 public static final int GRAPHIC_STRING = 25; 253 254 /** value for the tag */ 255 public static final int VISIBLE_STRING = 26; 256 257 /** value for the tag */ 258 public static final int GENERAL_STRING = 27; 259 260 /** value for the tag */ 261 public static final int UNIVERSAL_STRING = 28; 262 263 /** value for the tag */ 264 public static final int CHARACTER_STRING = 29; 265 266 /** value for the tag */ 267 public static final int BMP_STRING = 30; 268 269 /** value for the tag */ 270 public static final int RESERVED_31 = 31; 271 272 /** String representation of the tags */ 273 private static final String[] UNIVERSAL_TAG_STRING = 274 { 275 "RESERVED_0", 276 "BOOLEAN", 277 "INTEGER", 278 "BIT_STRING", 279 "OCTET_STRING", 280 "NULL", 281 "OBJECT_IDENTIFIER", 282 "OBJECT_DESCRIPTOR", 283 "EXTERNAL_INSTANCE_OF", 284 "REAL", 285 "ENUMERATED", 286 "EMBEDDED_PDV", 287 "UTF8_STRING", 288 "RELATIVE_OID", 289 "RESERVED_14", 290 "RESERVED_15", 291 "SEQUENCE_SEQUENCE_OF", 292 "SET_SET_OF", 293 "NUMERIC_STRING", 294 "PRINTABLE_STRING", 295 "TELETEX_STRING", 296 "VIDEOTEX_STRING", 297 "IA5_STRING", 298 "UTC_TIME", 299 "GENERALIZED_TIME", 300 "GRAPHIC_STRING", 301 "VISIBLE_STRING", 302 "GENERAL_STRING", 303 "UNIVERSAL_STRING", 304 "CHARACTER_STRING", 305 "BMP_STRING", 306 "RESERVED_31" 307 }; 308 309 /** ASN.1 primitive tag values */ 310 /** Boolean TAG */ 311 public static final byte BOOLEAN_TAG = 0x01; 312 313 /** Integer TAG */ 314 public static final byte INTEGER_TAG = 0x02; 315 316 /** BIT_STRING TAG */ 317 public static final byte BIT_STRING_TAG = 0x03; 318 319 /** OCTET_STRING TAG */ 320 public static final byte OCTET_STRING_TAG = 0x04; 321 322 /** ENUMERATED TAG */ 323 public static final byte ENUMERATED_TAG = 0x0A; 324 325 /** UTF8_STRING TAG */ 326 public static final byte UTF8_STRING_TAG = 0x0C; 327 328 /** GENERALIZED_TIME TAG */ 329 public static final byte GENERALIZED_TIME_TAG = 0x18; 330 331 /** GENERALIZED_STRING TAG */ 332 public static final byte GENERALIZED_STRING_TAG = 0x1B; 333 334 /** SEQUENCE TAG */ 335 public static final byte SEQUENCE_TAG = 0x30; 336 337 /** SET TAG */ 338 public static final byte SET_TAG = 0x31; 339 340 341 // ~ Methods 342 // ------------------------------------------------------------------------------------ 343 344 // ----------------------------------------------------------------------- 345 // Members 346 // ----------------------------------------------------------------------- 347 /** 348 * Gets the ASN.1 UNIVERSAL type tag's enum using a tag value. 349 * 350 * @param tag 351 * the first octet of the TLV 352 * @return the valued enum for the ASN.1 UNIVERSAL type tag 353 */ 354 public static String toString( int tag ) 355 { 356 return UNIVERSAL_TAG_STRING[tag & 0x1F]; 357 } 358 } // end class UniversalTag