unique_ptr和OpenSSL的STACK_OF(X509)*
unique_ptr and OpenSSL's STACK_OF(X509)*
我使用一些using
语句和unique_ptr
与OpenSSL一起工作,正如另一个问题所建议的那样。如果没有goto语句,代码会变得非常难看,我也不太喜欢goto语句。
using BIO_ptr = std::unique_ptr<BIO, decltype(&::BIO_free)>;
using X509_ptr = std::unique_ptr<X509, decltype(&::X509_free)>;
using EVP_PKEY_ptr = std::unique_ptr<EVP_PKEY, decltype(&::EVP_PKEY_free)>;
using PKCS7_ptr = std::unique_ptr<PKCS7, decltype(&::PKCS7_free)>;
...
BIO_ptr tbio(BIO_new_file(some_filename, "r"), ::BIO_free);
现在我需要一个STACK_OF(X509)
,我不知道,如果这也可能与unique_ptr
。我正在寻找类似于下面的东西,但这是不工作。
using STACK_OF_X509_ptr = std::unique_ptr<STACK_OF(X509), decltype(&::sk_X509_free)>;
我还尝试了函子:
struct StackX509Deleter {
void operator()(STACK_OF(X509) *ptr) {
sk_X509_free(ptr);
}
};
using STACK_OF_X509_ptr = std::unique_ptr<STACK_OF(X509), StackX509Deleter>;
STACK_OF_X509_ptr chain(loadIntermediate(cert.string()));
编译器接受此参数并运行应用程序。只有一个问题:在上面显示的其他unique_ptrs
中,我总是指定了第二个参数,所以我敢打赌我遗漏了一些东西:
STACK_OF_X509_ptr chain(loadIntermediate(cert.string()), ??????);
如何使用c++ unique_ptr
和OpenSSL的STACK_OF(X509)*
?
我定义了一个正则函数:
void stackOfX509Deleter(STACK_OF(X509) *ptr) {
sk_X509_free(ptr);
}
然后我在我的代码中使用它:
using STACK_OF_X509_ptr = std::unique_ptr<STACK_OF(X509),
decltype(&stackOfX509Deleter)>;
STACK_OF_X509_ptr chain(loadIntermediate(cert.string()),
stackOfX509Deleter);
相关文章:
- Usages of std::move
- 如何在C++中使用X509证书模在令牌中查找私钥
- 使用 [] 运算符时"binding reference of type discards qualifiers"
- 如何处理 c++ 中类实现中的"invalid use of non-static data member"?
- 具有变量Number of Arguments的std::函数的矢量
- Capacity of a deque
- Deprecation of _writeBarrier()
- constexpr begin of a std::array
- 如何调整 std::vector of Eigen::MatrixXd 的大小
- C++ "error: invalid use of void expression"
- 我看到"use of undeclared identifier"错误,有人可以告诉我如何解决它吗?
- 赛通"Cannot take address of memoryview slice"
- C++ Version Of Double.longBitsToDouble
- 收到错误"invalid use of non-static data member 'stu::n' "
- C++ Usage of AsyncCallback
- 错误:"Left of getValue must have class/struct/union"
- Centos7 g++ "to_string is not in a member of std"
- 在C++中使用 Catch 测试框架编译错误"error: expected ';' at end of declaration list"
- 传递 std::vector of std::shared_ptr,而不是更新对象
- C++/SDL "initial value of reference to a non-const must be an lvalue"