<legend id='zoumz'><style id='zoumz'><dir id='zoumz'><q id='zoumz'></q></dir></style></legend>
<tfoot id='zoumz'></tfoot>

<small id='zoumz'></small><noframes id='zoumz'>

    <i id='zoumz'><tr id='zoumz'><dt id='zoumz'><q id='zoumz'><span id='zoumz'><b id='zoumz'><form id='zoumz'><ins id='zoumz'></ins><ul id='zoumz'></ul><sub id='zoumz'></sub></form><legend id='zoumz'></legend><bdo id='zoumz'><pre id='zoumz'><center id='zoumz'></center></pre></bdo></b><th id='zoumz'></th></span></q></dt></tr></i><div id='zoumz'><tfoot id='zoumz'></tfoot><dl id='zoumz'><fieldset id='zoumz'></fieldset></dl></div>

      <bdo id='zoumz'></bdo><ul id='zoumz'></ul>

      1. unique_ptr 和 OpenSSL 的 STACK_OF(X509)*

        unique_ptr and OpenSSL#39;s STACK_OF(X509)*(unique_ptr 和 OpenSSL 的 STACK_OF(X509)*)
        1. <small id='YVwVt'></small><noframes id='YVwVt'>

              <tbody id='YVwVt'></tbody>

                <bdo id='YVwVt'></bdo><ul id='YVwVt'></ul>
                <i id='YVwVt'><tr id='YVwVt'><dt id='YVwVt'><q id='YVwVt'><span id='YVwVt'><b id='YVwVt'><form id='YVwVt'><ins id='YVwVt'></ins><ul id='YVwVt'></ul><sub id='YVwVt'></sub></form><legend id='YVwVt'></legend><bdo id='YVwVt'><pre id='YVwVt'><center id='YVwVt'></center></pre></bdo></b><th id='YVwVt'></th></span></q></dt></tr></i><div id='YVwVt'><tfoot id='YVwVt'></tfoot><dl id='YVwVt'><fieldset id='YVwVt'></fieldset></dl></div>
              • <legend id='YVwVt'><style id='YVwVt'><dir id='YVwVt'><q id='YVwVt'></q></dir></style></legend>

                  <tfoot id='YVwVt'></tfoot>
                  本文介绍了unique_ptr 和 OpenSSL 的 STACK_OF(X509)*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我使用一些 using 语句和 unique_ptr 来处理 OpenSSL,如 在另一个问题中建议.否则,代码会变得非常丑陋,而且我不太喜欢 goto 语句.

                  I use some using statements and unique_ptr to work with OpenSSL, as suggested in another question. Without, code becomes really ugly and I am not so much a fan of goto statements.

                  到目前为止,我已经尽可能地更改了我的代码.以下是我使用的示例:

                  So far I have changed my code as far as possible. Here are examples, what I use:

                  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 是否也可以.我正在寻找类似于下面的内容,但这不起作用.

                  Now I have the need of a STACK_OF(X509) and I do not know, if this is also possible with unique_ptr. I am looking for something similar to below, but this is not working.

                  using STACK_OF_X509_ptr = std::unique_ptr<STACK_OF(X509), decltype(&::sk_X509_free)>;
                  

                  我也尝试过 Functor:

                  I also tried the Functor:

                  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 中,我总是指定了第二个参数,所以我打赌我遗漏了一些东西:

                  The compiler accepts this and the application runs. Just one question: In other unique_ptrs as shown above, I always had specified a second argument, so I bet I am missing something:

                  STACK_OF_X509_ptr chain(loadIntermediate(cert.string()),  ??????);
                  

                  我如何使用 C++ unique_ptr 和 OpenSSL 的 STACK_OF(X509)*?

                  How do I use C++ unique_ptr and OpenSSL's STACK_OF(X509)*?

                  推荐答案

                  我定义了一个正则函数:

                  I defined a regular function:

                  void stackOfX509Deleter(STACK_OF(X509) *ptr) {
                      sk_X509_free(ptr);
                  }
                  

                  然后我在我的代码中使用它:

                  Then I use it in my code:

                  using STACK_OF_X509_ptr = std::unique_ptr<STACK_OF(X509),
                      decltype(&stackOfX509Deleter)>;
                  
                  STACK_OF_X509_ptr chain(loadIntermediate(cert.string()),
                                      stackOfX509Deleter);
                  

                  这篇关于unique_ptr 和 OpenSSL 的 STACK_OF(X509)*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)
                  How should a size-limited stl-like container be implemented?(应该如何实现大小受限的 stl 类容器?)
                  Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)
                  STL BigInt class implementation(STL BigInt 类实现)
                  Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)
                  Move list element to the end in STL(在 STL 中将列表元素移动到末尾)
                  • <i id='yb5L3'><tr id='yb5L3'><dt id='yb5L3'><q id='yb5L3'><span id='yb5L3'><b id='yb5L3'><form id='yb5L3'><ins id='yb5L3'></ins><ul id='yb5L3'></ul><sub id='yb5L3'></sub></form><legend id='yb5L3'></legend><bdo id='yb5L3'><pre id='yb5L3'><center id='yb5L3'></center></pre></bdo></b><th id='yb5L3'></th></span></q></dt></tr></i><div id='yb5L3'><tfoot id='yb5L3'></tfoot><dl id='yb5L3'><fieldset id='yb5L3'></fieldset></dl></div>
                    • <bdo id='yb5L3'></bdo><ul id='yb5L3'></ul>
                      <legend id='yb5L3'><style id='yb5L3'><dir id='yb5L3'><q id='yb5L3'></q></dir></style></legend>

                            <tbody id='yb5L3'></tbody>

                          <small id='yb5L3'></small><noframes id='yb5L3'>

                          <tfoot id='yb5L3'></tfoot>