summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Carroll <jim@caroll.com>2016-07-28 08:55:09 -0400
committerMatěj Cepl <mcepl@cepl.eu>2017-09-15 14:42:51 +0200
commite7e5d9166a337fc1a02f1d43528b5975f1c09e07 (patch)
tree17c2129aebd998718d98bfa29355c5dc3407a101
parent99cb0bc235b945a933fb1baad93f08140b928a0e (diff)
downloadm2crypto-e7e5d9166a337fc1a02f1d43528b5975f1c09e07.tar.gz
Invoke OPENSSL_SetApplink()
Added helper m2_PyObject_AsBIGNUM() Fixed #if directives for OpenSSL 1.0 support Also in SWIG/_evp.i move #define statements into %include %{ ... %}
-rw-r--r--SWIG/_evp.i33
-rw-r--r--SWIG/_lib.h2
-rw-r--r--SWIG/_lib.i24
-rw-r--r--SWIG/_x509.i2
4 files changed, 27 insertions, 34 deletions
diff --git a/SWIG/_evp.i b/SWIG/_evp.i
index e292c1e..6ee3b6b 100644
--- a/SWIG/_evp.i
+++ b/SWIG/_evp.i
@@ -34,34 +34,7 @@ typedef struct evp_md_ctx_st EVP_MD_CTX;
%apply Pointer NONNULL { EVP_CIPHER_CTX * };
%apply Pointer NONNULL { EVP_CIPHER * };
%apply Pointer NONNULL { RSA * };
-
-/* FIXME
-#if OPENSSL_VERSION_NUMBER < 0x10100000L
-#define EVP_MD_CTX_size(ctx) ((ctx)->digest->md_size)
-#define HMAC_size(ctx) ((ctx)->md->md_size)
-
-#define HMAC_CTX_new() \
- ((HMAC_CTX *)PyMem_Malloc(sizeof(HMAC_CTX)))
-#define HMAC_CTX_init(ctx) HMAC_CTX_reset(ctx)
-#define HMAC_CTX_free(ctx) \
- do { \
- HMAC_CTX_cleanup(ctx); \
- PyMem_Free((void *)ctx); \
- } while(0)
-
-#define EVP_CIPHER_CTX_new() \
- ((EVP_CIPHER_CTX *)PyMem_Malloc(sizeof(EVP_CIPHER_CTX)))
-#define EVP_CIPHER_CTX_init(ctx) EVP_CIPHER_CTX_reset(ctx)
-#define EVP_CIPHER_CTX_free(ctx) \
- do { \
- EVP_CIPHER_CTX_cleanup(ctx);\
- PyMem_Free((void *)ctx); \
- } while(0)
-#define EVP_CIPHER_CTX_block_size(ctx) \
- ((ctx)->cipher->block_size)
-#define EVP_PKEY_base_id(pkey) ((pkey)->type)
-#endif
-*/
+%}
%rename(md5) EVP_md5;
extern const EVP_MD *EVP_md5(void);
@@ -684,7 +657,7 @@ PyObject *pkey_get_modulus(EVP_PKEY *pkey)
ret = PyString_FromStringAndSize(bptr->data, bptr->length);
#endif
- BIO_set_close(bio, BIO_CLOSE);
+ (void)BIO_set_close(bio, BIO_CLOSE);
BIO_free(bio);
RSA_free(rsa);
@@ -717,7 +690,7 @@ PyObject *pkey_get_modulus(EVP_PKEY *pkey)
ret = PyString_FromStringAndSize(bptr->data, bptr->length);
#endif
- BIO_set_close(bio, BIO_CLOSE);
+ (void)BIO_set_close(bio, BIO_CLOSE);
BIO_free(bio);
DSA_free(dsa);
diff --git a/SWIG/_lib.h b/SWIG/_lib.h
index 9059334..5c36c0c 100644
--- a/SWIG/_lib.h
+++ b/SWIG/_lib.h
@@ -14,6 +14,8 @@ static int m2_PyObject_AsReadBufferInt(PyObject *obj, const void **buffer,
int *buffer_len);
static int m2_PyString_AsStringAndSizeInt(PyObject *obj, char **s, int *len);
+static BIGNUM* m2_PyObject_AsBIGNUM(PyObject* value, PyObject* _py_exc) ;
+
/* Always use these two together, to correctly handle non-memoryview objects. */
static int m2_PyObject_GetBufferInt(PyObject *obj, Py_buffer *view, int flags);
static void m2_PyBuffer_Release(PyObject *obj, Py_buffer *view);
diff --git a/SWIG/_lib.i b/SWIG/_lib.i
index 28f34f7..29b5fa0 100644
--- a/SWIG/_lib.i
+++ b/SWIG/_lib.i
@@ -102,6 +102,24 @@ static int m2_PyObject_GetBufferInt(PyObject *obj, Py_buffer *view, int flags)
return 0;
}
+static BIGNUM*
+m2_PyObject_AsBIGNUM(PyObject* value, PyObject* _py_exc)
+{
+ BIGNUM* bn;
+ const void* vbuf;
+ int vlen;
+
+ if (m2_PyObject_AsReadBufferInt(value, &vbuf, &vlen) == -1)
+ return NULL;
+
+ if (!(bn = BN_mpi2bn((unsigned char *)vbuf, vlen, NULL))) {
+ PyErr_SetString(_py_exc, ERR_reason_error_string(ERR_get_error()));
+ return NULL;
+ }
+
+ return bn;
+}
+
static void m2_PyBuffer_Release(PyObject *obj, Py_buffer *view)
{
if (PyObject_CheckBuffer(obj))
@@ -407,9 +425,12 @@ int passphrase_callback(char *buf, int num, int v, void *arg) {
%}
%inline %{
+
void lib_init() {
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
SSLeay_add_all_algorithms();
ERR_load_ERR_strings();
+#endif
}
/* Bignum routines that aren't not numerous enough to
@@ -662,9 +683,6 @@ http://stackoverflow.com/questions/8195383/pyfile-type-replaced-by
/* A bunch of "straight-thru" functions. */
-%rename(err_print_errors_fp) ERR_print_errors_fp;
-%threadallow ERR_print_errors_fp;
-extern void ERR_print_errors_fp(FILE *);
%rename(err_print_errors) ERR_print_errors;
%threadallow ERR_print_errors;
extern void ERR_print_errors(BIO *);
diff --git a/SWIG/_x509.i b/SWIG/_x509.i
index 909ba4e..0e8d691 100644
--- a/SWIG/_x509.i
+++ b/SWIG/_x509.i
@@ -495,7 +495,7 @@ int x509_name_add_entry_by_txt(X509_NAME *name, char *field, int type, char *byt
PyObject *x509_name_get_der(X509_NAME *name)
{
- unsigned char* pder;
+ const char* pder;
size_t pderlen;
i2d_X509_NAME(name, 0);
if (!X509_NAME_get0_der(&pder, &pderlen, name)) {