libisdn
asn1_types.c
Go to the documentation of this file.
00001 /*
00002  *
00003  */
00004 #ifdef HAVE_CONFIG_H
00005 #include "config.h"
00006 #endif
00007 
00008 #include <stdio.h>
00009 
00010 #include "asn1.h"
00011 #include "asn1_common.h"
00012 #include "asn1_types.h"
00013 
00014 static const struct asn1_class {
00015         const int   id;
00016         const char *name;
00017 } asn1_classes[] = {
00018         { ASN1_CLASS_UNIVERSAL,   "universal"            },
00019         { ASN1_CLASS_APPLICATION, "application specific" },
00020         { ASN1_CLASS_CONTEXT,     "context specific"     },
00021         { ASN1_CLASS_PRIVATE,     "private"              }
00022 };
00023 
00024 const char *asn1_class_name(const asn1_class_t id)
00025 {
00026         if (id < 0 || id > ASN1_CLASS_PRIVATE)
00027                 return "invalid";
00028 
00029         return asn1_classes[id].name;
00030 }
00031 
00032 static const struct asn1_type {
00033         const int   id;
00034         const char *name;
00035 } asn1_types[] = {
00036         { ASN1_TYPE_EOC,              "EOC"                },
00037         { ASN1_TYPE_BOOLEAN,          "boolean"            },
00038         { ASN1_TYPE_INTEGER,          "Integer"            },
00039         { ASN1_TYPE_BIT_STRING,       "Bit string"         },
00040         { ASN1_TYPE_OCTET_STRING,     "Octet string"       },
00041         { ASN1_TYPE_NULL,             "Null"               },
00042         { ASN1_TYPE_OID,              "OID"                },
00043         { ASN1_TYPE_OBJECTDESC,       "Object description" },
00044         { ASN1_TYPE_EXTERNAL,         "External"           },
00045         { ASN1_TYPE_REAL,             "Real"               },
00046         { ASN1_TYPE_ENUMERATED,       "Enumerated"         },
00047         { ASN1_TYPE_EMBEDDED_PDV,     "Embedded PDV"       },
00048         { ASN1_TYPE_UTF8_STRING,      "UTF8 string"        },
00049         { ASN1_TYPE_RELATIVE_OID,     "Relative OID"       },
00050         { ASN1_TYPE_SEQUENCE,         "Sequence"           },
00051         { ASN1_TYPE_SET,              "Set"                },
00052         { ASN1_TYPE_NUMERIC_STRING,   "Numeric string"     },
00053         { ASN1_TYPE_PRINTABLE_STRING, "Printable string"   },
00054         { ASN1_TYPE_T61_STRING,       "T61 string"         },
00055         { ASN1_TYPE_VIDEOTEX_STRING,  "Videotex string"    },
00056         { ASN1_TYPE_IA5_STRING,       "IA5 string"         },
00057         { ASN1_TYPE_UTC_TIME,         "UTC time"           },
00058         { ASN1_TYPE_GENERALIZED_TIME, "Generalized time"   },
00059         { ASN1_TYPE_GRAPHIC_STRING,   "Graphic string"     },
00060         { ASN1_TYPE_VISIBLE_STRING,   "Visible string"     },
00061         { ASN1_TYPE_GENERAL_STRING,   "General string"     },
00062         { ASN1_TYPE_UNIVERSAL_STRING, "Universal string"   },
00063         { ASN1_TYPE_CHARACTER_STRING, "Character string"   },
00064         { ASN1_TYPE_BMP_STRING,       "BMP string"         }
00065 };
00066 
00067 const char *asn1_type_name(const asn1_type_t id)
00068 {
00069         int x;
00070 
00071         if (id < 0 || id > ASN1_TYPE_BMP_STRING)
00072                 return "invalid";
00073 
00074         for (x = 0; x < ARRAY_SIZE(asn1_types); x++) {
00075                 if (asn1_types[x].id == id) {
00076                         return asn1_types[x].name;
00077                 }
00078         }
00079         return "unknown";
00080 }
00081 
00082 int asn1_get_class(const struct asn1_object *elem)
00083 {
00084         return elem->hdr.asn_class;
00085 }
00086 
00087 int asn1_get_type(const struct asn1_object *elem)
00088 {
00089         return elem->hdr.asn_type;
00090 }
00091 
00092 int asn1_get_size(const struct asn1_object *elem)
00093 {
00094         return elem->hdr.size;
00095 }
00096 
00097 int asn1_eq_class(const struct asn1_object *elem, const asn1_class_t asn_class)
00098 {
00099         return (elem->hdr.asn_class == asn_class);
00100 }
00101 
00102 int asn1_eq_type(const struct asn1_object *elem, const asn1_type_t asn_type)
00103 {
00104         return (elem->hdr.asn_type == asn_type);
00105 }