xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/tools/quic_reject_reason_decoder_bin.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright (c) 2016 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 // Decodes the packet HandshakeFailureReason from the chromium histogram
6 // Net.QuicClientHelloRejectReasons
7 
8 #include <iostream>
9 
10 #include "absl/strings/numbers.h"
11 #include "quiche/quic/core/crypto/crypto_handshake.h"
12 #include "quiche/quic/core/crypto/crypto_utils.h"
13 #include "quiche/quic/platform/api/quic_flags.h"
14 #include "quiche/common/platform/api/quiche_command_line_flags.h"
15 #include "quiche/common/quiche_text_utils.h"
16 
17 using quic::CryptoUtils;
18 using quic::HandshakeFailureReason;
19 using quic::MAX_FAILURE_REASON;
20 
main(int argc,char * argv[])21 int main(int argc, char* argv[]) {
22   const char* usage = "Usage: quic_reject_reason_decoder <packed_reason>";
23   std::vector<std::string> args =
24       quiche::QuicheParseCommandLineFlags(usage, argc, argv);
25 
26   if (args.size() != 1) {
27     std::cerr << usage << std::endl;
28     return 1;
29   }
30 
31   uint32_t packed_error = 0;
32   if (!absl::SimpleAtoi(args[0], &packed_error)) {
33     std::cerr << "Unable to parse: " << args[0] << "\n";
34     return 2;
35   }
36 
37   for (int i = 1; i < MAX_FAILURE_REASON; ++i) {
38     if ((packed_error & (1 << (i - 1))) == 0) {
39       continue;
40     }
41     HandshakeFailureReason reason = static_cast<HandshakeFailureReason>(i);
42     std::cout << CryptoUtils::HandshakeFailureReasonToString(reason) << "\n";
43   }
44   return 0;
45 }
46