aboutsummaryrefslogtreecommitdiff
path: root/cast/sender/channel/message_util.cc
blob: ab3ed5d807d32c2b958d743687b8a316cf230445 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2019 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 "cast/sender/channel/message_util.h"

#include "cast/sender/channel/cast_auth_util.h"

namespace cast {
namespace channel {

CastMessage CreateAuthChallengeMessage(const AuthContext& auth_context) {
  CastMessage message;
  DeviceAuthMessage auth_message;

  AuthChallenge* challenge = auth_message.mutable_challenge();
  challenge->set_sender_nonce(auth_context.nonce());
  challenge->set_hash_algorithm(SHA256);

  std::string auth_message_string;
  auth_message.SerializeToString(&auth_message_string);

  message.set_protocol_version(CastMessage::CASTV2_1_0);
  message.set_source_id(kPlatformSenderId);
  message.set_destination_id(kPlatformReceiverId);
  message.set_namespace_(kAuthNamespace);
  message.set_payload_type(CastMessage_PayloadType_BINARY);
  message.set_payload_binary(auth_message_string);

  return message;
}

}  // namespace channel
}  // namespace cast