Remove fillins/openssl_util

The only user of the tiny utility class to clear the error stack
was verify_certificate_chain, which can have it in it's anonymous
namespace.

It was however, used to great effect as a horrible dirty cheat to get
us openssl/base.h during the conversion. That time is past, so just
let us include <openssl/base.h> normally, and get rid of this.

Bug: 668
Change-Id: Ie8537d5b1d6789acb35182f3d781f7505ad79109
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/64188
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
Auto-Submit: Bob Beck <bbe@google.com>
diff --git a/pki/cert_error_id.h b/pki/cert_error_id.h
index a9d7b54..d325b1b 100644
--- a/pki/cert_error_id.h
+++ b/pki/cert_error_id.h
@@ -5,8 +5,7 @@
 #ifndef BSSL_PKI_CERT_ERROR_ID_H_
 #define BSSL_PKI_CERT_ERROR_ID_H_
 
-#include "fillins/openssl_util.h"
-
+#include <openssl/base.h>
 
 namespace bssl {
 
diff --git a/pki/cert_error_params.cc b/pki/cert_error_params.cc
index 5d45aa8..8d0ab42 100644
--- a/pki/cert_error_params.cc
+++ b/pki/cert_error_params.cc
@@ -3,11 +3,11 @@
 // found in the LICENSE file.
 
 #include "cert_error_params.h"
-#include "fillins/openssl_util.h"
 
 #include <memory>
 
 #include <openssl/base.h>
+
 #include "input.h"
 #include "string_util.h"
 
diff --git a/pki/cert_error_params.h b/pki/cert_error_params.h
index 5a2e9dc..474ba70 100644
--- a/pki/cert_error_params.h
+++ b/pki/cert_error_params.h
@@ -7,9 +7,8 @@
 
 #include <memory>
 #include <string>
-#include "fillins/openssl_util.h"
 
-
+#include <openssl/base.h>
 
 namespace bssl {
 
diff --git a/pki/cert_errors.h b/pki/cert_errors.h
index daaf01f..8f16e11 100644
--- a/pki/cert_errors.h
+++ b/pki/cert_errors.h
@@ -5,7 +5,6 @@
 // ----------------------------
 // Overview of error design
 // ----------------------------
-#include "fillins/openssl_util.h"
 //
 // Certificate path building/validation/parsing may emit a sequence of errors
 // and warnings.
@@ -50,6 +49,7 @@
 #include <memory>
 #include <vector>
 
+#include <openssl/base.h>
 
 #include "cert_error_id.h"
 #include "parsed_certificate.h"
diff --git a/pki/cert_issuer_source.h b/pki/cert_issuer_source.h
index 47d4b87..7de0fa4 100644
--- a/pki/cert_issuer_source.h
+++ b/pki/cert_issuer_source.h
@@ -7,8 +7,8 @@
 
 #include <memory>
 #include <vector>
-#include "fillins/openssl_util.h"
 
+#include <openssl/base.h>
 
 #include "parsed_certificate.h"
 
diff --git a/pki/cert_issuer_source_static.h b/pki/cert_issuer_source_static.h
index 2ab138a..1e60934 100644
--- a/pki/cert_issuer_source_static.h
+++ b/pki/cert_issuer_source_static.h
@@ -6,8 +6,8 @@
 #define BSSL_PKI_CERT_ISSUER_SOURCE_STATIC_H_
 
 #include <unordered_map>
-#include "fillins/openssl_util.h"
 
+#include <openssl/base.h>
 
 #include "cert_issuer_source.h"
 
diff --git a/pki/certificate_policies.h b/pki/certificate_policies.h
index 340ed63..e044cde 100644
--- a/pki/certificate_policies.h
+++ b/pki/certificate_policies.h
@@ -6,8 +6,6 @@
 #define BSSL_PKI_CERTIFICATE_POLICIES_H_
 
 #include <stdint.h>
-#include "fillins/openssl_util.h"
-
 #include <vector>
 
 
diff --git a/pki/common_cert_errors.h b/pki/common_cert_errors.h
index 5e3f1b9..43f2408 100644
--- a/pki/common_cert_errors.h
+++ b/pki/common_cert_errors.h
@@ -5,7 +5,7 @@
 #ifndef BSSL_PKI_COMMON_CERT_ERRORS_H_
 #define BSSL_PKI_COMMON_CERT_ERRORS_H_
 
-#include "fillins/openssl_util.h"
+#include <openssl/base.h>
 
 #include "cert_errors.h"
 
diff --git a/pki/crl.h b/pki/crl.h
index 0d36f22..445c6e8 100644
--- a/pki/crl.h
+++ b/pki/crl.h
@@ -5,9 +5,10 @@
 #ifndef BSSL_PKI_CRL_H_
 #define BSSL_PKI_CRL_H_
 
-#include "fillins/openssl_util.h"
-
 #include <optional>
+
+#include <openssl/base.h>
+
 #include "general_names.h"
 #include "input.h"
 #include "parse_values.h"
diff --git a/pki/encode_values.h b/pki/encode_values.h
index b3bc0be..030c864 100644
--- a/pki/encode_values.h
+++ b/pki/encode_values.h
@@ -7,9 +7,8 @@
 
 #include <stddef.h>
 #include <stdint.h>
-#include "fillins/openssl_util.h"
 
-
+#include <openssl/base.h>
 
 namespace bssl::der {
 
diff --git a/pki/extended_key_usage.h b/pki/extended_key_usage.h
index 59e66c4..f3b9d02 100644
--- a/pki/extended_key_usage.h
+++ b/pki/extended_key_usage.h
@@ -6,8 +6,8 @@
 #define BSSL_PKI_EXTENDED_KEY_USAGE_H_
 
 #include <vector>
-#include "fillins/openssl_util.h"
 
+#include <openssl/base.h>
 
 #include "input.h"
 
diff --git a/pki/fillins/openssl_util.cc b/pki/fillins/openssl_util.cc
deleted file mode 100644
index 6c58169..0000000
--- a/pki/fillins/openssl_util.cc
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright 2023 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "openssl_util.h"
-
-#include <openssl/err.h>
-
-namespace bssl {
-
-namespace fillins {
-
-OpenSSLErrStackTracer::OpenSSLErrStackTracer() {}
-
-OpenSSLErrStackTracer::~OpenSSLErrStackTracer() { ERR_clear_error(); }
-
-}  // namespace fillins
-
-}  // namespace bssl
diff --git a/pki/fillins/openssl_util.h b/pki/fillins/openssl_util.h
deleted file mode 100644
index f193a51..0000000
--- a/pki/fillins/openssl_util.h
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2023 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef BSSL_FILLINS_OPENSSL_UTIL_H
-#define BSSL_FILLINS_OPENSSL_UTIL_H
-
-#include <openssl/base.h>
-
-#include <string>
-
-namespace bssl {
-
-namespace fillins {
-
-// Place an instance of this class on the call stack to automatically clear
-// the OpenSSL error stack on function exit.
-class OPENSSL_EXPORT OpenSSLErrStackTracer {
- public:
-  OpenSSLErrStackTracer();
-  ~OpenSSLErrStackTracer();
-};
-
-}  // namespace fillins
-
-}  // namespace bssl
-
-#endif  // BSSL_FILLINS_OPENSSL_UTIL_H
diff --git a/pki/general_names.h b/pki/general_names.h
index 426859c..300fed9 100644
--- a/pki/general_names.h
+++ b/pki/general_names.h
@@ -8,7 +8,8 @@
 #include <memory>
 #include <string_view>
 #include <vector>
-#include "fillins/openssl_util.h"
+
+#include <openssl/base.h>
 
 
 #include "cert_error_id.h"
diff --git a/pki/input.h b/pki/input.h
index cd5326f..2f61a33 100644
--- a/pki/input.h
+++ b/pki/input.h
@@ -7,12 +7,11 @@
 
 #include <stddef.h>
 #include <stdint.h>
-#include "fillins/openssl_util.h"
 
 #include <string>
 #include <string_view>
 
-
+#include <openssl/base.h>
 #include <openssl/span.h>
 
 namespace bssl::der {
diff --git a/pki/ip_util.h b/pki/ip_util.h
index 64ea719..3bcc7df 100644
--- a/pki/ip_util.h
+++ b/pki/ip_util.h
@@ -5,7 +5,7 @@
 #ifndef BSSL_PKI_IP_UTIL_H_
 #define BSSL_PKI_IP_UTIL_H_
 
-#include "fillins/openssl_util.h"
+#include <openssl/base.h>
 
 #include "input.h"
 
diff --git a/pki/name_constraints.h b/pki/name_constraints.h
index bf3d3c6..5a55d3d 100644
--- a/pki/name_constraints.h
+++ b/pki/name_constraints.h
@@ -6,8 +6,8 @@
 #define BSSL_PKI_NAME_CONSTRAINTS_H_
 
 #include <memory>
-#include "fillins/openssl_util.h"
 
+#include <openssl/base.h>
 
 #include "general_names.h"
 
diff --git a/pki/ocsp.h b/pki/ocsp.h
index 334da79..213ec26 100644
--- a/pki/ocsp.h
+++ b/pki/ocsp.h
@@ -6,12 +6,12 @@
 #define BSSL_PKI_OCSP_H_
 
 #include <memory>
+#include <optional>
 #include <string>
 #include <vector>
-#include "fillins/openssl_util.h"
 
+#include <openssl/base.h>
 
-#include <optional>
 #include "input.h"
 #include "ocsp_revocation_status.h"
 #include "ocsp_verify_result.h"
diff --git a/pki/ocsp_verify_result.h b/pki/ocsp_verify_result.h
index 4f5b9e2..1e07f1a 100644
--- a/pki/ocsp_verify_result.h
+++ b/pki/ocsp_verify_result.h
@@ -5,7 +5,7 @@
 #ifndef BSSL_PKI_OCSP_VERIFY_RESULT_H_
 #define BSSL_PKI_OCSP_VERIFY_RESULT_H_
 
-#include "fillins/openssl_util.h"
+#include <openssl/base.h>
 
 #include "ocsp_revocation_status.h"
 
diff --git a/pki/parse_certificate.cc b/pki/parse_certificate.cc
index ab06c93..8335f2f 100644
--- a/pki/parse_certificate.cc
+++ b/pki/parse_certificate.cc
@@ -3,11 +3,12 @@
 // found in the LICENSE file.
 
 #include "parse_certificate.h"
-#include "fillins/openssl_util.h"
-
-#include <utility>
 
 #include <optional>
+#include <utility>
+
+#include <openssl/base.h>
+
 #include "cert_error_params.h"
 #include "cert_errors.h"
 #include "general_names.h"
diff --git a/pki/parse_certificate.h b/pki/parse_certificate.h
index d6171de..2a85654 100644
--- a/pki/parse_certificate.h
+++ b/pki/parse_certificate.h
@@ -6,14 +6,14 @@
 #define BSSL_PKI_PARSE_CERTIFICATE_H_
 
 #include <stdint.h>
-#include "fillins/openssl_util.h"
 
 #include <map>
 #include <memory>
+#include <optional>
 #include <vector>
 
+#include <openssl/base.h>
 
-#include <optional>
 #include "general_names.h"
 #include "input.h"
 #include "parse_values.h"
diff --git a/pki/parse_name.h b/pki/parse_name.h
index e67b2e2..aea2f76 100644
--- a/pki/parse_name.h
+++ b/pki/parse_name.h
@@ -6,8 +6,8 @@
 #define BSSL_PKI_PARSE_NAME_H_
 
 #include <vector>
-#include "fillins/openssl_util.h"
 
+#include <openssl/base.h>
 
 #include "input.h"
 #include "parser.h"
diff --git a/pki/parse_values.h b/pki/parse_values.h
index f9b7470..28ca49f 100644
--- a/pki/parse_values.h
+++ b/pki/parse_values.h
@@ -6,10 +6,11 @@
 #define BSSL_DER_PARSE_VALUES_H_
 
 #include <stdint.h>
-#include "fillins/openssl_util.h"
-
 
 #include <optional>
+
+#include <openssl/base.h>
+
 #include "input.h"
 
 namespace bssl::der {
diff --git a/pki/parsed_certificate.h b/pki/parsed_certificate.h
index 9d72e62..bcc0fd9 100644
--- a/pki/parsed_certificate.h
+++ b/pki/parsed_certificate.h
@@ -7,12 +7,11 @@
 
 #include <map>
 #include <memory>
+#include <optional>
 #include <vector>
-#include "fillins/openssl_util.h"
-
 
 #include <openssl/base.h>
-#include <optional>
+
 #include "certificate_policies.h"
 #include "input.h"
 #include "parse_certificate.h"
diff --git a/pki/parser.h b/pki/parser.h
index 81a0d02..94065e5 100644
--- a/pki/parser.h
+++ b/pki/parser.h
@@ -6,11 +6,12 @@
 #define BSSL_DER_PARSER_H_
 
 #include <stdint.h>
-#include "fillins/openssl_util.h"
 
-
-#include <openssl/bytestring.h>
 #include <optional>
+
+#include <openssl/base.h>
+#include <openssl/bytestring.h>
+
 #include "input.h"
 #include "tag.h"
 
diff --git a/pki/path_builder.h b/pki/path_builder.h
index 48f0666..9aae757 100644
--- a/pki/path_builder.h
+++ b/pki/path_builder.h
@@ -7,8 +7,8 @@
 
 #include <memory>
 #include <vector>
-#include "fillins/openssl_util.h"
 
+#include <openssl/base.h>
 
 #include "cert_errors.h"
 #include "input.h"
diff --git a/pki/pem.h b/pki/pem.h
index 9ec5519..1fd28fb 100644
--- a/pki/pem.h
+++ b/pki/pem.h
@@ -6,14 +6,12 @@
 #define BSSL_PKI_PEM_H_
 
 #include <stddef.h>
-#include "fillins/openssl_util.h"
 
 #include <string>
+#include <string_view>
 #include <vector>
 
-#include <string_view>
-
-
+#include <openssl/base.h>
 
 namespace bssl {
 
diff --git a/pki/revocation_util.h b/pki/revocation_util.h
index 273c6fe..5b20f4c 100644
--- a/pki/revocation_util.h
+++ b/pki/revocation_util.h
@@ -5,11 +5,10 @@
 #ifndef BSSL_PKI_REVOCATION_UTIL_H_
 #define BSSL_PKI_REVOCATION_UTIL_H_
 
-#include "fillins/openssl_util.h"
-
+#include <cstdint>
 #include <optional>
 
-#include <cstdint>
+#include <openssl/base.h>
 
 namespace bssl {
 
diff --git a/pki/signature_algorithm.h b/pki/signature_algorithm.h
index 1cec208..72c8ea6 100644
--- a/pki/signature_algorithm.h
+++ b/pki/signature_algorithm.h
@@ -6,12 +6,12 @@
 #define BSSL_PKI_SIGNATURE_ALGORITHM_H_
 
 #include <stdint.h>
-#include "fillins/openssl_util.h"
 
-
-#include <openssl/evp.h>
 #include <optional>
 
+#include <openssl/base.h>
+#include <openssl/evp.h>
+
 namespace bssl {
 
 namespace der {
diff --git a/pki/signature_verify_cache.h b/pki/signature_verify_cache.h
index 83f99ac..640132e 100644
--- a/pki/signature_verify_cache.h
+++ b/pki/signature_verify_cache.h
@@ -5,8 +5,8 @@
 #ifndef BSSL_PKI_SIGNATURE_VERIFY_CACHE_H_
 #define BSSL_PKI_SIGNATURE_VERIFY_CACHE_H_
 
+#include <openssl/base.h>
 #include <string>
-#include "fillins/openssl_util.h"
 
 namespace bssl {
 
diff --git a/pki/simple_path_builder_delegate.h b/pki/simple_path_builder_delegate.h
index 0face8e..ab844ae 100644
--- a/pki/simple_path_builder_delegate.h
+++ b/pki/simple_path_builder_delegate.h
@@ -6,8 +6,8 @@
 #define BSSL_PKI_SIMPLE_PATH_BUILDER_DELEGATE_H_
 
 #include <stddef.h>
-#include "fillins/openssl_util.h"
 
+#include <openssl/base.h>
 
 #include "path_builder.h"
 #include "signature_algorithm.h"
diff --git a/pki/string_util.h b/pki/string_util.h
index c93beaa..b238c29 100644
--- a/pki/string_util.h
+++ b/pki/string_util.h
@@ -5,15 +5,12 @@
 #ifndef BSSL_PKI_STRING_UTIL_H_
 #define BSSL_PKI_STRING_UTIL_H_
 
-#include "fillins/openssl_util.h"
-
-
-#include <stdint.h>
-
 #include <cstdint>
 #include <string_view>
 #include <vector>
 
+#include <openssl/base.h>
+
 namespace bssl::string_util {
 
 // Returns true if the characters in |str| are all ASCII, false otherwise.
diff --git a/pki/tag.h b/pki/tag.h
index a2c3b4f..683e527 100644
--- a/pki/tag.h
+++ b/pki/tag.h
@@ -6,9 +6,8 @@
 #define BSSL_DER_TAG_H_
 
 #include <stdint.h>
-#include "fillins/openssl_util.h"
 
-
+#include <openssl/base.h>
 #include <openssl/bytestring.h>
 
 namespace bssl::der {
diff --git a/pki/test_helpers.cc b/pki/test_helpers.cc
index df80835..b6e6385 100644
--- a/pki/test_helpers.cc
+++ b/pki/test_helpers.cc
@@ -91,7 +91,7 @@
   return out;
 }
 
-  bool ReadFileToString(const std::string &path, std::string *out) {
+bool ReadFileToString(const std::string &path, std::string *out) {
   std::ifstream file(path, std::ios::binary);
   file.unsetf(std::ios::skipws);
 
diff --git a/pki/trust_store.h b/pki/trust_store.h
index e5a9246..5493f6b 100644
--- a/pki/trust_store.h
+++ b/pki/trust_store.h
@@ -5,9 +5,10 @@
 #ifndef BSSL_PKI_TRUST_STORE_H_
 #define BSSL_PKI_TRUST_STORE_H_
 
-#include "fillins/openssl_util.h"
-
 #include <optional>
+
+#include <openssl/base.h>
+
 #include "cert_issuer_source.h"
 #include "parsed_certificate.h"
 
diff --git a/pki/trust_store_collection.h b/pki/trust_store_collection.h
index 9ec914e..494909e 100644
--- a/pki/trust_store_collection.h
+++ b/pki/trust_store_collection.h
@@ -5,7 +5,7 @@
 #ifndef BSSL_PKI_TRUST_STORE_COLLECTION_H_
 #define BSSL_PKI_TRUST_STORE_COLLECTION_H_
 
-#include "fillins/openssl_util.h"
+#include <openssl/base.h>
 
 #include "trust_store.h"
 
diff --git a/pki/trust_store_in_memory.h b/pki/trust_store_in_memory.h
index ccffc7f..4fea8d1 100644
--- a/pki/trust_store_in_memory.h
+++ b/pki/trust_store_in_memory.h
@@ -6,8 +6,8 @@
 #define BSSL_PKI_TRUST_STORE_IN_MEMORY_H_
 
 #include <unordered_map>
-#include "fillins/openssl_util.h"
 
+#include <openssl/base.h>
 
 #include "trust_store.h"
 
diff --git a/pki/verify_certificate_chain.h b/pki/verify_certificate_chain.h
index 9e62f5c..718eceb 100644
--- a/pki/verify_certificate_chain.h
+++ b/pki/verify_certificate_chain.h
@@ -6,10 +6,10 @@
 #define BSSL_PKI_VERIFY_CERTIFICATE_CHAIN_H_
 
 #include <set>
-#include "fillins/openssl_util.h"
 
-
+#include <openssl/base.h>
 #include <openssl/evp.h>
+
 #include "cert_errors.h"
 #include "input.h"
 #include "parsed_certificate.h"
diff --git a/pki/verify_name_match.h b/pki/verify_name_match.h
index 27ed913..bef9054 100644
--- a/pki/verify_name_match.h
+++ b/pki/verify_name_match.h
@@ -7,9 +7,8 @@
 
 #include <string>
 #include <vector>
-#include "fillins/openssl_util.h"
 
-
+#include <openssl/base.h>
 
 namespace bssl {
 
diff --git a/pki/verify_signed_data.cc b/pki/verify_signed_data.cc
index 9bf8414..4271366 100644
--- a/pki/verify_signed_data.cc
+++ b/pki/verify_signed_data.cc
@@ -6,11 +6,11 @@
 
 #include <openssl/bytestring.h>
 #include <openssl/digest.h>
+#include <openssl/err.h>
 #include <openssl/evp.h>
 #include <openssl/rsa.h>
 #include <openssl/sha.h>
 #include "cert_errors.h"
-#include "fillins/openssl_util.h"
 #include "input.h"
 #include "parse_values.h"
 #include "parser.h"
@@ -61,6 +61,15 @@
   return std::string();
 }
 
+// Place an instance of this class on the call stack to automatically clear
+// the OpenSSL error stack on function exit.
+// TODO(crbug.com/boringssl/38): Remove this when the library is more robust to
+// leaving things in the error queue.
+class OpenSSLErrStackTracer {
+ public:
+  ~OpenSSLErrStackTracer() { ERR_clear_error(); };
+};
+
 }  // namespace
 
 // Parses an RSA public key or EC public key from SPKI to an EVP_PKEY. Returns
@@ -131,7 +140,7 @@
 bool ParsePublicKey(const der::Input &public_key_spki,
                     bssl::UniquePtr<EVP_PKEY> *public_key) {
   // Parse the SPKI to an EVP_PKEY.
-  fillins::OpenSSLErrStackTracer err_tracer;
+  OpenSSLErrStackTracer err_tracer;
 
   CBS cbs;
   CBS_init(&cbs, public_key_spki.UnsafeData(), public_key_spki.Length());
@@ -241,7 +250,7 @@
     }
   }
 
-  fillins::OpenSSLErrStackTracer err_tracer;
+  OpenSSLErrStackTracer err_tracer;
 
   bssl::ScopedEVP_MD_CTX ctx;
   EVP_PKEY_CTX *pctx = nullptr;  // Owned by |ctx|.
diff --git a/pki/verify_signed_data.h b/pki/verify_signed_data.h
index 66a34ca..bd7d659 100644
--- a/pki/verify_signed_data.h
+++ b/pki/verify_signed_data.h
@@ -5,9 +5,9 @@
 #ifndef BSSL_PKI_VERIFY_SIGNED_DATA_H_
 #define BSSL_PKI_VERIFY_SIGNED_DATA_H_
 
-#include "fillins/openssl_util.h"
-
+#include <openssl/base.h>
 #include <openssl/evp.h>
+
 #include "signature_algorithm.h"
 #include "signature_verify_cache.h"