d2i_X509(3) | LibreSSL | d2i_X509(3) |
NAME
d2i_X509, i2d_X509, d2i_X509_bio, d2i_X509_fp, i2d_X509_bio, i2d_X509_fp - X509 encode and decode functionsSYNOPSIS
#include <openssl/x509.h>
X509 *d2i_X509(X509 **px, const unsigned char **in, int len);
int i2d_X509(X509 *x, unsigned char **out);
X509 *d2i_X509_bio(BIO *bp, X509 **x);
X509 *d2i_X509_fp(FILE *fp, X509 **x);
int i2d_X509_bio(BIO *bp, X509 *x);
int i2d_X509_fp(FILE *fp, X509 *x);
DESCRIPTION
The X509 encode and decode routines encode and parse an X509 structure, which represents an X509 certificate.NOTES
The letters i and d in for example i2d_X509 stand for "internal" (that is an internal C structure) and "DER". So that i2d_X509 converts from internal to DER.EXAMPLES
Allocate and encode the DER encoding of an X509 structure:int len;
unsigned char *buf, *p;
len = i2d_X509(x, NULL);
buf = malloc(len);
if (buf == NULL)
/* error */
p = buf;
i2d_X509(x, &p);
int len;
unsigned char *buf;
buf = NULL;
len = i2d_X509(x, &buf);
if (len < 0)
/* error */
X509 *x;
unsigned char *buf, *p;
int len;
/* Something to setup buf and len */
p = buf;
x = d2i_X509(NULL, &p, len);
if (x == NULL)
/* Some error */
X509 *x;
unsigned char *buf, *p;
int len;
/* Something to setup buf and len */
p = buf;
x = NULL;
if(!d2i_X509(&x, &p, len))
/* Some error */
WARNINGS
The use of temporary variable is mandatory. A common mistake is to attempt to use a buffer directly as follows:int len;
unsigned char *buf;
len = i2d_X509(x, NULL);
buf = malloc(len);
if (buf == NULL)
/* error */
i2d_X509(x, &buf);
/* Other stuff ... */
free(buf);
X509 *x;
if (!d2i_X509(&x, &p, len))
/* Some error */
BUGS
In some versions of OpenSSL the "reuse" behaviour of d2i_X509() when *px is valid is broken and some parts of the reused structure may persist if they are not present in the new one. As a result the use of this "reuse" behaviour is strongly discouraged.RETURN VALUES
d2i_X509(), d2i_X509_bio() and d2i_X509_fp() return a valid X509 structure or NULL if an error occurs. The error code that can be obtained by ERR_get_error(3).SEE ALSO
ERR_get_error(3)HISTORY
d2i_X509, i2d_X509, d2i_X509_bio, d2i_X509_fp, i2d_X509_bio and i2d_X509_fp are available in all versions of SSLeay and OpenSSL.2015-10-26 | LibreSSL |