diff options
author | Gregory P. Smith <greg@mad-scientist.com> | 2010-01-19 08:19:03 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@mad-scientist.com> | 2010-01-19 08:19:03 (GMT) |
commit | 6b3573009a2b36950c4f1257d0ccd2a94f8cfd0d (patch) | |
tree | d61d0cebff8a05b6f682a9cb40fce9895b9a80cd /Modules | |
parent | 8f6f42621a28f02424a8effd45a03a6496fcabad (diff) | |
download | cpython-6b3573009a2b36950c4f1257d0ccd2a94f8cfd0d.zip cpython-6b3573009a2b36950c4f1257d0ccd2a94f8cfd0d.tar.gz cpython-6b3573009a2b36950c4f1257d0ccd2a94f8cfd0d.tar.bz2 |
Do not compile stubs for the sha2 series hashes in the openssl hashlib
module when the openssl version is too old to support them. That
leads both compiled code bloat and to unittests attempting to test
implementations that don't exist for comparison purposes on such
platforms.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_hashopenssl.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c index 004d5a3..3e972d1 100644 --- a/Modules/_hashopenssl.c +++ b/Modules/_hashopenssl.c @@ -48,6 +48,10 @@ #define HASH_OBJ_CONSTRUCTOR 0 #endif +/* Minimum OpenSSL version needed to support sha224 and higher. */ +#if defined(OPENSSL_VERSION_NUMBER) && (OPENSSL_VERSION_NUMBER >= 0x00908000) +#define _OPENSSL_SUPPORTS_SHA2 +#endif typedef struct { PyObject_HEAD @@ -69,10 +73,12 @@ static PyTypeObject EVPtype; DEFINE_CONSTS_FOR_NEW(md5) DEFINE_CONSTS_FOR_NEW(sha1) +#ifdef _OPENSSL_SUPPORTS_SHA2 DEFINE_CONSTS_FOR_NEW(sha224) DEFINE_CONSTS_FOR_NEW(sha256) DEFINE_CONSTS_FOR_NEW(sha384) DEFINE_CONSTS_FOR_NEW(sha512) +#endif static EVPobject * @@ -529,10 +535,12 @@ EVP_new(PyObject *self, PyObject *args, PyObject *kwdict) GEN_CONSTRUCTOR(md5) GEN_CONSTRUCTOR(sha1) +#ifdef _OPENSSL_SUPPORTS_SHA2 GEN_CONSTRUCTOR(sha224) GEN_CONSTRUCTOR(sha256) GEN_CONSTRUCTOR(sha384) GEN_CONSTRUCTOR(sha512) +#endif /* List of functions exported by this module */ @@ -540,10 +548,12 @@ static struct PyMethodDef EVP_functions[] = { {"new", (PyCFunction)EVP_new, METH_VARARGS|METH_KEYWORDS, EVP_new__doc__}, CONSTRUCTOR_METH_DEF(md5), CONSTRUCTOR_METH_DEF(sha1), +#ifdef _OPENSSL_SUPPORTS_SHA2 CONSTRUCTOR_METH_DEF(sha224), CONSTRUCTOR_METH_DEF(sha256), CONSTRUCTOR_METH_DEF(sha384), CONSTRUCTOR_METH_DEF(sha512), +#endif {NULL, NULL} /* Sentinel */ }; @@ -578,8 +588,10 @@ init_hashlib(void) /* these constants are used by the convenience constructors */ INIT_CONSTRUCTOR_CONSTANTS(md5); INIT_CONSTRUCTOR_CONSTANTS(sha1); +#ifdef _OPENSSL_SUPPORTS_SHA2 INIT_CONSTRUCTOR_CONSTANTS(sha224); INIT_CONSTRUCTOR_CONSTANTS(sha256); INIT_CONSTRUCTOR_CONSTANTS(sha384); INIT_CONSTRUCTOR_CONSTANTS(sha512); +#endif } |