Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Side by Side Diff: remoting/host/security_key/security_key_message.cc

Issue 1821393002: Adding the message definitions for the remote_security_key STDIO communication classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing feedback Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "remoting/host/security_key/security_key_message.h"
6
7 namespace {
8
9 // Limit remote security key messages to 256KB.
10 const uint32_t kMaxSecurityKeyMessageByteCount = 256 * 1024;
11
12 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.
13
14 } // namespace
15
16 namespace remoting {
17
18 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.
19
20 SecurityKeyMessage::SecurityKeyMessage() {}
21
22 SecurityKeyMessage::~SecurityKeyMessage() {}
23
24 bool SecurityKeyMessage::IsValidMessageSize(uint32_t message_size) {
25 return message_size > 0 && message_size <= kMaxSecurityKeyMessageByteCount;
26 }
27
28 bool SecurityKeyMessage::ParseMessage(const std::string& message_data) {
29 if (!IsValidMessageSize(message_data.size())) {
30 return false;
31 }
32
33 // The first char of the message is the message type.
34 type_ = static_cast<RemoteSecurityKeyMessageType>(message_data[0]);
35 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
36 return false;
37 }
38
39 payload_.clear();
40 if (message_data.size() > kRemoteSecurityKeyMessageControlCodeByteCount) {
41 payload_.reserve(message_data.size() - 1);
42 std::string::const_iterator it = message_data.begin();
43 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.
44 }
45
46 return true;
47 }
48
49 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698