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

Side by Side Diff: components/cast_channel/cast_message_util.cc

Issue 2926313002: Revert of [cast_channel] Move cast_channel related files from //extensions to //components (Closed)
Patch Set: Created 3 years, 6 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 | « components/cast_channel/cast_message_util.h ('k') | components/cast_channel/cast_socket.h » ('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 2014 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 "components/cast_channel/cast_message_util.h"
6
7 #include <memory>
8
9 #include "base/logging.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "base/values.h"
12 #include "components/cast_channel/cast_auth_util.h"
13 #include "components/cast_channel/proto/cast_channel.pb.h"
14
15 namespace {
16 static const char kAuthNamespace[] = "urn:x-cast:com.google.cast.tp.deviceauth";
17 // Sender and receiver IDs to use for platform messages.
18 static const char kPlatformSenderId[] = "sender-0";
19 static const char kPlatformReceiverId[] = "receiver-0";
20 } // namespace
21
22 namespace cast_channel {
23
24 bool IsCastMessageValid(const CastMessage& message_proto) {
25 if (message_proto.namespace_().empty() || message_proto.source_id().empty() ||
26 message_proto.destination_id().empty()) {
27 return false;
28 }
29 return (message_proto.payload_type() == CastMessage_PayloadType_STRING &&
30 message_proto.has_payload_utf8()) ||
31 (message_proto.payload_type() == CastMessage_PayloadType_BINARY &&
32 message_proto.has_payload_binary());
33 }
34
35 std::string CastMessageToString(const CastMessage& message_proto) {
36 std::string out("{");
37 out += "namespace = " + message_proto.namespace_();
38 out += ", sourceId = " + message_proto.source_id();
39 out += ", destId = " + message_proto.destination_id();
40 out += ", type = " + base::IntToString(message_proto.payload_type());
41 out += ", str = \"" + message_proto.payload_utf8() + "\"}";
42 return out;
43 }
44
45 std::string AuthMessageToString(const DeviceAuthMessage& message) {
46 std::string out("{");
47 if (message.has_challenge()) {
48 out += "challenge: {}, ";
49 }
50 if (message.has_response()) {
51 out += "response: {signature: (";
52 out += base::SizeTToString(message.response().signature().length());
53 out += " bytes), certificate: (";
54 out += base::SizeTToString(
55 message.response().client_auth_certificate().length());
56 out += " bytes)}";
57 }
58 if (message.has_error()) {
59 out += ", error: {";
60 out += base::IntToString(message.error().error_type());
61 out += "}";
62 }
63 out += "}";
64 return out;
65 }
66
67 void CreateAuthChallengeMessage(CastMessage* message_proto,
68 const AuthContext& auth_context) {
69 CHECK(message_proto);
70 DeviceAuthMessage auth_message;
71 auth_message.mutable_challenge()->set_sender_nonce(auth_context.nonce());
72 std::string auth_message_string;
73 auth_message.SerializeToString(&auth_message_string);
74
75 message_proto->set_protocol_version(CastMessage_ProtocolVersion_CASTV2_1_0);
76 message_proto->set_source_id(kPlatformSenderId);
77 message_proto->set_destination_id(kPlatformReceiverId);
78 message_proto->set_namespace_(kAuthNamespace);
79 message_proto->set_payload_type(CastMessage_PayloadType_BINARY);
80 message_proto->set_payload_binary(auth_message_string);
81 }
82
83 bool IsAuthMessage(const CastMessage& message) {
84 return message.namespace_() == kAuthNamespace;
85 }
86
87 } // namespace cast_channel
OLDNEW
« no previous file with comments | « components/cast_channel/cast_message_util.h ('k') | components/cast_channel/cast_socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698