在openssl crypto库中,有很多形似i2d_xxx和d2i_xxx的函数,而且用source insight这样的代码浏览工具是没法找到其定义的,在我刚刚接触openssl的时候,着实郁闷了一阵子,就是找不到定义。后来才发现了这一系列函数的来源。原来他们是通过宏定义的方式来实现的。
在asn1.h中,有一系列的宏定义,其中DECLARE_ASN1_ENCODE_FUNCTIONS就是用于d2i和i2d的原型。
#define DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) /
type *d2i_##name(type **a, unsigned char **in, long len); /
int i2d_##name(type *a, unsigned char **out); /
DECLARE_ASN1_ITEM(itname)
对于此宏,如果传入参数为x509,那么扩展以后将变为
X509 *d2i_x509(type **a, unsigned char **in, long len);
int i2d_509(type *a, unsigned char **out);
DECLARE_ASN1_ITEM(x509)
这就是d2i和i2d的声明,那么函数定义呢?类似的在asn1t.h中,有这样的宏定义。
#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) /
stname *d2i_##fname(stname **a, unsigned char **in