/*1* Copyright (c) 1997 - 2005 Kungliga Tekniska Högskolan2* (Royal Institute of Technology, Stockholm, Sweden).3* All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8*9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11*12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15*16* 3. Neither the name of the Institute nor the names of its contributors17* may be used to endorse or promote products derived from this software18* without specific prior written permission.19*20* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND21* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE22* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE23* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE24* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL25* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS26* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)27* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT28* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY29* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF30* SUCH DAMAGE.31*/3233#include "der_locl.h"34#include <com_err.h>35#include <sys/types.h>36#include <sys/stat.h>37#include <getarg.h>38#include <err.h>3940RCSID("$Id$");414243static const char *class_names[] = {44"UNIV", /* 0 */45"APPL", /* 1 */46"CONTEXT", /* 2 */47"PRIVATE" /* 3 */48};4950static const char *type_names[] = {51"PRIM", /* 0 */52"CONS" /* 1 */53};5455static const char *tag_names[] = {56"EndOfContent", /* 0 */57"Boolean", /* 1 */58"Integer", /* 2 */59"BitString", /* 3 */60"OctetString", /* 4 */61"Null", /* 5 */62"ObjectID", /* 6 */63NULL, /* 7 */64NULL, /* 8 */65NULL, /* 9 */66"Enumerated", /* 10 */67NULL, /* 11 */68NULL, /* 12 */69NULL, /* 13 */70NULL, /* 14 */71NULL, /* 15 */72"Sequence", /* 16 */73"Set", /* 17 */74NULL, /* 18 */75"PrintableString", /* 19 */76NULL, /* 20 */77NULL, /* 21 */78"IA5String", /* 22 */79"UTCTime", /* 23 */80"GeneralizedTime", /* 24 */81NULL, /* 25 */82"VisibleString", /* 26 */83"GeneralString", /* 27 */84NULL, /* 28 */85NULL, /* 29 */86"BMPString" /* 30 */87};8889static int90get_type(const char *name, const char *list[], unsigned len)91{92unsigned i;93for (i = 0; i < len; i++)94if (list[i] && strcasecmp(list[i], name) == 0)95return i;96return -1;97}9899#define SIZEOF_ARRAY(a) (sizeof((a))/sizeof((a)[0]))100101const char *102der_get_class_name(unsigned num)103{104if (num >= SIZEOF_ARRAY(class_names))105return NULL;106return class_names[num];107}108109int110der_get_class_num(const char *name)111{112return get_type(name, class_names, SIZEOF_ARRAY(class_names));113}114115const char *116der_get_type_name(unsigned num)117{118if (num >= SIZEOF_ARRAY(type_names))119return NULL;120return type_names[num];121}122123int124der_get_type_num(const char *name)125{126return get_type(name, type_names, SIZEOF_ARRAY(type_names));127}128129const char *130der_get_tag_name(unsigned num)131{132if (num >= SIZEOF_ARRAY(tag_names))133return NULL;134return tag_names[num];135}136137int138der_get_tag_num(const char *name)139{140return get_type(name, tag_names, SIZEOF_ARRAY(tag_names));141}142143144