Sortix cross-nightly manual
This manual documents Sortix cross-nightly. You can instead view this document in the latest official manual.
NAME
ASN1_item_d2i, ASN1_item_d2i_bio, ASN1_item_d2i_fp, d2i_ASN1_TYPE, ASN1_item_i2d, ASN1_item_i2d_bio, ASN1_item_i2d_fp, i2d_ASN1_TYPE, ASN1_item_dup, ASN1_item_print — decode and encode ASN.1 objectsSYNOPSIS
#include <openssl/asn1.h>ASN1_item_d2i(ASN1_VALUE **val_out, const unsigned char **der_in, long length, const ASN1_ITEM *it);
ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in_bio, void *val_out);
ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in_fp, void *val_out);
d2i_ASN1_TYPE(ASN1_TYPE **val_out, const unsigned char **der_in, long length);
ASN1_item_i2d(ASN1_VALUE *val_in, unsigned char **der_out, const ASN1_ITEM *it);
ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out_bio, void *val_in);
ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out_fp, void *val_in);
i2d_ASN1_TYPE(ASN1_TYPE *val_in, unsigned char **der_out);
ASN1_item_dup(const ASN1_ITEM *it, void *val_in);
ASN1_item_print(BIO *out_bio, ASN1_VALUE *val_in, int indent, const ASN1_ITEM *it, const ASN1_PCTX *pctx);
DESCRIPTION
These functions convert ASN.1 values from their BER encoding to internal C structures (“d2i”) and vice versa (“i2d”). Unlike the C structures which contain pointers to sub-objects, BER is a serialized encoding, suitable for transfer over the network and for storage in a file.RETURN VALUES
If successful, ASN1_item_d2i(), ASN1_item_d2i_bio(), ASN1_item_d2i_fp(), and d2i_ASN1_TYPE() return a pointer to the decoded ASN.1 value. In addition, if val_out is not NULL, the pointer is also written to *val_out. If an error occurs, NULL is returned.EXAMPLES
Many type-specific wrapper functions exist. Using those wrappers is recommended in application code because it restores part of the type safety that the low-level interfaces using ASN1_VALUE lack.X509 *x; unsigned char *buf; int len; buf = NULL; len = i2d_X509(x, &buf); if (len < 0) /* error */
X509 *x; unsigned char *buf; const unsigned char *p; int len; /* Set up buf and len to point to the input buffer. */ p = buf; x = d2i_X509(NULL, &p, len); if (x == NULL) /* error */
X509 *x; unsigned char *buf; const unsigned char *p; int len; /* Set up buf and len to point to the input buffer. */ p = buf; x = NULL; if (d2i_X509(&x, &p, len) == NULL) /* error */
SEE ALSO
ASN1_get_object(3), ASN1_item_digest(3), ASN1_item_new(3), ASN1_item_pack(3), ASN1_item_sign(3), ASN1_item_verify(3), ASN1_TYPE_new(3)HISTORY
d2i_ASN1_TYPE() and i2d_ASN1_TYPE() first appeared in SSLeay 0.5.1 and have been available since OpenBSD 2.4.CAVEATS
If the type described by it fails to match the true type of val_in or *val_out, buffer overflows and segmentation faults are likely to occur. For more details about why the type ASN1_VALUE constitutes dangerous user interface design, see ASN1_item_new(3).X509 *x; unsigned char *buf; int len; len = i2d_X509(x, NULL); buf = malloc(len); i2d_X509(x, &buf); /* do something with buf[] */ free(buf);
X509 *x; if (d2i_X509(&x, &p, len) == NULL) /* error */