| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/extensions/api/cast_channel/cast_message_util.h" | 5 #include "chrome/browser/extensions/api/cast_channel/cast_message_util.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 out += ", sourceId = " + message_proto.source_id(); | 100 out += ", sourceId = " + message_proto.source_id(); |
| 101 out += ", destId = " + message_proto.destination_id(); | 101 out += ", destId = " + message_proto.destination_id(); |
| 102 out += ", type = " + base::IntToString(message_proto.payload_type()); | 102 out += ", type = " + base::IntToString(message_proto.payload_type()); |
| 103 out += ", str = \"" + message_proto.payload_utf8() + "\"}"; | 103 out += ", str = \"" + message_proto.payload_utf8() + "\"}"; |
| 104 return out; | 104 return out; |
| 105 } | 105 } |
| 106 | 106 |
| 107 std::string AuthMessageToString(const DeviceAuthMessage& message) { | 107 std::string AuthMessageToString(const DeviceAuthMessage& message) { |
| 108 std::string out("{"); | 108 std::string out("{"); |
| 109 if (message.has_challenge()) { | 109 if (message.has_challenge()) { |
| 110 out += "\n challenge = {},"; | 110 out += "challenge: {}, "; |
| 111 } | 111 } |
| 112 if (message.has_response()) { | 112 if (message.has_response()) { |
| 113 out += "\n response = {"; | 113 out += "response: {signature: ("; |
| 114 out += "\n signature = " + message.response().signature(); | 114 out += base::UintToString(message.response().signature().length()); |
| 115 out += "\n, certificate = " + | 115 out += " bytes), certificate: ("; |
| 116 message.response().client_auth_certificate(); | 116 out += base::UintToString( |
| 117 out += "\n }"; | 117 message.response().client_auth_certificate().length()); |
| 118 out += " bytes)}"; |
| 118 } | 119 } |
| 119 if (message.has_error()) { | 120 if (message.has_error()) { |
| 120 out += "\n error = {"; | 121 out += ", error: {"; |
| 121 out += base::IntToString(message.error().error_type()); | 122 out += base::IntToString(message.error().error_type()); |
| 122 out += "}"; | 123 out += "}"; |
| 123 } | 124 } |
| 124 out += "}"; | 125 out += "}"; |
| 125 return out; | 126 return out; |
| 126 } | 127 } |
| 127 | 128 |
| 128 void CreateAuthChallengeMessage(CastMessage* message_proto) { | 129 void CreateAuthChallengeMessage(CastMessage* message_proto) { |
| 129 CHECK(message_proto); | 130 CHECK(message_proto); |
| 130 DeviceAuthMessage auth_message; | 131 DeviceAuthMessage auth_message; |
| 131 auth_message.mutable_challenge(); | 132 auth_message.mutable_challenge(); |
| 132 std::string auth_message_string; | 133 std::string auth_message_string; |
| 133 auth_message.SerializeToString(&auth_message_string); | 134 auth_message.SerializeToString(&auth_message_string); |
| 134 | 135 |
| 135 message_proto->set_protocol_version(CastMessage_ProtocolVersion_CASTV2_1_0); | 136 message_proto->set_protocol_version(CastMessage_ProtocolVersion_CASTV2_1_0); |
| 136 message_proto->set_source_id(kPlatformSenderId); | 137 message_proto->set_source_id(kPlatformSenderId); |
| 137 message_proto->set_destination_id(kPlatformReceiverId); | 138 message_proto->set_destination_id(kPlatformReceiverId); |
| 138 message_proto->set_namespace_(kAuthNamespace); | 139 message_proto->set_namespace_(kAuthNamespace); |
| 139 message_proto->set_payload_type(CastMessage_PayloadType_BINARY); | 140 message_proto->set_payload_type(CastMessage_PayloadType_BINARY); |
| 140 message_proto->set_payload_binary(auth_message_string); | 141 message_proto->set_payload_binary(auth_message_string); |
| 141 } | 142 } |
| 142 | 143 |
| 143 bool IsAuthMessage(const CastMessage& message) { | 144 bool IsAuthMessage(const CastMessage& message) { |
| 144 return message.namespace_() == kAuthNamespace; | 145 return message.namespace_() == kAuthNamespace; |
| 145 } | 146 } |
| 146 | 147 |
| 147 } // namespace cast_channel | 148 } // namespace cast_channel |
| 148 } // namespace api | 149 } // namespace api |
| 149 } // namespace extensions | 150 } // namespace extensions |
| OLD | NEW |