Chromium Code Reviews| 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 #ifndef NET_QUIC_CRYPTO_CRYPTO_FRAMER_H_ | |
| 6 #define NET_QUIC_CRYPTO_CRYPTO_FRAMER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/logging.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "net/quic/quic_protocol.h" | |
| 15 #include "net/quic/crypto/crypto_protocol.h" | |
|
jar (doing other things)
2012/10/14 23:04:38
nit: alphabetize
Ryan Hamilton
2012/10/15 21:22:08
Done.
| |
| 16 #include "base/string_piece.h" | |
| 17 | |
| 18 namespace net { | |
| 19 | |
| 20 class CryptoFramer; | |
| 21 class QuicDataReader; | |
| 22 class QuicData; | |
| 23 | |
| 24 class CryptoFramerVisitorInterface { | |
| 25 public: | |
| 26 virtual ~CryptoFramerVisitorInterface() {} | |
| 27 | |
| 28 // Called if an error is detected. | |
| 29 virtual void OnError(CryptoFramer* framer) = 0; | |
| 30 | |
| 31 // Called when a complete handshake message has been parsed. | |
| 32 virtual void OnHandshakeMessage(const CryptoHandshakeMessage& message) = 0; | |
| 33 }; | |
| 34 | |
| 35 class CryptoFramer { | |
|
jar (doing other things)
2012/10/14 23:04:38
It might be helpful to have a class comment, indic
Ryan Hamilton
2012/10/15 21:22:08
Done.
| |
| 36 public: | |
| 37 CryptoFramer(); | |
| 38 | |
| 39 virtual ~CryptoFramer(); | |
| 40 | |
| 41 // Set callbacks to be called from the framer. A visitor must be set, or | |
| 42 // else the framer will likely crash. It is acceptable for the visitor | |
| 43 // to do nothing. If this is called multiple times, only the last visitor | |
| 44 // will be used. | |
| 45 void set_visitor(CryptoFramerVisitorInterface* visitor) { | |
| 46 visitor_ = visitor; | |
|
jar (doing other things)
2012/10/14 23:04:38
Perhaps it is worth a comment that the ownership o
Ryan Hamilton
2012/10/15 21:22:08
Done.
Ryan Hamilton
2012/10/15 21:22:08
Done.
| |
| 47 } | |
| 48 | |
| 49 QuicErrorCode error() const { | |
| 50 return error_; | |
| 51 } | |
| 52 | |
| 53 // Processes input data, which must be delievered in order. Returns | |
| 54 // false if there was an error, and true otherwise. | |
| 55 bool ProcessInput(base::StringPiece input); | |
| 56 | |
| 57 // Serializes |message| into |packet|. Returns fase if there was an | |
|
jar (doing other things)
2012/10/14 23:04:38
nit: fase-->false
Ryan Hamilton
2012/10/15 21:22:08
Done.
| |
| 58 // error, and true otherwise. | |
| 59 bool ConstructHandshakeMessage(const CryptoHandshakeMessage& message, | |
| 60 QuicData** packet); | |
| 61 | |
| 62 private: | |
| 63 // Clears per-message state. Does not clear the visitor. | |
| 64 void Clear(); | |
| 65 | |
| 66 void set_error(QuicErrorCode error) { | |
| 67 error_ = error; | |
| 68 } | |
| 69 | |
| 70 enum CryptoFramerState { | |
| 71 STATE_READING_TAG, | |
| 72 STATE_READING_NUM_ENTRIES, | |
| 73 STATE_READING_KEY_TAGS, | |
| 74 STATE_READING_LENGTHS, | |
| 75 STATE_READING_VALUES | |
| 76 }; | |
| 77 | |
| 78 // Reader for parsing data. | |
| 79 scoped_ptr<QuicDataReader> reader_; | |
| 80 // Visitor to send invoke when messages are parsed. | |
| 81 CryptoFramerVisitorInterface* visitor_; | |
| 82 // Last error. | |
| 83 QuicErrorCode error_; | |
| 84 // Remaining unparsed data. | |
| 85 std::string buffer_; | |
| 86 // Current state of the parsing. | |
| 87 CryptoFramerState state_; | |
| 88 // Tag of the message currently being parsed. | |
| 89 CryptoTag message_tag_; | |
| 90 // Number of entires in the message currently being parsed. | |
| 91 uint16 num_entries_; | |
| 92 // Vector of tags in the message currently being parsed. | |
| 93 std::vector<CryptoTag> tags_; | |
| 94 // Length of the data associated with each tag in the message currently | |
| 95 // being parsed. | |
| 96 std::map<CryptoTag, size_t> tag_length_map_; | |
| 97 // Length of the data associated with each tag in the message currently | |
|
jar (doing other things)
2012/10/14 23:04:38
This says "Length" just like line 94, but it looks
Ryan Hamilton
2012/10/15 21:22:08
Will be fixed when the changes from cl/35411506 ar
| |
| 98 // being parsed. | |
| 99 CryptoTagValueMap tag_value_map_; | |
| 100 // Cumulative length of all values in the message currently being parsed. | |
| 101 size_t values_len_; | |
| 102 }; | |
| 103 | |
| 104 } // namespace net | |
| 105 | |
| 106 #endif // NET_QUIC_CRYPTO_CRYPTO_FRAMER_H_ | |
| OLD | NEW |