ASN1_TYPE_set() -- SSLeay 0.9.0b -- January 1999

NAME

ASN1_TYPE_set, ASN1_TYPE_set_octetstring, ASN1_TYPE_get_octetstring,
ASN1_TYPE_set_int_octetstring, ASN1_TYPE_get_int_octetstring -- ASN1_TYPE manipulation routines

SYNOPSIS

#include "asn1.h"

void ASN1_TYPE_set(a,type,value)
ASN1_TYPE *a;
int type;
char *value;

int ASN1_TYPE_set_octetstring(a, data, len)
ASN1_TYPE *a;
unsigned char *data;
int len;

int ASN1_TYPE_get_octetstring(a, data, max_len)
ASN1_TYPE *a;
unsigned char *data;
int max_len;

int ASN1_TYPE_set_int_octetstring(a, num, data, len)
ASN1_TYPE *a;
long num;
unsigned char *data;
int len;

int ASN1_TYPE_get_int_octetstring(a, num, data, max_len)
ASN1_TYPE *a;
long *num;
unsigned char *data;
int max_len;

DESCRIPTION

These functions all operate on an ASN1_TYPE structure; see ASN1 types and structures for a definition of this structure.

ASN1_TYPE_set sets the type subfield of a to type, which must be one of

V_ASN1_EOC
V_ASN1_BOOLEAN
V_ASN1_INTEGER
V_ASN1_NEG_INTEGER
V_ASN1_BIT_STRING
V_ASN1_OCTET_STRING
V_ASN1_NULL
V_ASN1_OBJECT
V_ASN1_OBJECT_DESCRIPTOR
V_ASN1_EXTERNAL
V_ASN1_REAL
V_ASN1_ENUMERATED
V_ASN1_SEQUENCE
V_ASN1_SET
V_ASN1_NUMERICSTRING
V_ASN1_PRINTABLESTRING
V_ASN1_T61STRING         (or V_ASN1_TELETEXSTRING)
V_ASN1_VIDEOTEXSTRING
V_ASN1_IA5STRING
V_ASN1_UTCTIME
V_ASN1_GENERALIZEDTIME
V_ASN1_GRAPHICSTRING
V_ASN1_ISO64STRING       (or V_ASN1_VISIBLESTRING)
V_ASN1_GENERALSTRING
V_ASN1_UNIVERSALSTRING
V_ASN1_BMPSTRING

and sets the value.ptr subfield to value (after possibly freeing the value.ptr subfield; if you don't want that freed because some other part of your code is still using the contents with some other name, set a->value.ptr to NULL before calling this function). Remember that ASN1_TYPE is basically just a wrapper for the real ASN1 structure, which is referenced by a->value; so a typical use of this function is as in ASN1_TYPE_set_octetstring (see below) which does:

ASN1_STRING *os;

if ((os=ASN1_OCTET_STRING_new()) == NULL) return(0);
if (!ASN1_OCTET_STRING_set(os,data,len)) return(0);
ASN1_TYPE_set(a,V_ASN1_OCTET_STRING,(char *)os);

ASN1_TYPE_set_octetstring creates an ASN1_OCTETSTRING, sets it with dataand len passed, and then sets the ASN1_TYPE a with the new octet string and the V_ASN1_OCTET_STRING type.

ASN1_TYPE_get_octetstring copies up to max_len bytes from the octet string subfield of a into data; if data is longer than max_len, the extra bytes will be silently omitted. The actual length of bytes copied is returned or -1 on error.

ASN1_TYPE_set_int_octetstring constructs a SEQUENCE OF an ASN1_INTEGER from the value num and an ASN1_OCTET_STRING from len bytes of data and sets a->value to point to this new object. Warning: there is no error checking in case of malloc failure, and this function *always* returns 1 (success).

ASN1_TYPE_get_int_octetstring takes apart a SEQUENCE OF an ASN1_INTEGER and an ASN1_OCTET_STRING from a and returns the integer part in num and the contents of the string in data. If the ASN1_INTEGER is too larg to fit in a long, 0xffffffffL is placed in num instead. If the string contents are longer than max_len, the extra bytes will silently be dropped.

The number of bytes actually copied into data is returned, or 0 on error.