错误:“无效使用不完整类型‘RSA {aka struct rsa_st}";在 OpenSSL 1.1.0 中 [英] Error: "invalid use of incomplete type ‘RSA {aka struct rsa_st}" in OpenSSL 1.1.0

查看:39
本文介绍了错误:“无效使用不完整类型‘RSA {aka struct rsa_st}";在 OpenSSL 1.1.0 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有旧代码是为了链接旧版本的 openssl.此代码的一部分从 PEM 文件加载密钥,并尝试通过使用以下代码来了解此密钥是私钥还是公钥:

I have old code that was written to link against an old version of openssl. Part of this code loads a key from a PEM file, and tries to understand whether this key is a private or public key, by using the following code:

if( (prv->p==0 || prv->q==0) ) {
    // This is not a private key!
    throw error("No private key for decryption");
}

使用最新版本的 openssl,这(合理地)无法编译:

With the latest version of openssl, this (justifiably) doesn't compile:

crypto.cpp: In function ‘key* decrypt_header(file_t, RSA*)’:
crypto.cpp:158:13: error: invalid use of incomplete type ‘RSA {aka struct rsa_st}’
     if( (prv->p==0 || prv->q==0) ) {
             ^~

我知道直接访问结构体的私有成员已被函数取代,但我很难弄清楚是哪个函数.

I understand that direct access to the struct's private members was replaced with a function, but I am having a hard time figuring out which function that is.

推荐答案

crypto.cpp:158:13: error: invalid use of incomplete type ‘RSA {aka struct rsa_st}’
     if( (prv->p==0 || prv->q==0) ) {
             ^~

如您所知,OpenSSL 1.1.0 更改了许多结构体成员的可见性.您不能再直接访问成员.相反,您必须使用 getter 和 setter 函数.

As you are aware, OpenSSL 1.1.0 changed the visibility of a lot of struct members. You can no longer access the members directly. Instead, you have to use getter and setter functions.

尝试RSA_get0_factors.get0 表示引用计数递增.不要不要 BN_free 他们.

Try RSA_get0_factors. The get0 means the reference counts are not incremented. Do not BN_free them.

void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q);

<小时>

如果代码支持 OpenSSL 的多个版本,那么您将需要保护,因为 RSA_get0_factors 适用于 OpenSSL 1.1.0 及更高版本.也许像下面这样.另请参阅OPENSSL_VERSION_NUMBER 手册页.


If the code supports multiple versions of OpenSSL, then you will need a guard because RSA_get0_factors is for OpenSSL 1.1.0 and above. Maybe something like the following. Also see OPENSSL_VERSION_NUMBER man page.

#include <openssl/opensslv.h>

#if OPENSSL_VERSION_NUMBER < 0x10100000L

    /* OpenSSL 1.0.2 and below (old code) */

#else

    /* OpenSSL 1.1.0 and above (new code) */

#endif

这篇关于错误:“无效使用不完整类型‘RSA {aka struct rsa_st}";在 OpenSSL 1.1.0 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆