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 #ifndef REMOTING_HOST_SECURITY_KEY_SECURITY_KEY_MESSAGE_H_ | 5 #ifndef REMOTING_HOST_SECURITY_KEY_SECURITY_KEY_MESSAGE_H_ |
6 #define REMOTING_HOST_SECURITY_KEY_SECURITY_KEY_MESSAGE_H_ | 6 #define REMOTING_HOST_SECURITY_KEY_SECURITY_KEY_MESSAGE_H_ |
7 | 7 |
8 #include <cstdint> | 8 #include <cstdint> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 26 matching lines...) Expand all Loading... |
37 // Multi-byte payloads which are part of the security key request and | 37 // Multi-byte payloads which are part of the security key request and |
38 // response messages are expected to be big endian. The bytes for | 38 // response messages are expected to be big endian. The bytes for |
39 // these messages will be transmitted across the network as-is. | 39 // these messages will be transmitted across the network as-is. |
40 // The format for all other payloads is the endianness of the platform. | 40 // The format for all other payloads is the endianness of the platform. |
41 | 41 |
42 // ----------------------------------------------------------------------------- | 42 // ----------------------------------------------------------------------------- |
43 // Messages | 43 // Messages |
44 // ----------------------------------------------------------------------------- | 44 // ----------------------------------------------------------------------------- |
45 // NOTE: Make sure SecurityKeyMessage::MessageTypeFromValue is updated when new | 45 // NOTE: Make sure SecurityKeyMessage::MessageTypeFromValue is updated when new |
46 // enum values are added/removed. | 46 // enum values are added/removed. |
47 enum class RemoteSecurityKeyMessageType : uint8_t { | 47 enum class SecurityKeyMessageType : uint8_t { |
48 INVALID = 0, | 48 INVALID = 0, |
49 | 49 |
50 // Sent to the remote_security_key process to ask it to establish a | 50 // Sent to the remote_security_key process to ask it to establish a |
51 // connection to the Chromoting host if a security key enabled session | 51 // connection to the Chromoting host if a security key enabled session |
52 // exists for the current user. | 52 // exists for the current user. |
53 // Payload length: 0 | 53 // Payload length: 0 |
54 CONNECT = 1, | 54 CONNECT = 1, |
55 | 55 |
56 // Sent is sent by the remote_security_key process in response to a | 56 // Sent is sent by the remote_security_key process in response to a |
57 // |kConnectToSecurityKeyEnabledSessionMsg| request. | 57 // |kConnectToSecurityKeyEnabledSessionMsg| request. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 // The number of bytes used to represent the message type. | 108 // The number of bytes used to represent the message type. |
109 static const int kMessageTypeSizeBytes; | 109 static const int kMessageTypeSizeBytes; |
110 | 110 |
111 SecurityKeyMessage(); | 111 SecurityKeyMessage(); |
112 ~SecurityKeyMessage(); | 112 ~SecurityKeyMessage(); |
113 | 113 |
114 // When given a header value (uint32_t), this method will return whether the | 114 // When given a header value (uint32_t), this method will return whether the |
115 // length is within the allowable size range. | 115 // length is within the allowable size range. |
116 static bool IsValidMessageSize(uint32_t message_size); | 116 static bool IsValidMessageSize(uint32_t message_size); |
117 | 117 |
118 // Returns a RemoteSecurityKeyMessageType enum value corresponding to the | 118 // Returns a SecurityKeyMessageType enum value corresponding to the |
119 // value passed in if it is valid, otherwise INVALID is returned. | 119 // value passed in if it is valid, otherwise INVALID is returned. |
120 static RemoteSecurityKeyMessageType MessageTypeFromValue(int value); | 120 static SecurityKeyMessageType MessageTypeFromValue(int value); |
121 | 121 |
122 // Creates a message from the passed in values, no validation is done as this | 122 // Creates a message from the passed in values, no validation is done as this |
123 // method is only expected to be called from test code. | 123 // method is only expected to be called from test code. |
124 static std::unique_ptr<SecurityKeyMessage> CreateMessageForTest( | 124 static std::unique_ptr<SecurityKeyMessage> CreateMessageForTest( |
125 RemoteSecurityKeyMessageType type, | 125 SecurityKeyMessageType type, |
126 const std::string& payload); | 126 const std::string& payload); |
127 | 127 |
128 // Parses |message_data| and initializes the internal members. Returns true | 128 // Parses |message_data| and initializes the internal members. Returns true |
129 // if |message_data| was parsed and the instance was initialized successfully. | 129 // if |message_data| was parsed and the instance was initialized successfully. |
130 bool ParseMessage(const std::string& message_data); | 130 bool ParseMessage(const std::string& message_data); |
131 | 131 |
132 RemoteSecurityKeyMessageType type() { return type_; } | 132 SecurityKeyMessageType type() { return type_; } |
133 | 133 |
134 const std::string& payload() { return payload_; } | 134 const std::string& payload() { return payload_; } |
135 | 135 |
136 private: | 136 private: |
137 RemoteSecurityKeyMessageType type_ = RemoteSecurityKeyMessageType::INVALID; | 137 SecurityKeyMessageType type_ = SecurityKeyMessageType::INVALID; |
138 std::string payload_; | 138 std::string payload_; |
139 | 139 |
140 DISALLOW_COPY_AND_ASSIGN(SecurityKeyMessage); | 140 DISALLOW_COPY_AND_ASSIGN(SecurityKeyMessage); |
141 }; | 141 }; |
142 | 142 |
143 // Used to pass remote security key message data between classes. | 143 // Used to pass security key message data between classes. |
144 typedef base::Callback<void(std::unique_ptr<SecurityKeyMessage> message)> | 144 typedef base::Callback<void(std::unique_ptr<SecurityKeyMessage> message)> |
145 SecurityKeyMessageCallback; | 145 SecurityKeyMessageCallback; |
146 | 146 |
147 } // namespace remoting | 147 } // namespace remoting |
148 | 148 |
149 #endif // REMOTING_HOST_SECURITY_KEY_SECURITY_KEY_MESSAGE_H_ | 149 #endif // REMOTING_HOST_SECURITY_KEY_SECURITY_KEY_MESSAGE_H_ |
OLD | NEW |