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