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

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: Fixing a non-windows build break Created 4 years, 8 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
« no previous file with comments | « remoting/host/security_key/security_key_message.h ('k') | remoting/remoting_host_srcs.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "base/logging.h"
8
9 namespace {
10
11 // Limit remote security key messages to 256KB.
12 const uint32_t kMaxSecurityKeyMessageByteCount = 256 * 1024;
13
14 const int kRemoteSecurityKeyMessageControlCodeByteCount = 1;
15
16 } // namespace
17
18 namespace remoting {
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 RemoteSecurityKeyMessageType SecurityKeyMessage::MessageTypeFromValue(
29 int value) {
30 // Note: The static_cast from enum value to int should be safe since the enum
31 // type is an unsigned 8bit value.
32 switch (value) {
Sergey Ulanov 2016/03/30 21:21:50 I think you can also format this code as follows:
joedow 2016/03/30 21:46:10 Done.
33 case static_cast<int>(RemoteSecurityKeyMessageType::CONNECT):
34 return RemoteSecurityKeyMessageType::CONNECT;
35
36 case static_cast<int>(RemoteSecurityKeyMessageType::CONNECT_RESPONSE):
37 return RemoteSecurityKeyMessageType::CONNECT_RESPONSE;
38
39 case static_cast<int>(RemoteSecurityKeyMessageType::CONNECT_ERROR):
40 return RemoteSecurityKeyMessageType::CONNECT_ERROR;
41
42 case static_cast<int>(RemoteSecurityKeyMessageType::REQUEST):
43 return RemoteSecurityKeyMessageType::REQUEST;
44
45 case static_cast<int>(RemoteSecurityKeyMessageType::REQUEST_RESPONSE):
46 return RemoteSecurityKeyMessageType::REQUEST_RESPONSE;
47
48 case static_cast<int>(RemoteSecurityKeyMessageType::REQUEST_ERROR):
49 return RemoteSecurityKeyMessageType::REQUEST_ERROR;
50
51 case static_cast<int>(RemoteSecurityKeyMessageType::UNKNOWN_COMMAND):
52 return RemoteSecurityKeyMessageType::UNKNOWN_COMMAND;
53
54 case static_cast<int>(RemoteSecurityKeyMessageType::UNKNOWN_ERROR):
55 return RemoteSecurityKeyMessageType::UNKNOWN_ERROR;
56
57 case static_cast<int>(RemoteSecurityKeyMessageType::INVALID):
58 return RemoteSecurityKeyMessageType::INVALID;
59
60 default:
61 LOG(ERROR) << "Unknown message type passed in: " << value;
62 return RemoteSecurityKeyMessageType::INVALID;
63 }
64 }
65
66 bool SecurityKeyMessage::ParseMessage(const std::string& message_data) {
67 if (!IsValidMessageSize(message_data.size())) {
68 return false;
69 }
70
71 // The first char of the message is the message type.
72 type_ = MessageTypeFromValue(message_data[0]);
73 if (type_ == RemoteSecurityKeyMessageType::INVALID) {
74 return false;
75 }
76
77 payload_.clear();
78 if (message_data.size() > kRemoteSecurityKeyMessageControlCodeByteCount) {
79 payload_ = message_data.substr(1);
80 }
81
82 return true;
83 }
84
85 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/security_key/security_key_message.h ('k') | remoting/remoting_host_srcs.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698