ASN1 types and structures -- SSLeay 0.9.0b -- January 1999

NAME

ASN1 types and structures

SYNOPSIS

#include "asn1.h"

DESCRIPTION

The following structures are used to manipulate ASN1 types and objects.

ASN1_CTX, used for keeping track of various things during ASN1 manipulations:

typedef struct asn1_ctx_st
        {
        unsigned char *p;/* work char pointer */
        int eos;        /* end of sequence read for indefinite encoding */
        int error;      /* error code to use when returning an error */
        int inf;        /* constructed if 0x20, indefinite is 0x21 */
        int tag;        /* tag from last 'get object' */
        int xclass;     /* class from last 'get object' */
        long slen;      /* length of last 'get object' */
        unsigned char *max; /* largest value of p alowed */
        unsigned char *q;/* temporary variable */
        unsigned char **pp;/* variable */
        } ASN1_CTX;

ASN1_OBJECT, used to hold an ASN1 OBJECT. The nid is a unique internal numeric identifier asssigned to every object. sn and ln designate the short name and long or lower case name of the object, respectively. See ASN1 Object names and nids for these. length and data will be filled in by the appropriate ASN1 routine with the object data and the length of that data.

typedef struct asn1_object_st
        {
        char *sn,*ln;
        int nid;
        int length;
        unsigned char *data;
        int flags;      /* Should we free this one */
        } ASN1_OBJECT;

ASN1_STRING, the real internal structure underlying the types ASN1_INTEGER, ASN1_BIT_STRING, ASN1_OCTET_STRING, ASN1_PRINTABLESTRING, ASN1_T61STRING, ASN1_IA5STRING, ASN1_UTCTIME, ASN1_GENERALIZEDTIME, ASN1_GENERALSTRING, ASN1_UNIVERSALSTRING, and ASN1_BMPSTRING

typedef struct asn1_string_st
        {
        int length;
        int type;
        unsigned char *data;
        } ASN1_STRING;

ASN1_TYPE:

This structure is used in a few places when ASN.1 type ANY can be expected.

typedef struct asn1_type_st
        {
        int type;
        union   {
                char *ptr;
                ASN1_STRING *           asn1_string;
                ASN1_OBJECT *           object;
                ASN1_INTEGER *          integer;
                ASN1_BIT_STRING *       bit_string;
                ASN1_OCTET_STRING *     octet_string;
                ASN1_PRINTABLESTRING *  printablestring;
                ASN1_T61STRING *        t61string;
                ASN1_IA5STRING *        ia5string;
                ASN1_GENERALSTRING *    generalstring;
                ASN1_BMPSTRING *        bmpstring;
                ASN1_UNIVERSALSTRING *  universalstring;
                ASN1_UTCTIME *          utctime;
                ASN1_GENERALIZEDTIME *  generalizedtime;
                /* set and sequence are left complete and still
                 * contain the set or sequence bytes */
                ASN1_STRING *           set;
                ASN1_STRING *           sequence;
        } ASN1_TYPE;

ASN1_METHOD, which contains pointers to the routines that convert to and from DER encoded format, and the routines that allocate new memory for a new structure or free it:

typedef struct asn1_method_st
        {
        int (*i2d)();
        char *(*d2i)();
        char *(*create)();
        void (*destroy)();
        } ASN1_METHOD;

For example, in x_x509.c, the METHOD for X509 objects is set up as follows:

static ASN1_METHOD meth={
        (int (*)())  i2d_X509,
        (char *(*)())d2i_X509,
        (char *(*)())X509_new,
        (void (*)()) X509_free};

ASN1_METHOD *X509_asn1_meth()
        {
        return(&meth);
        }

ASN1_HEADER -- someone want to tell me what we use this for? So far I only see it used when we have to deal with Netscape-formatted certificates (see apps/x509.c):

typedef struct asn1_header_st
        {
        ASN1_OCTET_STRING *header;
        char *data;
        ASN1_METHOD *meth;
        } ASN1_HEADER;