From 65e56b78e0aecf92c846068088f64dff3c5d5a20 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sat, 2 Jan 2016 12:27:11 -0500 Subject: [PATCH 1/7] Attempt to use coverage to quantify how many of the CONDITIONAL_NAMES we really use --- .../hazmat/bindings/openssl/_conditional.py | 56 +++++++++---------- .../hazmat/bindings/openssl/binding.py | 4 +- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/cryptography/hazmat/bindings/openssl/_conditional.py b/src/cryptography/hazmat/bindings/openssl/_conditional.py index e9bbba6931ef..64de740bbafe 100644 --- a/src/cryptography/hazmat/bindings/openssl/_conditional.py +++ b/src/cryptography/hazmat/bindings/openssl/_conditional.py @@ -9,7 +9,7 @@ # when cffi supports #if in cdef. CONDITIONAL_NAMES = { - "Cryptography_HAS_CMS": [ + "Cryptography_HAS_CMS": lambda: [ "BIO_new_CMS", "i2d_CMS_bio_stream", "PEM_write_bio_CMS_stream", @@ -41,7 +41,7 @@ "CMS_DEBUG_DECRYPT", ], - "Cryptography_HAS_EC2M": [ + "Cryptography_HAS_EC2M": lambda: [ "EC_GF2m_simple_method", "EC_POINT_set_affine_coordinates_GF2m", "EC_POINT_get_affine_coordinates_GF2m", @@ -51,51 +51,51 @@ "EC_GROUP_new_curve_GF2m", ], - "Cryptography_HAS_EC_1_0_2": [ + "Cryptography_HAS_EC_1_0_2": lambda: [ "EC_curve_nid2nist", ], - "Cryptography_HAS_SET_ECDH_AUTO": [ + "Cryptography_HAS_SET_ECDH_AUTO": lambda: [ "SSL_CTX_set_ecdh_auto", ], - "Cryptography_HAS_ENGINE_CRYPTODEV": [ + "Cryptography_HAS_ENGINE_CRYPTODEV": lambda: [ "ENGINE_load_cryptodev" ], - "Cryptography_HAS_RSA_R_PKCS_DECODING_ERROR": [ + "Cryptography_HAS_RSA_R_PKCS_DECODING_ERROR": lambda: [ "RSA_R_PKCS_DECODING_ERROR" ], - "Cryptography_HAS_EGD": [ + "Cryptography_HAS_EGD": lambda: [ "RAND_egd", "RAND_egd_bytes", "RAND_query_egd_bytes", ], - "Cryptography_HAS_RSA_OAEP_MD": [ + "Cryptography_HAS_RSA_OAEP_MD": lambda: [ "EVP_PKEY_CTX_set_rsa_oaep_md", ], - "Cryptography_HAS_SSL3_METHOD": [ + "Cryptography_HAS_SSL3_METHOD": lambda: [ "SSLv3_method", "SSLv3_client_method", "SSLv3_server_method", ], - "Cryptography_HAS_ALPN": [ + "Cryptography_HAS_ALPN": lambda: [ "SSL_CTX_set_alpn_protos", "SSL_set_alpn_protos", "SSL_CTX_set_alpn_select_cb", "SSL_get0_alpn_selected", ], - "Cryptography_HAS_COMPRESSION": [ + "Cryptography_HAS_COMPRESSION": lambda: [ "SSL_get_current_compression", "SSL_get_current_expansion", "SSL_COMP_get_name", ], - "Cryptography_HAS_GET_SERVER_TMP_KEY": [ + "Cryptography_HAS_GET_SERVER_TMP_KEY": lambda: [ "SSL_get_server_tmp_key", ], - "Cryptography_HAS_102_VERIFICATION_ERROR_CODES": [ + "Cryptography_HAS_102_VERIFICATION_ERROR_CODES": lambda: [ 'X509_V_ERR_SUITE_B_INVALID_VERSION', 'X509_V_ERR_SUITE_B_INVALID_ALGORITHM', 'X509_V_ERR_SUITE_B_INVALID_CURVE', @@ -106,7 +106,7 @@ 'X509_V_ERR_EMAIL_MISMATCH', 'X509_V_ERR_IP_ADDRESS_MISMATCH' ], - "Cryptography_HAS_102_VERIFICATION_PARAMS": [ + "Cryptography_HAS_102_VERIFICATION_PARAMS": lambda: [ "X509_V_FLAG_SUITEB_128_LOS_ONLY", "X509_V_FLAG_SUITEB_192_LOS", "X509_V_FLAG_SUITEB_128_LOS", @@ -116,51 +116,51 @@ "X509_VERIFY_PARAM_set1_ip_asc", "X509_VERIFY_PARAM_set_hostflags", ], - "Cryptography_HAS_X509_V_FLAG_TRUSTED_FIRST": [ + "Cryptography_HAS_X509_V_FLAG_TRUSTED_FIRST": lambda: [ "X509_V_FLAG_TRUSTED_FIRST", ], - "Cryptography_HAS_X509_V_FLAG_PARTIAL_CHAIN": [ + "Cryptography_HAS_X509_V_FLAG_PARTIAL_CHAIN": lambda: [ "X509_V_FLAG_PARTIAL_CHAIN", ], - "Cryptography_HAS_SET_CERT_CB": [ + "Cryptography_HAS_SET_CERT_CB": lambda: [ "SSL_CTX_set_cert_cb", "SSL_set_cert_cb", ], - "Cryptography_HAS_SSL_ST": [ + "Cryptography_HAS_SSL_ST": lambda: [ "SSL_ST_BEFORE", "SSL_ST_OK", "SSL_ST_INIT", "SSL_ST_RENEGOTIATE", ], - "Cryptography_HAS_TLS_ST": [ + "Cryptography_HAS_TLS_ST": lambda: [ "TLS_ST_BEFORE", "TLS_ST_OK", ], - "Cryptography_HAS_LOCKING_CALLBACKS": [ + "Cryptography_HAS_LOCKING_CALLBACKS": lambda: [ "CRYPTO_LOCK", "CRYPTO_UNLOCK", "CRYPTO_READ", "CRYPTO_LOCK_SSL", "CRYPTO_lock", ], - "Cryptography_HAS_SCRYPT": [ + "Cryptography_HAS_SCRYPT": lambda: [ "EVP_PBE_scrypt", ], - "Cryptography_HAS_GENERIC_DTLS_METHOD": [ + "Cryptography_HAS_GENERIC_DTLS_METHOD": lambda: [ "DTLS_method", "DTLS_server_method", "DTLS_client_method", ], - "Cryptography_HAS_EVP_PKEY_DHX": [ + "Cryptography_HAS_EVP_PKEY_DHX": lambda: [ "EVP_PKEY_DHX", "Cryptography_d2i_DHxparams_bio", "Cryptography_i2d_DHxparams_bio", "PEM_write_bio_DHxparams", ], - "Cryptography_HAS_MEM_FUNCTIONS": [ + "Cryptography_HAS_MEM_FUNCTIONS": lambda: [ "Cryptography_CRYPTO_set_mem_functions", ], - "Cryptography_HAS_SCT": [ + "Cryptography_HAS_SCT": lambda: [ "SCT_get_version", "SCT_get_log_entry_type", "SCT_get0_log_id", @@ -170,14 +170,14 @@ "sk_SCT_value", "SCT_LIST_free", ], - "Cryptography_HAS_X509_STORE_CTX_GET_ISSUER": [ + "Cryptography_HAS_X509_STORE_CTX_GET_ISSUER": lambda: [ "X509_STORE_get_get_issuer", "X509_STORE_set_get_issuer", ], - "Cryptography_HAS_X25519": [ + "Cryptography_HAS_X25519": lambda: [ "NID_X25519", ], - "Cryptography_HAS_EVP_PKEY_get_set_tls_encodedpoint": [ + "Cryptography_HAS_EVP_PKEY_get_set_tls_encodedpoint": lambda: [ "EVP_PKEY_get1_tls_encodedpoint", "EVP_PKEY_set1_tls_encodedpoint", ], diff --git a/src/cryptography/hazmat/bindings/openssl/binding.py b/src/cryptography/hazmat/bindings/openssl/binding.py index d00fc7948c3f..7790213eb2ac 100644 --- a/src/cryptography/hazmat/bindings/openssl/binding.py +++ b/src/cryptography/hazmat/bindings/openssl/binding.py @@ -80,9 +80,9 @@ def build_conditional_library(lib, conditional_names): conditional_lib = types.ModuleType("lib") conditional_lib._original_lib = lib excluded_names = set() - for condition, names in conditional_names.items(): + for condition, names_cb in conditional_names.items(): if not getattr(lib, condition): - excluded_names |= set(names) + excluded_names.update(names_cb()) for attr in dir(lib): if attr not in excluded_names: From 4ae85fc1c83c58a043302526f0c08decf4d6ac54 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Mon, 13 Mar 2017 18:55:59 -0400 Subject: [PATCH 2/7] rewrite file to improve coverage --- .../hazmat/bindings/openssl/_conditional.py | 370 ++++++++++-------- 1 file changed, 198 insertions(+), 172 deletions(-) diff --git a/src/cryptography/hazmat/bindings/openssl/_conditional.py b/src/cryptography/hazmat/bindings/openssl/_conditional.py index 64de740bbafe..ca26d71d06b1 100644 --- a/src/cryptography/hazmat/bindings/openssl/_conditional.py +++ b/src/cryptography/hazmat/bindings/openssl/_conditional.py @@ -8,177 +8,203 @@ # loop over them and delete unsupported names at runtime. It will be removed # when cffi supports #if in cdef. +Cryptography_HAS_CMS = lambda: [ + "BIO_new_CMS", + "i2d_CMS_bio_stream", + "PEM_write_bio_CMS_stream", + "CMS_final", + "CMS_sign", + "CMS_verify", + "CMS_encrypt", + "CMS_decrypt", + "CMS_add1_signer", + "CMS_TEXT", + "CMS_NOCERTS", + "CMS_NO_CONTENT_VERIFY", + "CMS_NO_ATTR_VERIFY", + "CMS_NOSIGS", + "CMS_NOINTERN", + "CMS_NO_SIGNER_CERT_VERIFY", + "CMS_NOVERIFY", + "CMS_DETACHED", + "CMS_BINARY", + "CMS_NOATTR", + "CMS_NOSMIMECAP", + "CMS_NOOLDMIMETYPE", + "CMS_CRLFEOL", + "CMS_STREAM", + "CMS_NOCRL", + "CMS_PARTIAL", + "CMS_REUSE_DIGEST", + "CMS_USE_KEYID", + "CMS_DEBUG_DECRYPT", +] + +Cryptography_HAS_EC2M = lambda: [ + "EC_GF2m_simple_method", + "EC_POINT_set_affine_coordinates_GF2m", + "EC_POINT_get_affine_coordinates_GF2m", + "EC_POINT_set_compressed_coordinates_GF2m", + "EC_GROUP_set_curve_GF2m", + "EC_GROUP_get_curve_GF2m", + "EC_GROUP_new_curve_GF2m", +] + +Cryptography_HAS_EC_1_0_2 = lambda: [ + "EC_curve_nid2nist", +] +Cryptography_HAS_SET_ECDH_AUTO = lambda: [ + "SSL_CTX_set_ecdh_auto", +] +Cryptography_HAS_ENGINE_CRYPTODEV = lambda: [ + "ENGINE_load_cryptodev" +] +Cryptography_HAS_RSA_R_PKCS_DECODING_ERROR = lambda: [ + "RSA_R_PKCS_DECODING_ERROR" +] +Cryptography_HAS_EGD = lambda: [ + "RAND_egd", + "RAND_egd_bytes", + "RAND_query_egd_bytes", +] +Cryptography_HAS_RSA_OAEP_MD = lambda: [ + "EVP_PKEY_CTX_set_rsa_oaep_md", +] + +Cryptography_HAS_SSL3_METHOD = lambda: [ + "SSLv3_method", + "SSLv3_client_method", + "SSLv3_server_method", +] + +Cryptography_HAS_ALPN = lambda: [ + "SSL_CTX_set_alpn_protos", + "SSL_set_alpn_protos", + "SSL_CTX_set_alpn_select_cb", + "SSL_get0_alpn_selected", +] + +Cryptography_HAS_COMPRESSION = lambda: [ + "SSL_get_current_compression", + "SSL_get_current_expansion", + "SSL_COMP_get_name", +] + +Cryptography_HAS_GET_SERVER_TMP_KEY = lambda: [ + "SSL_get_server_tmp_key", +] + +Cryptography_HAS_102_VERIFICATION_ERROR_CODES = lambda: [ + 'X509_V_ERR_SUITE_B_INVALID_VERSION', + 'X509_V_ERR_SUITE_B_INVALID_ALGORITHM', + 'X509_V_ERR_SUITE_B_INVALID_CURVE', + 'X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM', + 'X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED', + 'X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256', + 'X509_V_ERR_HOSTNAME_MISMATCH', + 'X509_V_ERR_EMAIL_MISMATCH', + 'X509_V_ERR_IP_ADDRESS_MISMATCH' +] +Cryptography_HAS_102_VERIFICATION_PARAMS = lambda: [ + "X509_V_FLAG_SUITEB_128_LOS_ONLY", + "X509_V_FLAG_SUITEB_192_LOS", + "X509_V_FLAG_SUITEB_128_LOS", + "X509_VERIFY_PARAM_set1_host", + "X509_VERIFY_PARAM_set1_email", + "X509_VERIFY_PARAM_set1_ip", + "X509_VERIFY_PARAM_set1_ip_asc", + "X509_VERIFY_PARAM_set_hostflags", +] +Cryptography_HAS_X509_V_FLAG_TRUSTED_FIRST = lambda: [ + "X509_V_FLAG_TRUSTED_FIRST", +] +Cryptography_HAS_X509_V_FLAG_PARTIAL_CHAIN = lambda: [ + "X509_V_FLAG_PARTIAL_CHAIN", +] +Cryptography_HAS_SET_CERT_CB = lambda: [ + "SSL_CTX_set_cert_cb", + "SSL_set_cert_cb", +] +Cryptography_HAS_SSL_ST = lambda: [ + "SSL_ST_BEFORE", + "SSL_ST_OK", + "SSL_ST_INIT", + "SSL_ST_RENEGOTIATE", +] +Cryptography_HAS_TLS_ST = lambda: [ + "TLS_ST_BEFORE", + "TLS_ST_OK", +] +Cryptography_HAS_LOCKING_CALLBACKS = lambda: [ + "CRYPTO_LOCK", + "CRYPTO_UNLOCK", + "CRYPTO_READ", + "CRYPTO_LOCK_SSL", + "CRYPTO_lock", +] +Cryptography_HAS_SCRYPT = lambda: [ + "EVP_PBE_scrypt", +] +Cryptography_HAS_EVP_PKEY_DHX = lambda: [ + "EVP_PKEY_DHX", +] + +Cryptography_HAS_MEM_FUNCTIONS = lambda: [ + "Cryptography_CRYPTO_set_mem_functions", +] + +Cryptography_HAS_SCT = lambda: [ + "SCT_get_version", + "SCT_get_log_entry_type", + "SCT_get0_log_id", + "SCT_get_timestamp", + "SCT_set_source", + "sk_SCT_num", + "sk_SCT_value", + "SCT_LIST_free", +] + +Cryptography_HAS_X509_STORE_CTX_GET_ISSUER = lambda: [ + "X509_STORE_get_get_issuer", + "X509_STORE_set_get_issuer", +] + +Cryptography_HAS_X25519 = lambda: [ + "NID_X25519", +] + +Cryptography_HAS_EVP_PKEY_get_set_tls_encodedpoint = lambda: [ + "EVP_PKEY_get1_tls_encodedpoint", + "EVP_PKEY_set1_tls_encodedpoint", +] + + CONDITIONAL_NAMES = { - "Cryptography_HAS_CMS": lambda: [ - "BIO_new_CMS", - "i2d_CMS_bio_stream", - "PEM_write_bio_CMS_stream", - "CMS_final", - "CMS_sign", - "CMS_verify", - "CMS_encrypt", - "CMS_decrypt", - "CMS_add1_signer", - "CMS_TEXT", - "CMS_NOCERTS", - "CMS_NO_CONTENT_VERIFY", - "CMS_NO_ATTR_VERIFY", - "CMS_NOSIGS", - "CMS_NOINTERN", - "CMS_NO_SIGNER_CERT_VERIFY", - "CMS_NOVERIFY", - "CMS_DETACHED", - "CMS_BINARY", - "CMS_NOATTR", - "CMS_NOSMIMECAP", - "CMS_NOOLDMIMETYPE", - "CMS_CRLFEOL", - "CMS_STREAM", - "CMS_NOCRL", - "CMS_PARTIAL", - "CMS_REUSE_DIGEST", - "CMS_USE_KEYID", - "CMS_DEBUG_DECRYPT", - ], - - "Cryptography_HAS_EC2M": lambda: [ - "EC_GF2m_simple_method", - "EC_POINT_set_affine_coordinates_GF2m", - "EC_POINT_get_affine_coordinates_GF2m", - "EC_POINT_set_compressed_coordinates_GF2m", - "EC_GROUP_set_curve_GF2m", - "EC_GROUP_get_curve_GF2m", - "EC_GROUP_new_curve_GF2m", - ], - - "Cryptography_HAS_EC_1_0_2": lambda: [ - "EC_curve_nid2nist", - ], - "Cryptography_HAS_SET_ECDH_AUTO": lambda: [ - "SSL_CTX_set_ecdh_auto", - ], - "Cryptography_HAS_ENGINE_CRYPTODEV": lambda: [ - "ENGINE_load_cryptodev" - ], - "Cryptography_HAS_RSA_R_PKCS_DECODING_ERROR": lambda: [ - "RSA_R_PKCS_DECODING_ERROR" - ], - "Cryptography_HAS_EGD": lambda: [ - "RAND_egd", - "RAND_egd_bytes", - "RAND_query_egd_bytes", - ], - "Cryptography_HAS_RSA_OAEP_MD": lambda: [ - "EVP_PKEY_CTX_set_rsa_oaep_md", - ], - - "Cryptography_HAS_SSL3_METHOD": lambda: [ - "SSLv3_method", - "SSLv3_client_method", - "SSLv3_server_method", - ], - - "Cryptography_HAS_ALPN": lambda: [ - "SSL_CTX_set_alpn_protos", - "SSL_set_alpn_protos", - "SSL_CTX_set_alpn_select_cb", - "SSL_get0_alpn_selected", - ], - - "Cryptography_HAS_COMPRESSION": lambda: [ - "SSL_get_current_compression", - "SSL_get_current_expansion", - "SSL_COMP_get_name", - ], - - "Cryptography_HAS_GET_SERVER_TMP_KEY": lambda: [ - "SSL_get_server_tmp_key", - ], - - "Cryptography_HAS_102_VERIFICATION_ERROR_CODES": lambda: [ - 'X509_V_ERR_SUITE_B_INVALID_VERSION', - 'X509_V_ERR_SUITE_B_INVALID_ALGORITHM', - 'X509_V_ERR_SUITE_B_INVALID_CURVE', - 'X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM', - 'X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED', - 'X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256', - 'X509_V_ERR_HOSTNAME_MISMATCH', - 'X509_V_ERR_EMAIL_MISMATCH', - 'X509_V_ERR_IP_ADDRESS_MISMATCH' - ], - "Cryptography_HAS_102_VERIFICATION_PARAMS": lambda: [ - "X509_V_FLAG_SUITEB_128_LOS_ONLY", - "X509_V_FLAG_SUITEB_192_LOS", - "X509_V_FLAG_SUITEB_128_LOS", - "X509_VERIFY_PARAM_set1_host", - "X509_VERIFY_PARAM_set1_email", - "X509_VERIFY_PARAM_set1_ip", - "X509_VERIFY_PARAM_set1_ip_asc", - "X509_VERIFY_PARAM_set_hostflags", - ], - "Cryptography_HAS_X509_V_FLAG_TRUSTED_FIRST": lambda: [ - "X509_V_FLAG_TRUSTED_FIRST", - ], - "Cryptography_HAS_X509_V_FLAG_PARTIAL_CHAIN": lambda: [ - "X509_V_FLAG_PARTIAL_CHAIN", - ], - "Cryptography_HAS_SET_CERT_CB": lambda: [ - "SSL_CTX_set_cert_cb", - "SSL_set_cert_cb", - ], - "Cryptography_HAS_SSL_ST": lambda: [ - "SSL_ST_BEFORE", - "SSL_ST_OK", - "SSL_ST_INIT", - "SSL_ST_RENEGOTIATE", - ], - "Cryptography_HAS_TLS_ST": lambda: [ - "TLS_ST_BEFORE", - "TLS_ST_OK", - ], - "Cryptography_HAS_LOCKING_CALLBACKS": lambda: [ - "CRYPTO_LOCK", - "CRYPTO_UNLOCK", - "CRYPTO_READ", - "CRYPTO_LOCK_SSL", - "CRYPTO_lock", - ], - "Cryptography_HAS_SCRYPT": lambda: [ - "EVP_PBE_scrypt", - ], - "Cryptography_HAS_GENERIC_DTLS_METHOD": lambda: [ - "DTLS_method", - "DTLS_server_method", - "DTLS_client_method", - ], - "Cryptography_HAS_EVP_PKEY_DHX": lambda: [ - "EVP_PKEY_DHX", - "Cryptography_d2i_DHxparams_bio", - "Cryptography_i2d_DHxparams_bio", - "PEM_write_bio_DHxparams", - ], - "Cryptography_HAS_MEM_FUNCTIONS": lambda: [ - "Cryptography_CRYPTO_set_mem_functions", - ], - "Cryptography_HAS_SCT": lambda: [ - "SCT_get_version", - "SCT_get_log_entry_type", - "SCT_get0_log_id", - "SCT_get_timestamp", - "SCT_set_source", - "sk_SCT_num", - "sk_SCT_value", - "SCT_LIST_free", - ], - "Cryptography_HAS_X509_STORE_CTX_GET_ISSUER": lambda: [ - "X509_STORE_get_get_issuer", - "X509_STORE_set_get_issuer", - ], - "Cryptography_HAS_X25519": lambda: [ - "NID_X25519", - ], - "Cryptography_HAS_EVP_PKEY_get_set_tls_encodedpoint": lambda: [ - "EVP_PKEY_get1_tls_encodedpoint", - "EVP_PKEY_set1_tls_encodedpoint", - ], + "Cryptography_HAS_CMS": Cryptography_HAS_CMS, + "Cryptography_HAS_EC2M": Cryptography_HAS_EC2M, + "Cryptography_HAS_EC_1_0_2": Cryptography_HAS_EC_1_0_2, + "Cryptography_HAS_SET_ECDH_AUTO": Cryptography_HAS_SET_ECDH_AUTO, + "Cryptography_HAS_ENGINE_CRYPTODEV": Cryptography_HAS_ENGINE_CRYPTODEV, + "Cryptography_HAS_RSA_R_PKCS_DECODING_ERROR": Cryptography_HAS_RSA_R_PKCS_DECODING_ERROR, + "Cryptography_HAS_EGD": Cryptography_HAS_EGD, + "Cryptography_HAS_RSA_OAEP_MD": Cryptography_HAS_RSA_OAEP_MD, + "Cryptography_HAS_SSL3_METHOD": Cryptography_HAS_SSL3_METHOD, + "Cryptography_HAS_ALPN": Cryptography_HAS_ALPN, + "Cryptography_HAS_COMPRESSION": Cryptography_HAS_COMPRESSION, + "Cryptography_HAS_GET_SERVER_TMP_KEY": Cryptography_HAS_GET_SERVER_TMP_KEY, + "Cryptography_HAS_102_VERIFICATION_ERROR_CODES": Cryptography_HAS_102_VERIFICATION_ERROR_CODES, + "Cryptography_HAS_102_VERIFICATION_PARAMS": Cryptography_HAS_102_VERIFICATION_PARAMS, + "Cryptography_HAS_X509_V_FLAG_TRUSTED_FIRST": Cryptography_HAS_X509_V_FLAG_TRUSTED_FIRST, + "Cryptography_HAS_X509_V_FLAG_PARTIAL_CHAIN": Cryptography_HAS_X509_V_FLAG_PARTIAL_CHAIN, + "Cryptography_HAS_SET_CERT_CB": Cryptography_HAS_SET_CERT_CB, + "Cryptography_HAS_SSL_ST": Cryptography_HAS_SSL_ST, + "Cryptography_HAS_TLS_ST": Cryptography_HAS_TLS_ST, + "Cryptography_HAS_LOCKING_CALLBACKS": Cryptography_HAS_LOCKING_CALLBACKS, + "Cryptography_HAS_SCRYPT": Cryptography_HAS_SCRYPT, + "Cryptography_HAS_EVP_PKEY_DHX": Cryptography_HAS_EVP_PKEY_DHX, + "Cryptography_HAS_MEM_FUNCTIONS": Cryptography_HAS_MEM_FUNCTIONS, + "Cryptography_HAS_SCT": Cryptography_HAS_SCT, + "Cryptography_HAS_X509_STORE_CTX_GET_ISSUER": Cryptography_HAS_X509_STORE_CTX_GET_ISSUER + "Cryptography_HAS_X25519": Cryptography_HAS_X25519, + "Cryptography_HAS_EVP_PKEY_get_set_tls_encodedpoint": Cryptography_HAS_EVP_PKEY_get_set_tls_encodedpoint } From e3e966b0aad882a01d5bf63c2288156a44da1ccb Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Mon, 13 Mar 2017 19:10:23 -0400 Subject: [PATCH 3/7] Write it this way so we can use line coverage --- .../hazmat/bindings/openssl/_conditional.py | 434 +++++++++++------- 1 file changed, 258 insertions(+), 176 deletions(-) diff --git a/src/cryptography/hazmat/bindings/openssl/_conditional.py b/src/cryptography/hazmat/bindings/openssl/_conditional.py index ca26d71d06b1..165b41cc691e 100644 --- a/src/cryptography/hazmat/bindings/openssl/_conditional.py +++ b/src/cryptography/hazmat/bindings/openssl/_conditional.py @@ -8,175 +8,243 @@ # loop over them and delete unsupported names at runtime. It will be removed # when cffi supports #if in cdef. -Cryptography_HAS_CMS = lambda: [ - "BIO_new_CMS", - "i2d_CMS_bio_stream", - "PEM_write_bio_CMS_stream", - "CMS_final", - "CMS_sign", - "CMS_verify", - "CMS_encrypt", - "CMS_decrypt", - "CMS_add1_signer", - "CMS_TEXT", - "CMS_NOCERTS", - "CMS_NO_CONTENT_VERIFY", - "CMS_NO_ATTR_VERIFY", - "CMS_NOSIGS", - "CMS_NOINTERN", - "CMS_NO_SIGNER_CERT_VERIFY", - "CMS_NOVERIFY", - "CMS_DETACHED", - "CMS_BINARY", - "CMS_NOATTR", - "CMS_NOSMIMECAP", - "CMS_NOOLDMIMETYPE", - "CMS_CRLFEOL", - "CMS_STREAM", - "CMS_NOCRL", - "CMS_PARTIAL", - "CMS_REUSE_DIGEST", - "CMS_USE_KEYID", - "CMS_DEBUG_DECRYPT", -] - -Cryptography_HAS_EC2M = lambda: [ - "EC_GF2m_simple_method", - "EC_POINT_set_affine_coordinates_GF2m", - "EC_POINT_get_affine_coordinates_GF2m", - "EC_POINT_set_compressed_coordinates_GF2m", - "EC_GROUP_set_curve_GF2m", - "EC_GROUP_get_curve_GF2m", - "EC_GROUP_new_curve_GF2m", -] - -Cryptography_HAS_EC_1_0_2 = lambda: [ - "EC_curve_nid2nist", -] -Cryptography_HAS_SET_ECDH_AUTO = lambda: [ - "SSL_CTX_set_ecdh_auto", -] -Cryptography_HAS_ENGINE_CRYPTODEV = lambda: [ - "ENGINE_load_cryptodev" -] -Cryptography_HAS_RSA_R_PKCS_DECODING_ERROR = lambda: [ - "RSA_R_PKCS_DECODING_ERROR" -] -Cryptography_HAS_EGD = lambda: [ - "RAND_egd", - "RAND_egd_bytes", - "RAND_query_egd_bytes", -] -Cryptography_HAS_RSA_OAEP_MD = lambda: [ - "EVP_PKEY_CTX_set_rsa_oaep_md", -] - -Cryptography_HAS_SSL3_METHOD = lambda: [ - "SSLv3_method", - "SSLv3_client_method", - "SSLv3_server_method", -] - -Cryptography_HAS_ALPN = lambda: [ - "SSL_CTX_set_alpn_protos", - "SSL_set_alpn_protos", - "SSL_CTX_set_alpn_select_cb", - "SSL_get0_alpn_selected", -] - -Cryptography_HAS_COMPRESSION = lambda: [ - "SSL_get_current_compression", - "SSL_get_current_expansion", - "SSL_COMP_get_name", -] - -Cryptography_HAS_GET_SERVER_TMP_KEY = lambda: [ - "SSL_get_server_tmp_key", -] - -Cryptography_HAS_102_VERIFICATION_ERROR_CODES = lambda: [ - 'X509_V_ERR_SUITE_B_INVALID_VERSION', - 'X509_V_ERR_SUITE_B_INVALID_ALGORITHM', - 'X509_V_ERR_SUITE_B_INVALID_CURVE', - 'X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM', - 'X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED', - 'X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256', - 'X509_V_ERR_HOSTNAME_MISMATCH', - 'X509_V_ERR_EMAIL_MISMATCH', - 'X509_V_ERR_IP_ADDRESS_MISMATCH' -] -Cryptography_HAS_102_VERIFICATION_PARAMS = lambda: [ - "X509_V_FLAG_SUITEB_128_LOS_ONLY", - "X509_V_FLAG_SUITEB_192_LOS", - "X509_V_FLAG_SUITEB_128_LOS", - "X509_VERIFY_PARAM_set1_host", - "X509_VERIFY_PARAM_set1_email", - "X509_VERIFY_PARAM_set1_ip", - "X509_VERIFY_PARAM_set1_ip_asc", - "X509_VERIFY_PARAM_set_hostflags", -] -Cryptography_HAS_X509_V_FLAG_TRUSTED_FIRST = lambda: [ - "X509_V_FLAG_TRUSTED_FIRST", -] -Cryptography_HAS_X509_V_FLAG_PARTIAL_CHAIN = lambda: [ - "X509_V_FLAG_PARTIAL_CHAIN", -] -Cryptography_HAS_SET_CERT_CB = lambda: [ - "SSL_CTX_set_cert_cb", - "SSL_set_cert_cb", -] -Cryptography_HAS_SSL_ST = lambda: [ - "SSL_ST_BEFORE", - "SSL_ST_OK", - "SSL_ST_INIT", - "SSL_ST_RENEGOTIATE", -] -Cryptography_HAS_TLS_ST = lambda: [ - "TLS_ST_BEFORE", - "TLS_ST_OK", -] -Cryptography_HAS_LOCKING_CALLBACKS = lambda: [ - "CRYPTO_LOCK", - "CRYPTO_UNLOCK", - "CRYPTO_READ", - "CRYPTO_LOCK_SSL", - "CRYPTO_lock", -] -Cryptography_HAS_SCRYPT = lambda: [ - "EVP_PBE_scrypt", -] -Cryptography_HAS_EVP_PKEY_DHX = lambda: [ - "EVP_PKEY_DHX", -] - -Cryptography_HAS_MEM_FUNCTIONS = lambda: [ - "Cryptography_CRYPTO_set_mem_functions", -] - -Cryptography_HAS_SCT = lambda: [ - "SCT_get_version", - "SCT_get_log_entry_type", - "SCT_get0_log_id", - "SCT_get_timestamp", - "SCT_set_source", - "sk_SCT_num", - "sk_SCT_value", - "SCT_LIST_free", -] - -Cryptography_HAS_X509_STORE_CTX_GET_ISSUER = lambda: [ - "X509_STORE_get_get_issuer", - "X509_STORE_set_get_issuer", -] - -Cryptography_HAS_X25519 = lambda: [ - "NID_X25519", -] - -Cryptography_HAS_EVP_PKEY_get_set_tls_encodedpoint = lambda: [ - "EVP_PKEY_get1_tls_encodedpoint", - "EVP_PKEY_set1_tls_encodedpoint", -] + +def Cryptography_HAS_CMS(): + return [ + "BIO_new_CMS", + "i2d_CMS_bio_stream", + "PEM_write_bio_CMS_stream", + "CMS_final", + "CMS_sign", + "CMS_verify", + "CMS_encrypt", + "CMS_decrypt", + "CMS_add1_signer", + "CMS_TEXT", + "CMS_NOCERTS", + "CMS_NO_CONTENT_VERIFY", + "CMS_NO_ATTR_VERIFY", + "CMS_NOSIGS", + "CMS_NOINTERN", + "CMS_NO_SIGNER_CERT_VERIFY", + "CMS_NOVERIFY", + "CMS_DETACHED", + "CMS_BINARY", + "CMS_NOATTR", + "CMS_NOSMIMECAP", + "CMS_NOOLDMIMETYPE", + "CMS_CRLFEOL", + "CMS_STREAM", + "CMS_NOCRL", + "CMS_PARTIAL", + "CMS_REUSE_DIGEST", + "CMS_USE_KEYID", + "CMS_DEBUG_DECRYPT", + ] + + +def Cryptography_HAS_EC2M(): + return [ + "EC_GF2m_simple_method", + "EC_POINT_set_affine_coordinates_GF2m", + "EC_POINT_get_affine_coordinates_GF2m", + "EC_POINT_set_compressed_coordinates_GF2m", + "EC_GROUP_set_curve_GF2m", + "EC_GROUP_get_curve_GF2m", + "EC_GROUP_new_curve_GF2m", + ] + + +def Cryptography_HAS_EC_1_0_2(): + return [ + "EC_curve_nid2nist", + ] + + +def Cryptography_HAS_SET_ECDH_AUTO(): + return [ + "SSL_CTX_set_ecdh_auto", + ] + + +def Cryptography_HAS_ENGINE_CRYPTODEV(): + return [ + "ENGINE_load_cryptodev" + ] + + +def Cryptography_HAS_RSA_R_PKCS_DECODING_ERROR(): + return [ + "RSA_R_PKCS_DECODING_ERROR" + ] + + +def Cryptography_HAS_EGD(): + return [ + "RAND_egd", + "RAND_egd_bytes", + "RAND_query_egd_bytes", + ] + + +def Cryptography_HAS_RSA_OAEP_MD(): + return [ + "EVP_PKEY_CTX_set_rsa_oaep_md", + ] + + +def Cryptography_HAS_SSL3_METHOD(): + return [ + "SSLv3_method", + "SSLv3_client_method", + "SSLv3_server_method", + ] + + +def Cryptography_HAS_ALPN(): + return [ + "SSL_CTX_set_alpn_protos", + "SSL_set_alpn_protos", + "SSL_CTX_set_alpn_select_cb", + "SSL_get0_alpn_selected", + ] + + +def Cryptography_HAS_COMPRESSION(): + return [ + "SSL_get_current_compression", + "SSL_get_current_expansion", + "SSL_COMP_get_name", + ] + + +def Cryptography_HAS_GET_SERVER_TMP_KEY(): + return [ + "SSL_get_server_tmp_key", + ] + + +def Cryptography_HAS_102_VERIFICATION_ERROR_CODES(): + return [ + 'X509_V_ERR_SUITE_B_INVALID_VERSION', + 'X509_V_ERR_SUITE_B_INVALID_ALGORITHM', + 'X509_V_ERR_SUITE_B_INVALID_CURVE', + 'X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM', + 'X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED', + 'X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256', + 'X509_V_ERR_HOSTNAME_MISMATCH', + 'X509_V_ERR_EMAIL_MISMATCH', + 'X509_V_ERR_IP_ADDRESS_MISMATCH' + ] + + +def Cryptography_HAS_102_VERIFICATION_PARAMS(): + return [ + "X509_V_FLAG_SUITEB_128_LOS_ONLY", + "X509_V_FLAG_SUITEB_192_LOS", + "X509_V_FLAG_SUITEB_128_LOS", + "X509_VERIFY_PARAM_set1_host", + "X509_VERIFY_PARAM_set1_email", + "X509_VERIFY_PARAM_set1_ip", + "X509_VERIFY_PARAM_set1_ip_asc", + "X509_VERIFY_PARAM_set_hostflags", + ] + + +def Cryptography_HAS_X509_V_FLAG_TRUSTED_FIRST(): + return [ + "X509_V_FLAG_TRUSTED_FIRST", + ] + + +def Cryptography_HAS_X509_V_FLAG_PARTIAL_CHAIN(): + return [ + "X509_V_FLAG_PARTIAL_CHAIN", + ] + + +def Cryptography_HAS_SET_CERT_CB(): + return [ + "SSL_CTX_set_cert_cb", + "SSL_set_cert_cb", + ] + + +def Cryptography_HAS_SSL_ST(): + return [ + "SSL_ST_BEFORE", + "SSL_ST_OK", + "SSL_ST_INIT", + "SSL_ST_RENEGOTIATE", + ] + + +def Cryptography_HAS_TLS_ST(): + return [ + "TLS_ST_BEFORE", + "TLS_ST_OK", + ] + + +def Cryptography_HAS_LOCKING_CALLBACKS(): + return [ + "CRYPTO_LOCK", + "CRYPTO_UNLOCK", + "CRYPTO_READ", + "CRYPTO_LOCK_SSL", + "CRYPTO_lock", + ] + + +def Cryptography_HAS_SCRYPT(): + return [ + "EVP_PBE_scrypt", + ] + + +def Cryptography_HAS_EVP_PKEY_DHX(): + return [ + "EVP_PKEY_DHX", + ] + + +def Cryptography_HAS_MEM_FUNCTIONS(): + return [ + "Cryptography_CRYPTO_set_mem_functions", + ] + + +def Cryptography_HAS_SCT(): + return [ + "SCT_get_version", + "SCT_get_log_entry_type", + "SCT_get0_log_id", + "SCT_get_timestamp", + "SCT_set_source", + "sk_SCT_num", + "sk_SCT_value", + "SCT_LIST_free", + ] + + +def Cryptography_HAS_X509_STORE_CTX_GET_ISSUER(): + return [ + "X509_STORE_get_get_issuer", + "X509_STORE_set_get_issuer", + ] + + +def Cryptography_HAS_X25519(): + return [ + "NID_X25519", + ] + + +def Cryptography_HAS_EVP_PKEY_get_set_tls_encodedpoint(): + return [ + "EVP_PKEY_get1_tls_encodedpoint", + "EVP_PKEY_set1_tls_encodedpoint", + ] CONDITIONAL_NAMES = { @@ -185,17 +253,27 @@ "Cryptography_HAS_EC_1_0_2": Cryptography_HAS_EC_1_0_2, "Cryptography_HAS_SET_ECDH_AUTO": Cryptography_HAS_SET_ECDH_AUTO, "Cryptography_HAS_ENGINE_CRYPTODEV": Cryptography_HAS_ENGINE_CRYPTODEV, - "Cryptography_HAS_RSA_R_PKCS_DECODING_ERROR": Cryptography_HAS_RSA_R_PKCS_DECODING_ERROR, + "Cryptography_HAS_RSA_R_PKCS_DECODING_ERROR": ( + Cryptography_HAS_RSA_R_PKCS_DECODING_ERROR + ), "Cryptography_HAS_EGD": Cryptography_HAS_EGD, "Cryptography_HAS_RSA_OAEP_MD": Cryptography_HAS_RSA_OAEP_MD, "Cryptography_HAS_SSL3_METHOD": Cryptography_HAS_SSL3_METHOD, "Cryptography_HAS_ALPN": Cryptography_HAS_ALPN, "Cryptography_HAS_COMPRESSION": Cryptography_HAS_COMPRESSION, "Cryptography_HAS_GET_SERVER_TMP_KEY": Cryptography_HAS_GET_SERVER_TMP_KEY, - "Cryptography_HAS_102_VERIFICATION_ERROR_CODES": Cryptography_HAS_102_VERIFICATION_ERROR_CODES, - "Cryptography_HAS_102_VERIFICATION_PARAMS": Cryptography_HAS_102_VERIFICATION_PARAMS, - "Cryptography_HAS_X509_V_FLAG_TRUSTED_FIRST": Cryptography_HAS_X509_V_FLAG_TRUSTED_FIRST, - "Cryptography_HAS_X509_V_FLAG_PARTIAL_CHAIN": Cryptography_HAS_X509_V_FLAG_PARTIAL_CHAIN, + "Cryptography_HAS_102_VERIFICATION_ERROR_CODES": ( + Cryptography_HAS_102_VERIFICATION_ERROR_CODES + ), + "Cryptography_HAS_102_VERIFICATION_PARAMS": ( + Cryptography_HAS_102_VERIFICATION_PARAMS + ), + "Cryptography_HAS_X509_V_FLAG_TRUSTED_FIRST": ( + Cryptography_HAS_X509_V_FLAG_TRUSTED_FIRST + ), + "Cryptography_HAS_X509_V_FLAG_PARTIAL_CHAIN": ( + Cryptography_HAS_X509_V_FLAG_PARTIAL_CHAIN + ), "Cryptography_HAS_SET_CERT_CB": Cryptography_HAS_SET_CERT_CB, "Cryptography_HAS_SSL_ST": Cryptography_HAS_SSL_ST, "Cryptography_HAS_TLS_ST": Cryptography_HAS_TLS_ST, @@ -204,7 +282,11 @@ "Cryptography_HAS_EVP_PKEY_DHX": Cryptography_HAS_EVP_PKEY_DHX, "Cryptography_HAS_MEM_FUNCTIONS": Cryptography_HAS_MEM_FUNCTIONS, "Cryptography_HAS_SCT": Cryptography_HAS_SCT, - "Cryptography_HAS_X509_STORE_CTX_GET_ISSUER": Cryptography_HAS_X509_STORE_CTX_GET_ISSUER + "Cryptography_HAS_X509_STORE_CTX_GET_ISSUER": ( + Cryptography_HAS_X509_STORE_CTX_GET_ISSUER + ), "Cryptography_HAS_X25519": Cryptography_HAS_X25519, - "Cryptography_HAS_EVP_PKEY_get_set_tls_encodedpoint": Cryptography_HAS_EVP_PKEY_get_set_tls_encodedpoint + "Cryptography_HAS_EVP_PKEY_get_set_tls_encodedpoint": ( + Cryptography_HAS_EVP_PKEY_get_set_tls_encodedpoint + ), } From 4046547156c3df15cc710fa784c07ec81d1dfaab Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sat, 8 Jul 2017 11:52:07 -0400 Subject: [PATCH 4/7] lost this one :-( --- .../hazmat/bindings/openssl/_conditional.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/cryptography/hazmat/bindings/openssl/_conditional.py b/src/cryptography/hazmat/bindings/openssl/_conditional.py index 165b41cc691e..e27c8cde5071 100644 --- a/src/cryptography/hazmat/bindings/openssl/_conditional.py +++ b/src/cryptography/hazmat/bindings/openssl/_conditional.py @@ -202,6 +202,14 @@ def Cryptography_HAS_SCRYPT(): ] +def Cryptography_HAS_GENERIC_DTLS_METHOD(): + return [ + "DTLS_method", + "DTLS_server_method", + "DTLS_client_method", + ] + + def Cryptography_HAS_EVP_PKEY_DHX(): return [ "EVP_PKEY_DHX", @@ -279,6 +287,9 @@ def Cryptography_HAS_EVP_PKEY_get_set_tls_encodedpoint(): "Cryptography_HAS_TLS_ST": Cryptography_HAS_TLS_ST, "Cryptography_HAS_LOCKING_CALLBACKS": Cryptography_HAS_LOCKING_CALLBACKS, "Cryptography_HAS_SCRYPT": Cryptography_HAS_SCRYPT, + "Cryptography_HAS_GENERIC_DTLS_METHOD": ( + Cryptography_HAS_GENERIC_DTLS_METHOD + ), "Cryptography_HAS_EVP_PKEY_DHX": Cryptography_HAS_EVP_PKEY_DHX, "Cryptography_HAS_MEM_FUNCTIONS": Cryptography_HAS_MEM_FUNCTIONS, "Cryptography_HAS_SCT": Cryptography_HAS_SCT, From 615d3eaca4a55b26358cdac4100a7434226ec596 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sat, 8 Jul 2017 12:13:17 -0400 Subject: [PATCH 5/7] fix comment and flake8 --- src/cryptography/hazmat/bindings/openssl/_conditional.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cryptography/hazmat/bindings/openssl/_conditional.py b/src/cryptography/hazmat/bindings/openssl/_conditional.py index e27c8cde5071..bfac4fa89b1a 100644 --- a/src/cryptography/hazmat/bindings/openssl/_conditional.py +++ b/src/cryptography/hazmat/bindings/openssl/_conditional.py @@ -4,9 +4,6 @@ from __future__ import absolute_import, division, print_function -# This is a mapping of {condition: names-dependent-on-that-condition} so we can -# loop over them and delete unsupported names at runtime. It will be removed -# when cffi supports #if in cdef. def Cryptography_HAS_CMS(): @@ -255,6 +252,11 @@ def Cryptography_HAS_EVP_PKEY_get_set_tls_encodedpoint(): ] +# This is a mapping of +# {condition: function-returning-names-dependent-on-that-condition} so we can +# loop over them and delete unsupported names at runtime. It will be removed +# when cffi supports #if in cdef. We use functions instead of just a dict of +# lists so we can use coverage to measure which are used. CONDITIONAL_NAMES = { "Cryptography_HAS_CMS": Cryptography_HAS_CMS, "Cryptography_HAS_EC2M": Cryptography_HAS_EC2M, From 2579fda8a8d22b83bdea71e6079e7b9578960528 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sat, 8 Jul 2017 17:48:30 -0400 Subject: [PATCH 6/7] update the docs as well --- docs/development/c-bindings.rst | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/docs/development/c-bindings.rst b/docs/development/c-bindings.rst index 43ec4d8d24e4..9c69f4ee33dc 100644 --- a/docs/development/c-bindings.rst +++ b/docs/development/c-bindings.rst @@ -167,15 +167,22 @@ the necessarily type definitions are in place. Finally, add an entry to ``CONDITIONAL_NAMES`` with all of the things you want to conditionally export:: - CONDITIONAL_NAMES = { - ... - "Cryptography_HAS_QUANTUM_TRANSMOGRIFICATION": [ + def Cryptography_HAS_QUANTUM_TRANSMOGRIFICATION(): + return [ "QM_TRANSMOGRIFICATION_ALIGNMENT_LEFT", "QM_TRANSMOGRIFICATION_ALIGNMENT_RIGHT", "QM_transmogrify" ] + + + CONDITIONAL_NAMES = { + ... + "Cryptography_HAS_QUANTUM_TRANSMOGRIFICATION": ( + Cryptography_HAS_QUANTUM_TRANSMOGRIFICATION + ), } + Caveats ~~~~~~~ From aa49d1121f525ad6e3bdb1987311f906baa131b4 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sat, 8 Jul 2017 18:01:39 -0400 Subject: [PATCH 7/7] flake8 --- docs/development/c-bindings.rst | 6 +- .../hazmat/bindings/openssl/_conditional.py | 113 +++++++++--------- 2 files changed, 59 insertions(+), 60 deletions(-) diff --git a/docs/development/c-bindings.rst b/docs/development/c-bindings.rst index 9c69f4ee33dc..8a9bb6de339b 100644 --- a/docs/development/c-bindings.rst +++ b/docs/development/c-bindings.rst @@ -167,18 +167,18 @@ the necessarily type definitions are in place. Finally, add an entry to ``CONDITIONAL_NAMES`` with all of the things you want to conditionally export:: - def Cryptography_HAS_QUANTUM_TRANSMOGRIFICATION(): + def cryptography_has_quantum_transmogrification(): return [ "QM_TRANSMOGRIFICATION_ALIGNMENT_LEFT", "QM_TRANSMOGRIFICATION_ALIGNMENT_RIGHT", - "QM_transmogrify" + "QM_transmogrify", ] CONDITIONAL_NAMES = { ... "Cryptography_HAS_QUANTUM_TRANSMOGRIFICATION": ( - Cryptography_HAS_QUANTUM_TRANSMOGRIFICATION + cryptography_has_quantum_transmogrification ), } diff --git a/src/cryptography/hazmat/bindings/openssl/_conditional.py b/src/cryptography/hazmat/bindings/openssl/_conditional.py index bfac4fa89b1a..b4926d253b2e 100644 --- a/src/cryptography/hazmat/bindings/openssl/_conditional.py +++ b/src/cryptography/hazmat/bindings/openssl/_conditional.py @@ -5,8 +5,7 @@ from __future__ import absolute_import, division, print_function - -def Cryptography_HAS_CMS(): +def cryptography_has_cms(): return [ "BIO_new_CMS", "i2d_CMS_bio_stream", @@ -40,7 +39,7 @@ def Cryptography_HAS_CMS(): ] -def Cryptography_HAS_EC2M(): +def cryptography_has_ec2m(): return [ "EC_GF2m_simple_method", "EC_POINT_set_affine_coordinates_GF2m", @@ -52,31 +51,31 @@ def Cryptography_HAS_EC2M(): ] -def Cryptography_HAS_EC_1_0_2(): +def cryptography_has_ec_1_0_2(): return [ "EC_curve_nid2nist", ] -def Cryptography_HAS_SET_ECDH_AUTO(): +def cryptography_has_set_ecdh_auto(): return [ "SSL_CTX_set_ecdh_auto", ] -def Cryptography_HAS_ENGINE_CRYPTODEV(): +def cryptography_has_engine_cryptodev(): return [ "ENGINE_load_cryptodev" ] -def Cryptography_HAS_RSA_R_PKCS_DECODING_ERROR(): +def cryptography_has_rsa_r_pkcs_decoding_error(): return [ "RSA_R_PKCS_DECODING_ERROR" ] -def Cryptography_HAS_EGD(): +def cryptography_has_egd(): return [ "RAND_egd", "RAND_egd_bytes", @@ -84,13 +83,13 @@ def Cryptography_HAS_EGD(): ] -def Cryptography_HAS_RSA_OAEP_MD(): +def cryptography_has_rsa_oaep_md(): return [ "EVP_PKEY_CTX_set_rsa_oaep_md", ] -def Cryptography_HAS_SSL3_METHOD(): +def cryptography_has_ssl3_method(): return [ "SSLv3_method", "SSLv3_client_method", @@ -98,7 +97,7 @@ def Cryptography_HAS_SSL3_METHOD(): ] -def Cryptography_HAS_ALPN(): +def cryptography_has_alpn(): return [ "SSL_CTX_set_alpn_protos", "SSL_set_alpn_protos", @@ -107,7 +106,7 @@ def Cryptography_HAS_ALPN(): ] -def Cryptography_HAS_COMPRESSION(): +def cryptography_has_compression(): return [ "SSL_get_current_compression", "SSL_get_current_expansion", @@ -115,13 +114,13 @@ def Cryptography_HAS_COMPRESSION(): ] -def Cryptography_HAS_GET_SERVER_TMP_KEY(): +def cryptography_has_get_server_tmp_key(): return [ "SSL_get_server_tmp_key", ] -def Cryptography_HAS_102_VERIFICATION_ERROR_CODES(): +def cryptography_has_102_verification_error_codes(): return [ 'X509_V_ERR_SUITE_B_INVALID_VERSION', 'X509_V_ERR_SUITE_B_INVALID_ALGORITHM', @@ -135,7 +134,7 @@ def Cryptography_HAS_102_VERIFICATION_ERROR_CODES(): ] -def Cryptography_HAS_102_VERIFICATION_PARAMS(): +def cryptography_has_102_verification_params(): return [ "X509_V_FLAG_SUITEB_128_LOS_ONLY", "X509_V_FLAG_SUITEB_192_LOS", @@ -148,26 +147,26 @@ def Cryptography_HAS_102_VERIFICATION_PARAMS(): ] -def Cryptography_HAS_X509_V_FLAG_TRUSTED_FIRST(): +def cryptography_has_x509_v_flag_trusted_first(): return [ "X509_V_FLAG_TRUSTED_FIRST", ] -def Cryptography_HAS_X509_V_FLAG_PARTIAL_CHAIN(): +def cryptography_has_x509_v_flag_partial_chain(): return [ "X509_V_FLAG_PARTIAL_CHAIN", ] -def Cryptography_HAS_SET_CERT_CB(): +def cryptography_has_set_cert_cb(): return [ "SSL_CTX_set_cert_cb", "SSL_set_cert_cb", ] -def Cryptography_HAS_SSL_ST(): +def cryptography_has_ssl_st(): return [ "SSL_ST_BEFORE", "SSL_ST_OK", @@ -176,14 +175,14 @@ def Cryptography_HAS_SSL_ST(): ] -def Cryptography_HAS_TLS_ST(): +def cryptography_has_tls_st(): return [ "TLS_ST_BEFORE", "TLS_ST_OK", ] -def Cryptography_HAS_LOCKING_CALLBACKS(): +def cryptography_has_locking_callbacks(): return [ "CRYPTO_LOCK", "CRYPTO_UNLOCK", @@ -193,13 +192,13 @@ def Cryptography_HAS_LOCKING_CALLBACKS(): ] -def Cryptography_HAS_SCRYPT(): +def cryptography_has_scrypt(): return [ "EVP_PBE_scrypt", ] -def Cryptography_HAS_GENERIC_DTLS_METHOD(): +def cryptography_has_generic_dtls_method(): return [ "DTLS_method", "DTLS_server_method", @@ -207,19 +206,19 @@ def Cryptography_HAS_GENERIC_DTLS_METHOD(): ] -def Cryptography_HAS_EVP_PKEY_DHX(): +def cryptography_has_evp_pkey_dhx(): return [ "EVP_PKEY_DHX", ] -def Cryptography_HAS_MEM_FUNCTIONS(): +def cryptography_has_mem_functions(): return [ "Cryptography_CRYPTO_set_mem_functions", ] -def Cryptography_HAS_SCT(): +def cryptography_has_sct(): return [ "SCT_get_version", "SCT_get_log_entry_type", @@ -232,20 +231,20 @@ def Cryptography_HAS_SCT(): ] -def Cryptography_HAS_X509_STORE_CTX_GET_ISSUER(): +def cryptography_has_x509_store_ctx_get_issuer(): return [ "X509_STORE_get_get_issuer", "X509_STORE_set_get_issuer", ] -def Cryptography_HAS_X25519(): +def cryptography_has_x25519(): return [ "NID_X25519", ] -def Cryptography_HAS_EVP_PKEY_get_set_tls_encodedpoint(): +def cryptography_has_evp_pkey_get_set_tls_encodedpoint(): return [ "EVP_PKEY_get1_tls_encodedpoint", "EVP_PKEY_set1_tls_encodedpoint", @@ -258,48 +257,48 @@ def Cryptography_HAS_EVP_PKEY_get_set_tls_encodedpoint(): # when cffi supports #if in cdef. We use functions instead of just a dict of # lists so we can use coverage to measure which are used. CONDITIONAL_NAMES = { - "Cryptography_HAS_CMS": Cryptography_HAS_CMS, - "Cryptography_HAS_EC2M": Cryptography_HAS_EC2M, - "Cryptography_HAS_EC_1_0_2": Cryptography_HAS_EC_1_0_2, - "Cryptography_HAS_SET_ECDH_AUTO": Cryptography_HAS_SET_ECDH_AUTO, - "Cryptography_HAS_ENGINE_CRYPTODEV": Cryptography_HAS_ENGINE_CRYPTODEV, + "Cryptography_HAS_CMS": cryptography_has_cms, + "Cryptography_HAS_EC2M": cryptography_has_ec2m, + "Cryptography_HAS_EC_1_0_2": cryptography_has_ec_1_0_2, + "Cryptography_HAS_SET_ECDH_AUTO": cryptography_has_set_ecdh_auto, + "Cryptography_HAS_ENGINE_CRYPTODEV": cryptography_has_engine_cryptodev, "Cryptography_HAS_RSA_R_PKCS_DECODING_ERROR": ( - Cryptography_HAS_RSA_R_PKCS_DECODING_ERROR + cryptography_has_rsa_r_pkcs_decoding_error ), - "Cryptography_HAS_EGD": Cryptography_HAS_EGD, - "Cryptography_HAS_RSA_OAEP_MD": Cryptography_HAS_RSA_OAEP_MD, - "Cryptography_HAS_SSL3_METHOD": Cryptography_HAS_SSL3_METHOD, - "Cryptography_HAS_ALPN": Cryptography_HAS_ALPN, - "Cryptography_HAS_COMPRESSION": Cryptography_HAS_COMPRESSION, - "Cryptography_HAS_GET_SERVER_TMP_KEY": Cryptography_HAS_GET_SERVER_TMP_KEY, + "Cryptography_HAS_EGD": cryptography_has_egd, + "Cryptography_HAS_RSA_OAEP_MD": cryptography_has_rsa_oaep_md, + "Cryptography_HAS_SSL3_METHOD": cryptography_has_ssl3_method, + "Cryptography_HAS_ALPN": cryptography_has_alpn, + "Cryptography_HAS_COMPRESSION": cryptography_has_compression, + "Cryptography_HAS_GET_SERVER_TMP_KEY": cryptography_has_get_server_tmp_key, "Cryptography_HAS_102_VERIFICATION_ERROR_CODES": ( - Cryptography_HAS_102_VERIFICATION_ERROR_CODES + cryptography_has_102_verification_error_codes ), "Cryptography_HAS_102_VERIFICATION_PARAMS": ( - Cryptography_HAS_102_VERIFICATION_PARAMS + cryptography_has_102_verification_params ), "Cryptography_HAS_X509_V_FLAG_TRUSTED_FIRST": ( - Cryptography_HAS_X509_V_FLAG_TRUSTED_FIRST + cryptography_has_x509_v_flag_trusted_first ), "Cryptography_HAS_X509_V_FLAG_PARTIAL_CHAIN": ( - Cryptography_HAS_X509_V_FLAG_PARTIAL_CHAIN + cryptography_has_x509_v_flag_partial_chain ), - "Cryptography_HAS_SET_CERT_CB": Cryptography_HAS_SET_CERT_CB, - "Cryptography_HAS_SSL_ST": Cryptography_HAS_SSL_ST, - "Cryptography_HAS_TLS_ST": Cryptography_HAS_TLS_ST, - "Cryptography_HAS_LOCKING_CALLBACKS": Cryptography_HAS_LOCKING_CALLBACKS, - "Cryptography_HAS_SCRYPT": Cryptography_HAS_SCRYPT, + "Cryptography_HAS_SET_CERT_CB": cryptography_has_set_cert_cb, + "Cryptography_HAS_SSL_ST": cryptography_has_ssl_st, + "Cryptography_HAS_TLS_ST": cryptography_has_tls_st, + "Cryptography_HAS_LOCKING_CALLBACKS": cryptography_has_locking_callbacks, + "Cryptography_HAS_SCRYPT": cryptography_has_scrypt, "Cryptography_HAS_GENERIC_DTLS_METHOD": ( - Cryptography_HAS_GENERIC_DTLS_METHOD + cryptography_has_generic_dtls_method ), - "Cryptography_HAS_EVP_PKEY_DHX": Cryptography_HAS_EVP_PKEY_DHX, - "Cryptography_HAS_MEM_FUNCTIONS": Cryptography_HAS_MEM_FUNCTIONS, - "Cryptography_HAS_SCT": Cryptography_HAS_SCT, + "Cryptography_HAS_EVP_PKEY_DHX": cryptography_has_evp_pkey_dhx, + "Cryptography_HAS_MEM_FUNCTIONS": cryptography_has_mem_functions, + "Cryptography_HAS_SCT": cryptography_has_sct, "Cryptography_HAS_X509_STORE_CTX_GET_ISSUER": ( - Cryptography_HAS_X509_STORE_CTX_GET_ISSUER + cryptography_has_x509_store_ctx_get_issuer ), - "Cryptography_HAS_X25519": Cryptography_HAS_X25519, + "Cryptography_HAS_X25519": cryptography_has_x25519, "Cryptography_HAS_EVP_PKEY_get_set_tls_encodedpoint": ( - Cryptography_HAS_EVP_PKEY_get_set_tls_encodedpoint + cryptography_has_evp_pkey_get_set_tls_encodedpoint ), }