"Wade L. Scholine" <[EMAIL PROTECTED]>:

> An alternative not mentioned is to make the callback type have a 
> variable number of arguments, like
> 
>   typedef int (*password_cb(char *buf, int size, int rwflag, ...));
> 
> where the arg list is terminated with a null pointer constant or something.
> 
> This would still break existing code, but which would allow for more
> or less arbitrary parameters to callbacks. [...]

Actually this version, while looking reasonably at first sight, does
not work at all: The library cannot know with parameter list should be
used when calling the callback functions.  After all, the extra
parameters are not for data that the library thinks the callback
should know about, but for data about which the library knows nothing,
but which the application wants to "tunnel" to its callback functions.

A void* parameter seems to be the way to go; and with the extra
#defines for the then-historical three-parameter form, it won't hurt
existing C programs too much.  To achieve compatibility on other than
C sourcecode level, we can add function stubs using the old function
names, e.g. as follows (with the implementation in a new, separate
file, so that it won't be linked into applications that use the
macros):

/* include/openssl/pem.h */

#undef PEM_read_PrivateKey
EVP_PKEY *PEM_read_PrivateKey(FILE *fp,EVP_PKEY **x, pem_password_cb *);
EVP_PKEY *PEM_read_PrivateKey_ex(FILE *fp,EVP_PKEY **x,pem_password_cb*,void*);
#define PEM_read_PrivateKey(fp,pkeyp,callback) \
  PEM_read_PrivateKey_ex(fp,pkeyp,callback,NULL)


/* crypto/pem/pem_stubs.c */

#include <openssl/pem.h>

#undef PEM_read_PrivateKey
EVP_PKEY *PEM_read_PrivateKey(FILE *fp,EVP_PKEY **x, pem_password_cb *cb)
{
    return PEM_read_PrivateKey_ex(fp, x, cb, NULL);
}
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to