crypto_message_printer_bin.cc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (c) 2012 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. // Dumps the contents of a QUIC crypto handshake message in a human readable
  5. // format.
  6. //
  7. // Usage: crypto_message_printer_bin <hex of message>
  8. #include <iostream>
  9. #include "base/command_line.h"
  10. #include "base/strings/string_number_conversions.h"
  11. #include "net/third_party/quiche/src/quiche/quic/core/crypto/crypto_framer.h"
  12. using quic::Perspective;
  13. using std::cerr;
  14. using std::cout;
  15. using std::endl;
  16. namespace net {
  17. class CryptoMessagePrinter : public quic::CryptoFramerVisitorInterface {
  18. public:
  19. explicit CryptoMessagePrinter() = default;
  20. void OnHandshakeMessage(
  21. const quic::CryptoHandshakeMessage& message) override {
  22. cout << message.DebugString() << endl;
  23. }
  24. void OnError(quic::CryptoFramer* framer) override {
  25. cerr << "Error code: " << framer->error() << endl;
  26. cerr << "Error details: " << framer->error_detail() << endl;
  27. }
  28. };
  29. } // namespace net
  30. int main(int argc, char* argv[]) {
  31. base::CommandLine::Init(argc, argv);
  32. if (argc != 1) {
  33. cerr << "Usage: " << argv[0] << " <hex of message>\n";
  34. return 1;
  35. }
  36. net::CryptoMessagePrinter printer;
  37. quic::CryptoFramer framer;
  38. framer.set_visitor(&printer);
  39. framer.set_process_truncated_messages(true);
  40. std::string input;
  41. if (!base::HexStringToString(argv[1], &input) ||
  42. !framer.ProcessInput(input)) {
  43. return 1;
  44. }
  45. if (framer.InputBytesRemaining() != 0) {
  46. cerr << "Input partially consumed. " << framer.InputBytesRemaining()
  47. << " bytes remaining." << endl;
  48. return 2;
  49. }
  50. return 0;
  51. }