| 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 <cstdint> |
| 8 #include <string> |
| 9 #include <utility> |
| 10 |
| 11 #include "base/callback.h" |
| 7 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 8 | 14 |
| 9 namespace { | 15 namespace { |
| 10 | 16 |
| 11 // Limit remote security key messages to 256KB. | 17 // Limit remote security key messages to 256KB. |
| 12 const uint32_t kMaxSecurityKeyMessageByteCount = 256 * 1024; | 18 const uint32_t kMaxSecurityKeyMessageByteCount = 256 * 1024; |
| 13 | 19 |
| 14 } // namespace | 20 } // namespace |
| 15 | 21 |
| 16 namespace remoting { | 22 namespace remoting { |
| 17 | 23 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 42 case static_cast<int>(RemoteSecurityKeyMessageType::UNKNOWN_ERROR): | 48 case static_cast<int>(RemoteSecurityKeyMessageType::UNKNOWN_ERROR): |
| 43 case static_cast<int>(RemoteSecurityKeyMessageType::INVALID): | 49 case static_cast<int>(RemoteSecurityKeyMessageType::INVALID): |
| 44 return static_cast<RemoteSecurityKeyMessageType>(value); | 50 return static_cast<RemoteSecurityKeyMessageType>(value); |
| 45 | 51 |
| 46 default: | 52 default: |
| 47 LOG(ERROR) << "Unknown message type passed in: " << value; | 53 LOG(ERROR) << "Unknown message type passed in: " << value; |
| 48 return RemoteSecurityKeyMessageType::INVALID; | 54 return RemoteSecurityKeyMessageType::INVALID; |
| 49 } | 55 } |
| 50 } | 56 } |
| 51 | 57 |
| 58 scoped_ptr<SecurityKeyMessage> SecurityKeyMessage::CreateMessageForTest( |
| 59 RemoteSecurityKeyMessageType type, |
| 60 const std::string& payload) { |
| 61 scoped_ptr<SecurityKeyMessage> message(new SecurityKeyMessage()); |
| 62 message->type_ = type; |
| 63 message->payload_ = payload; |
| 64 |
| 65 return message; |
| 66 } |
| 67 |
| 52 bool SecurityKeyMessage::ParseMessage(const std::string& message_data) { | 68 bool SecurityKeyMessage::ParseMessage(const std::string& message_data) { |
| 53 if (!IsValidMessageSize(message_data.size())) { | 69 if (!IsValidMessageSize(message_data.size())) { |
| 54 return false; | 70 return false; |
| 55 } | 71 } |
| 56 | 72 |
| 57 // The first char of the message is the message type. | 73 // The first char of the message is the message type. |
| 58 type_ = MessageTypeFromValue(message_data[0]); | 74 type_ = MessageTypeFromValue(message_data[0]); |
| 59 if (type_ == RemoteSecurityKeyMessageType::INVALID) { | 75 if (type_ == RemoteSecurityKeyMessageType::INVALID) { |
| 60 return false; | 76 return false; |
| 61 } | 77 } |
| 62 | 78 |
| 63 payload_.clear(); | 79 payload_.clear(); |
| 64 if (message_data.size() > kMessageTypeSizeBytes) { | 80 if (message_data.size() > kMessageTypeSizeBytes) { |
| 65 payload_ = message_data.substr(1); | 81 payload_ = message_data.substr(1); |
| 66 } | 82 } |
| 67 | 83 |
| 68 return true; | 84 return true; |
| 69 } | 85 } |
| 70 | 86 |
| 71 } // namespace remoting | 87 } // namespace remoting |
| OLD | NEW |