• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "quiche/common/quiche_crypto_logging.h"
6 
7 #include "absl/status/status.h"
8 #include "absl/strings/string_view.h"
9 #include "openssl/err.h"
10 #include "quiche/common/platform/api/quiche_logging.h"
11 
12 namespace quiche {
DLogOpenSslErrors()13 void DLogOpenSslErrors() {
14 #ifdef NDEBUG
15   // Clear OpenSSL error stack.
16   ClearOpenSslErrors();
17 #else
18   while (uint32_t error = ERR_get_error()) {
19     char buf[120];
20     ERR_error_string_n(error, buf, ABSL_ARRAYSIZE(buf));
21     QUICHE_DLOG(ERROR) << "OpenSSL error: " << buf;
22   }
23 #endif
24 }
25 
ClearOpenSslErrors()26 void ClearOpenSslErrors() {
27   while (ERR_get_error()) {
28   }
29 }
30 
SslErrorAsStatus(absl::string_view msg,absl::StatusCode code)31 absl::Status SslErrorAsStatus(absl::string_view msg, absl::StatusCode code) {
32   std::string message;
33   absl::StrAppend(&message, msg, "OpenSSL error: ");
34   while (uint32_t error = ERR_get_error()) {
35     char buf[120];
36     ERR_error_string_n(error, buf, ABSL_ARRAYSIZE(buf));
37     absl::StrAppend(&message, buf);
38   }
39   return absl::Status(code, message);
40 }
41 
42 }  // namespace quiche
43