1178825Sdfr/* 2233294Sstas * Copyright (c) 1997 - 2005 Kungliga Tekniska H��gskolan 3233294Sstas * (Royal Institute of Technology, Stockholm, Sweden). 4233294Sstas * All rights reserved. 5178825Sdfr * 6233294Sstas * Redistribution and use in source and binary forms, with or without 7233294Sstas * modification, are permitted provided that the following conditions 8233294Sstas * are met: 9178825Sdfr * 10233294Sstas * 1. Redistributions of source code must retain the above copyright 11233294Sstas * notice, this list of conditions and the following disclaimer. 12178825Sdfr * 13233294Sstas * 2. Redistributions in binary form must reproduce the above copyright 14233294Sstas * notice, this list of conditions and the following disclaimer in the 15233294Sstas * documentation and/or other materials provided with the distribution. 16178825Sdfr * 17233294Sstas * 3. Neither the name of the Institute nor the names of its contributors 18233294Sstas * may be used to endorse or promote products derived from this software 19233294Sstas * without specific prior written permission. 20178825Sdfr * 21233294Sstas * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 22233294Sstas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23233294Sstas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24233294Sstas * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 25233294Sstas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26233294Sstas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27233294Sstas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28233294Sstas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29233294Sstas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30233294Sstas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31233294Sstas * SUCH DAMAGE. 32178825Sdfr */ 33178825Sdfr 34178825Sdfr#include "der_locl.h" 35178825Sdfr#include <com_err.h> 36178825Sdfr#include <sys/types.h> 37178825Sdfr#include <sys/stat.h> 38178825Sdfr#include <getarg.h> 39178825Sdfr#include <err.h> 40178825Sdfr 41233294SstasRCSID("$Id$"); 42178825Sdfr 43178825Sdfr 44178825Sdfrstatic const char *class_names[] = { 45178825Sdfr "UNIV", /* 0 */ 46178825Sdfr "APPL", /* 1 */ 47178825Sdfr "CONTEXT", /* 2 */ 48178825Sdfr "PRIVATE" /* 3 */ 49178825Sdfr}; 50178825Sdfr 51178825Sdfrstatic const char *type_names[] = { 52178825Sdfr "PRIM", /* 0 */ 53178825Sdfr "CONS" /* 1 */ 54178825Sdfr}; 55178825Sdfr 56178825Sdfrstatic const char *tag_names[] = { 57178825Sdfr "EndOfContent", /* 0 */ 58178825Sdfr "Boolean", /* 1 */ 59178825Sdfr "Integer", /* 2 */ 60178825Sdfr "BitString", /* 3 */ 61178825Sdfr "OctetString", /* 4 */ 62178825Sdfr "Null", /* 5 */ 63178825Sdfr "ObjectID", /* 6 */ 64178825Sdfr NULL, /* 7 */ 65178825Sdfr NULL, /* 8 */ 66178825Sdfr NULL, /* 9 */ 67178825Sdfr "Enumerated", /* 10 */ 68178825Sdfr NULL, /* 11 */ 69178825Sdfr NULL, /* 12 */ 70178825Sdfr NULL, /* 13 */ 71178825Sdfr NULL, /* 14 */ 72178825Sdfr NULL, /* 15 */ 73178825Sdfr "Sequence", /* 16 */ 74178825Sdfr "Set", /* 17 */ 75178825Sdfr NULL, /* 18 */ 76178825Sdfr "PrintableString", /* 19 */ 77178825Sdfr NULL, /* 20 */ 78178825Sdfr NULL, /* 21 */ 79178825Sdfr "IA5String", /* 22 */ 80178825Sdfr "UTCTime", /* 23 */ 81178825Sdfr "GeneralizedTime", /* 24 */ 82178825Sdfr NULL, /* 25 */ 83178825Sdfr "VisibleString", /* 26 */ 84178825Sdfr "GeneralString", /* 27 */ 85178825Sdfr NULL, /* 28 */ 86178825Sdfr NULL, /* 29 */ 87178825Sdfr "BMPString" /* 30 */ 88178825Sdfr}; 89178825Sdfr 90178825Sdfrstatic int 91178825Sdfrget_type(const char *name, const char *list[], unsigned len) 92178825Sdfr{ 93178825Sdfr unsigned i; 94178825Sdfr for (i = 0; i < len; i++) 95178825Sdfr if (list[i] && strcasecmp(list[i], name) == 0) 96178825Sdfr return i; 97178825Sdfr return -1; 98178825Sdfr} 99178825Sdfr 100178825Sdfr#define SIZEOF_ARRAY(a) (sizeof((a))/sizeof((a)[0])) 101178825Sdfr 102178825Sdfrconst char * 103178825Sdfrder_get_class_name(unsigned num) 104178825Sdfr{ 105178825Sdfr if (num >= SIZEOF_ARRAY(class_names)) 106178825Sdfr return NULL; 107178825Sdfr return class_names[num]; 108178825Sdfr} 109178825Sdfr 110178825Sdfrint 111178825Sdfrder_get_class_num(const char *name) 112178825Sdfr{ 113178825Sdfr return get_type(name, class_names, SIZEOF_ARRAY(class_names)); 114178825Sdfr} 115178825Sdfr 116178825Sdfrconst char * 117178825Sdfrder_get_type_name(unsigned num) 118178825Sdfr{ 119178825Sdfr if (num >= SIZEOF_ARRAY(type_names)) 120178825Sdfr return NULL; 121178825Sdfr return type_names[num]; 122178825Sdfr} 123178825Sdfr 124178825Sdfrint 125178825Sdfrder_get_type_num(const char *name) 126178825Sdfr{ 127178825Sdfr return get_type(name, type_names, SIZEOF_ARRAY(type_names)); 128178825Sdfr} 129178825Sdfr 130178825Sdfrconst char * 131178825Sdfrder_get_tag_name(unsigned num) 132178825Sdfr{ 133178825Sdfr if (num >= SIZEOF_ARRAY(tag_names)) 134178825Sdfr return NULL; 135178825Sdfr return tag_names[num]; 136178825Sdfr} 137178825Sdfr 138178825Sdfrint 139178825Sdfrder_get_tag_num(const char *name) 140178825Sdfr{ 141178825Sdfr return get_type(name, tag_names, SIZEOF_ARRAY(tag_names)); 142178825Sdfr} 143