Codemod folly::make_unique to std::make_unique
[folly.git] / folly / ssl / OpenSSLCertUtils.cpp
index d06cdac756b0645e71bb619cfd407fd69b39a8dc..b1bdf180e737e8dbdfa5e4f1d0566d38e905aafa 100644 (file)
  * limitations under the License.
  */
 #include <folly/ssl/OpenSSLCertUtils.h>
-#include <folly/String.h>
-#include <folly/io/async/ssl/OpenSSLPtrTypes.h>
-
-#include <openssl/x509.h>
-#include <openssl/x509v3.h>
 
 #include <folly/ScopeGuard.h>
+#include <folly/String.h>
+#include <folly/ssl/OpenSSLPtrTypes.h>
 
 namespace folly {
 namespace ssl {
@@ -46,7 +43,7 @@ Optional<std::string> OpenSSLCertUtils::getCommonName(X509& x509) {
     return none;
   }
 
-  auto cnData = reinterpret_cast<const char*>(ASN1_STRING_data(cnAsn));
+  auto cnData = reinterpret_cast<const char*>(ASN1_STRING_get0_data(cnAsn));
   auto cnLen = ASN1_STRING_length(cnAsn);
   if (!cnData || cnLen <= 0) {
     return none;
@@ -72,8 +69,8 @@ std::vector<std::string> OpenSSLCertUtils::getSubjectAltNames(X509& x509) {
     if (!genName || genName->type != GEN_DNS) {
       continue;
     }
-    auto nameData =
-        reinterpret_cast<const char*>(ASN1_STRING_data(genName->d.dNSName));
+    auto nameData = reinterpret_cast<const char*>(
+        ASN1_STRING_get0_data(genName->d.dNSName));
     auto nameLen = ASN1_STRING_length(genName->d.dNSName);
     if (!nameData || nameLen <= 0) {
       continue;
@@ -128,17 +125,19 @@ folly::Optional<std::string> OpenSSLCertUtils::toString(X509& x509) {
     throw std::runtime_error("Cannot allocate bio");
   }
 
-  if (X509_print_ex(
-          in.get(),
-          &x509,
-          XN_FLAG_ONELINE,
-          X509_FLAG_NO_HEADER | /* A few bytes of cert and data */
-              X509_FLAG_NO_PUBKEY | /* Public key */
-              X509_FLAG_NO_IDS | /* Issuer/subject IDs */
-              X509_FLAG_NO_AUX | /* Auxiliary info? */
-              X509_FLAG_NO_SIGDUMP | /* Prints the signature */
-              X509_FLAG_NO_SIGNAME /* Signature algorithms */
-          ) > 0) {
+  int flags = 0;
+
+  flags |= X509_FLAG_NO_HEADER | /* A few bytes of cert and data */
+      X509_FLAG_NO_PUBKEY | /* Public key */
+      X509_FLAG_NO_AUX | /* Auxiliary info? */
+      X509_FLAG_NO_SIGDUMP | /* Prints the signature */
+      X509_FLAG_NO_SIGNAME; /* Signature algorithms */
+
+#ifdef X509_FLAG_NO_IDS
+  flags |= X509_FLAG_NO_IDS; /* Issuer/subject IDs */
+#endif
+
+  if (X509_print_ex(in.get(), &x509, XN_FLAG_ONELINE, flags) > 0) {
     char* bioData = nullptr;
     size_t bioLen = BIO_get_mem_data(in.get(), &bioData);
     return std::string(bioData, bioLen);
@@ -160,8 +159,6 @@ std::string OpenSSLCertUtils::getDateTimeStr(const ASN1_TIME* time) {
     return "";
   }
 
-  std::array<char, 32> buf;
-
   auto bio = BioUniquePtr(BIO_new(BIO_s_mem()));
   if (bio == nullptr) {
     throw std::runtime_error("Cannot allocate bio");