| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "remoting/host/security_key/security_key_message.h" | 5 #include "remoting/host/security_key/security_key_message.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 | 8 |
| 9 namespace { | 9 namespace { |
| 10 | 10 |
| 11 // Limit remote security key messages to 256KB. | 11 // Limit remote security key messages to 256KB. |
| 12 const uint32_t kMaxSecurityKeyMessageByteCount = 256 * 1024; | 12 const uint32_t kMaxSecurityKeyMessageByteCount = 256 * 1024; |
| 13 | 13 |
| 14 const int kRemoteSecurityKeyMessageControlCodeByteCount = 1; | |
| 15 | |
| 16 } // namespace | 14 } // namespace |
| 17 | 15 |
| 18 namespace remoting { | 16 namespace remoting { |
| 19 | 17 |
| 18 const int SecurityKeyMessage::kHeaderSizeBytes = 4; |
| 19 |
| 20 const int SecurityKeyMessage::kMessageTypeSizeBytes = 1; |
| 21 |
| 20 SecurityKeyMessage::SecurityKeyMessage() {} | 22 SecurityKeyMessage::SecurityKeyMessage() {} |
| 21 | 23 |
| 22 SecurityKeyMessage::~SecurityKeyMessage() {} | 24 SecurityKeyMessage::~SecurityKeyMessage() {} |
| 23 | 25 |
| 24 bool SecurityKeyMessage::IsValidMessageSize(uint32_t message_size) { | 26 bool SecurityKeyMessage::IsValidMessageSize(uint32_t message_size) { |
| 25 return message_size > 0 && message_size <= kMaxSecurityKeyMessageByteCount; | 27 return message_size > 0 && message_size <= kMaxSecurityKeyMessageByteCount; |
| 26 } | 28 } |
| 27 | 29 |
| 28 RemoteSecurityKeyMessageType SecurityKeyMessage::MessageTypeFromValue( | 30 RemoteSecurityKeyMessageType SecurityKeyMessage::MessageTypeFromValue( |
| 29 int value) { | 31 int value) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 return false; | 70 return false; |
| 69 } | 71 } |
| 70 | 72 |
| 71 // The first char of the message is the message type. | 73 // The first char of the message is the message type. |
| 72 type_ = MessageTypeFromValue(message_data[0]); | 74 type_ = MessageTypeFromValue(message_data[0]); |
| 73 if (type_ == RemoteSecurityKeyMessageType::INVALID) { | 75 if (type_ == RemoteSecurityKeyMessageType::INVALID) { |
| 74 return false; | 76 return false; |
| 75 } | 77 } |
| 76 | 78 |
| 77 payload_.clear(); | 79 payload_.clear(); |
| 78 if (message_data.size() > kRemoteSecurityKeyMessageControlCodeByteCount) { | 80 if (message_data.size() > kMessageTypeSizeBytes) { |
| 79 payload_ = message_data.substr(1); | 81 payload_ = message_data.substr(1); |
| 80 } | 82 } |
| 81 | 83 |
| 82 return true; | 84 return true; |
| 83 } | 85 } |
| 84 | 86 |
| 85 } // namespace remoting | 87 } // namespace remoting |
| OLD | NEW |