| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_QUIC_CRYPTO_CRYPTO_FRAMER_H_ | 5 #ifndef NET_QUIC_CRYPTO_CRYPTO_FRAMER_H_ |
| 6 #define NET_QUIC_CRYPTO_CRYPTO_FRAMER_H_ | 6 #define NET_QUIC_CRYPTO_CRYPTO_FRAMER_H_ |
| 7 | 7 |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 // A class for framing the crypto messages that are exchanged in a QUIC | 37 // A class for framing the crypto messages that are exchanged in a QUIC |
| 38 // session. | 38 // session. |
| 39 class NET_EXPORT_PRIVATE CryptoFramer { | 39 class NET_EXPORT_PRIVATE CryptoFramer { |
| 40 public: | 40 public: |
| 41 CryptoFramer(); | 41 CryptoFramer(); |
| 42 | 42 |
| 43 virtual ~CryptoFramer(); | 43 virtual ~CryptoFramer(); |
| 44 | 44 |
| 45 // ParseMessage parses exactly one message from the given StringPiece. If | 45 // ParseMessage parses exactly one message from the given StringPiece. If |
| 46 // there is an error, the message is truncated, or the message has trailing | 46 // there is an error, the message is truncated, or the message has trailing |
| 47 // garbage then NULL will be returned. | 47 // garbage then nullptr will be returned. |
| 48 static CryptoHandshakeMessage* ParseMessage(base::StringPiece in); | 48 static CryptoHandshakeMessage* ParseMessage(base::StringPiece in); |
| 49 | 49 |
| 50 // Set callbacks to be called from the framer. A visitor must be set, or | 50 // Set callbacks to be called from the framer. A visitor must be set, or |
| 51 // else the framer will crash. It is acceptable for the visitor to do | 51 // else the framer will crash. It is acceptable for the visitor to do |
| 52 // nothing. If this is called multiple times, only the last visitor | 52 // nothing. If this is called multiple times, only the last visitor |
| 53 // will be used. |visitor| will be owned by the framer. | 53 // will be used. |visitor| will be owned by the framer. |
| 54 void set_visitor(CryptoFramerVisitorInterface* visitor) { | 54 void set_visitor(CryptoFramerVisitorInterface* visitor) { |
| 55 visitor_ = visitor; | 55 visitor_ = visitor; |
| 56 } | 56 } |
| 57 | 57 |
| 58 QuicErrorCode error() const { return error_; } | 58 QuicErrorCode error() const { return error_; } |
| 59 | 59 |
| 60 // Processes input data, which must be delivered in order. Returns | 60 // Processes input data, which must be delivered in order. Returns |
| 61 // false if there was an error, and true otherwise. | 61 // false if there was an error, and true otherwise. |
| 62 bool ProcessInput(base::StringPiece input); | 62 bool ProcessInput(base::StringPiece input); |
| 63 | 63 |
| 64 // Returns the number of bytes of buffered input data remaining to be | 64 // Returns the number of bytes of buffered input data remaining to be |
| 65 // parsed. | 65 // parsed. |
| 66 size_t InputBytesRemaining() const { return buffer_.length(); } | 66 size_t InputBytesRemaining() const { return buffer_.length(); } |
| 67 | 67 |
| 68 // Returns a new QuicData owned by the caller that contains a serialized | 68 // Returns a new QuicData owned by the caller that contains a serialized |
| 69 // |message|, or NULL if there was an error. | 69 // |message|, or nullptr if there was an error. |
| 70 static QuicData* ConstructHandshakeMessage( | 70 static QuicData* ConstructHandshakeMessage( |
| 71 const CryptoHandshakeMessage& message); | 71 const CryptoHandshakeMessage& message); |
| 72 | 72 |
| 73 private: | 73 private: |
| 74 // Clears per-message state. Does not clear the visitor. | 74 // Clears per-message state. Does not clear the visitor. |
| 75 void Clear(); | 75 void Clear(); |
| 76 | 76 |
| 77 // Process does does the work of |ProcessInput|, but returns an error code, | 77 // Process does does the work of |ProcessInput|, but returns an error code, |
| 78 // doesn't set error_ and doesn't call |visitor_->OnError()|. | 78 // doesn't set error_ and doesn't call |visitor_->OnError()|. |
| 79 QuicErrorCode Process(base::StringPiece input); | 79 QuicErrorCode Process(base::StringPiece input); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 105 // tags_and_lengths_ contains the tags that are currently being parsed and | 105 // tags_and_lengths_ contains the tags that are currently being parsed and |
| 106 // their lengths. | 106 // their lengths. |
| 107 std::vector<std::pair<QuicTag, size_t> > tags_and_lengths_; | 107 std::vector<std::pair<QuicTag, size_t> > tags_and_lengths_; |
| 108 // Cumulative length of all values in the message currently being parsed. | 108 // Cumulative length of all values in the message currently being parsed. |
| 109 size_t values_len_; | 109 size_t values_len_; |
| 110 }; | 110 }; |
| 111 | 111 |
| 112 } // namespace net | 112 } // namespace net |
| 113 | 113 |
| 114 #endif // NET_QUIC_CRYPTO_CRYPTO_FRAMER_H_ | 114 #endif // NET_QUIC_CRYPTO_CRYPTO_FRAMER_H_ |
| OLD | NEW |