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

Unified 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: Updating enum translation function per 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..95556e5d1f864749b89bce776ce9fe72135b0a97
--- /dev/null
+++ b/remoting/host/security_key/security_key_message.cc
@@ -0,0 +1,69 @@
+// 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"
+
+#include "base/logging.h"
+
+namespace {
+
+// Limit remote security key messages to 256KB.
+const uint32_t kMaxSecurityKeyMessageByteCount = 256 * 1024;
+
+const int kRemoteSecurityKeyMessageControlCodeByteCount = 1;
+
+} // namespace
+
+namespace remoting {
+
+SecurityKeyMessage::SecurityKeyMessage() {}
+
+SecurityKeyMessage::~SecurityKeyMessage() {}
+
+bool SecurityKeyMessage::IsValidMessageSize(uint32_t message_size) {
+ return message_size > 0 && message_size <= kMaxSecurityKeyMessageByteCount;
+}
+
+RemoteSecurityKeyMessageType SecurityKeyMessage::MessageTypeFromValue(
+ int value) {
+ // Note: The static_cast from enum value to int should be safe since the enum
+ // type is an unsigned 8bit value.
+ switch (value) {
+ case static_cast<int>(RemoteSecurityKeyMessageType::CONNECT):
+ case static_cast<int>(RemoteSecurityKeyMessageType::CONNECT_RESPONSE):
+ case static_cast<int>(RemoteSecurityKeyMessageType::CONNECT_ERROR):
+ case static_cast<int>(RemoteSecurityKeyMessageType::REQUEST):
+ case static_cast<int>(RemoteSecurityKeyMessageType::REQUEST_RESPONSE):
+ case static_cast<int>(RemoteSecurityKeyMessageType::REQUEST_ERROR):
+ case static_cast<int>(RemoteSecurityKeyMessageType::UNKNOWN_COMMAND):
+ case static_cast<int>(RemoteSecurityKeyMessageType::UNKNOWN_ERROR):
+ case static_cast<int>(RemoteSecurityKeyMessageType::INVALID):
+ return static_cast<RemoteSecurityKeyMessageType>(value);
+
+ default:
+ LOG(ERROR) << "Unknown message type passed in: " << value;
+ return RemoteSecurityKeyMessageType::INVALID;
+ }
+}
+
+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_ = MessageTypeFromValue(message_data[0]);
+ if (type_ == RemoteSecurityKeyMessageType::INVALID) {
+ return false;
+ }
+
+ payload_.clear();
+ if (message_data.size() > kRemoteSecurityKeyMessageControlCodeByteCount) {
+ payload_ = message_data.substr(1);
+ }
+
+ return true;
+}
+
+} // namespace remoting
« 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