Chromium Code Reviews| Index: remoting/host/security_key/security_key_message.cc |
| diff --git a/remoting/host/security_key/security_key_message.cc b/remoting/host/security_key/security_key_message.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d0c6d54a033b33c8585cf08edc5aea7817457d13 |
| --- /dev/null |
| +++ b/remoting/host/security_key/security_key_message.cc |
| @@ -0,0 +1,49 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "remoting/host/security_key/security_key_message.h" |
| + |
| +namespace { |
| + |
| +// Limit remote security key messages to 256KB. |
| +const uint32_t kMaxSecurityKeyMessageByteCount = 256 * 1024; |
| + |
| +const int kRemoteSecurityKeyMessageControlCodeByteCount = sizeof(uint8_t); |
|
Sergey Ulanov
2016/03/24 21:51:17
1 instead sizeof(uint8_t) please
joedow
2016/03/28 19:44:26
Done.
|
| + |
| +} // namespace |
| + |
| +namespace remoting { |
| + |
| +const int SecurityKeyMessage::kHeaderSizeBytes = sizeof(uint32_t); |
|
Sergey Ulanov
2016/03/24 21:51:17
nit: replace sizeof(uint32_t) with 4.
joedow
2016/03/28 19:44:26
Acknowledged.
|
| + |
| +SecurityKeyMessage::SecurityKeyMessage() {} |
| + |
| +SecurityKeyMessage::~SecurityKeyMessage() {} |
| + |
| +bool SecurityKeyMessage::IsValidMessageSize(uint32_t message_size) { |
| + return message_size > 0 && message_size <= kMaxSecurityKeyMessageByteCount; |
| +} |
| + |
| +bool SecurityKeyMessage::ParseMessage(const std::string& message_data) { |
| + if (!IsValidMessageSize(message_data.size())) { |
| + return false; |
| + } |
| + |
| + // The first char of the message is the message type. |
| + type_ = static_cast<RemoteSecurityKeyMessageType>(message_data[0]); |
| + if (type_ == RemoteSecurityKeyMessageType::kUnitialized) { |
|
Sergey Ulanov
2016/03/24 21:51:17
Do we also need to validate that it's in accepted
joedow
2016/03/28 19:44:26
I thought about adding validation in but I don't t
Sergey Ulanov
2016/03/29 01:05:51
I think we want to validate the value before the s
|
| + return false; |
| + } |
| + |
| + payload_.clear(); |
| + if (message_data.size() > kRemoteSecurityKeyMessageControlCodeByteCount) { |
| + payload_.reserve(message_data.size() - 1); |
| + std::string::const_iterator it = message_data.begin(); |
| + payload_.append(++it, message_data.end()); |
|
Sergey Ulanov
2016/03/24 21:51:17
You don't really gain anything by calling reserve(
joedow
2016/03/28 19:44:26
Done.
|
| + } |
| + |
| + return true; |
| +} |
| + |
| +} // namespace remoting |