Chromium Code Reviews| Index: net/websockets/websocket_frame.h |
| diff --git a/net/websockets/websocket_frame.h b/net/websockets/websocket_frame.h |
| index 593d439481282b023397b241e08d9fa2975d9942..2edc189d81262d7db614150deeca4662e4e0e2da 100644 |
| --- a/net/websockets/websocket_frame.h |
| +++ b/net/websockets/websocket_frame.h |
| @@ -60,6 +60,9 @@ struct NET_EXPORT_PRIVATE WebSocketFrameHeader { |
| // Users of this struct should treat WebSocket frames as a data stream; it's |
| // important to keep the frame data flowing, especially in the browser process. |
| // Users should not let the data stuck somewhere in the pipeline. |
| +// |
| +// This struct is used for reading WebSocket frame data (created by |
| +// WebSocketFrameParser). To construct WebSocket frames, use functions below. |
| struct NET_EXPORT_PRIVATE WebSocketFrameChunk { |
| WebSocketFrameChunk(); |
| ~WebSocketFrameChunk(); |
| @@ -75,6 +78,43 @@ struct NET_EXPORT_PRIVATE WebSocketFrameChunk { |
| std::vector<char> data; |
| }; |
| +// Contains four-byte data representing "masking key" of WebSocket frames. |
| +struct WebSocketMaskingKey { |
| + char key[WebSocketFrameHeader::kMaskingKeyLength]; |
| +}; |
|
mmenke
2012/05/22 17:12:41
Think this should also be used in net/websockets/w
Yuta Kitamura
2012/06/06 18:06:48
Yeah I'm going to do that later.
|
| + |
| +// Writes wire format of a WebSocket frame header into |output|. |
| +// |
| +// WebSocket frame format is defined at: |
| +// <http://tools.ietf.org/html/rfc6455#section-5.2>. This function writes |
| +// everything but payload data in a WebSocket frame to |output|. |
| +// |
| +// If |header->masked| is true, |masking_key| must point to a valid |
| +// WebSocketMaskingKey object containing the masking key for that frame |
| +// (possibly generated by GenerateWebSocketMaskingKey() function below). |
| +// Otherwise, |masking_key| must be NULL. |
| +NET_EXPORT_PRIVATE void WriteWebSocketFrameHeader( |
| + const WebSocketFrameHeader& header, |
| + const WebSocketMaskingKey* masking_key, |
| + std::vector<char>* output); |
| + |
| +// Generates a masking key suitable for use in a new WebSocket frame. |
| +NET_EXPORT_PRIVATE WebSocketMaskingKey GenerateWebSocketMaskingKey(); |
| + |
| +// Masks WebSocket frame payload. |
| +// |
| +// A client must mask every WebSocket frame by XOR'ing the frame payload |
| +// with four-byte random data (masking key). This function applies the masking |
| +// to the given payload data. |
| +// |
| +// This function masks |frame_data| with |masking_key|, assuming |frame_data| |
| +// is partial data starting from |frame_offset| bytes from the beginning of |
| +// the payload data. |
| +NET_EXPORT_PRIVATE void MaskWebSocketFramePayload( |
| + const WebSocketMaskingKey& masking_key, |
| + uint64 frame_offset, |
| + std::vector<char>* frame_data); |
| + |
| } // namespace net |
| #endif // NET_WEBSOCKETS_WEBSOCKET_FRAME_H_ |