Dim*_*las 3 c openssl deprecated
在我的 C 项目中,我将 OpenSSl 库 1.0.2g 更新为较新的库(1.1.x 版本),同时编译代码时抛出以下警告:
\n\n\n\n\nmain.c:40:3: 警告: \xe2\x80\x98OPENSSL_config\xe2\x80\x99 已弃用 [-Wdeprecated-declarations]\n OPENSSL_config(NULL);
\n
抛出此错误的代码是:
\n\n#include <stdio.h>\n\n// Openssl\n#include <openssl/conf.h>\n#include <openssl/evp.h>\n#include <openssl/err.h>\n\nint main(int argc, char *argv[]) {\n /* Load the human readable error strings for libcrypto */\n ERR_load_crypto_strings();\n /* Load all digest and cipher algorithms */\n OpenSSL_add_all_algorithms();\n /* Load config file, and other important initialisation */\n OPENSSL_config(NULL);\n\n //Come code here\n\n EVP_cleanup();\n CRYPTO_cleanup_all_ex_data();\n ERR_free_strings();\n return 0;\n}\nRun Code Online (Sandbox Code Playgroud)\n\n因此,根据最佳实践,我应该避免对已弃用的函数使用替代方法,在我的情况下我应该使用哪一种?
\nOPENSSL_config说明了一切:
此函数已被弃用,应避免使用。应用程序应该在初始化期间(即启动任何线程之前)调用 CONF_modules_load()。
此外,SSL_load_error_strings和OpenSSL_add_all_algorithms也已被弃用。
对于 openssl >= 1.1,您可以删除上面的整个启动和清理代码,因为不再需要它。现在这一切都会自动为您完成。
| 归档时间: |
|
| 查看次数: |
2683 次 |
| 最近记录: |