Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit aabcfbb3 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes Idb1389ce,I0f7013a6

* changes:
  Treat file paths as UTF-8
  Use mersenne twister for random values.
parents 187ce75c 847a018f
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#include "dual_mode_controller.h"

#include <memory>
#include <random>

#include <base/files/file_util.h>
#include <base/json/json_reader.h>
@@ -2240,14 +2241,16 @@ void DualModeController::LeReadRemoteFeatures(CommandView command) {
  send_event_(std::move(packet));
}


static std::random_device rd{};
static std::mt19937_64 s_mt{rd()};

void DualModeController::LeRand(CommandView command) {
  auto command_view = gd_hci::LeRandView::Create(
      gd_hci::LeSecurityCommandView::Create(command));
  ASSERT(command_view.IsValid());
  uint64_t random_val = 0;
  for (size_t rand_bytes = 0; rand_bytes < sizeof(uint64_t); rand_bytes += sizeof(RAND_MAX)) {
    random_val = (random_val << (8 * sizeof(RAND_MAX))) | random();
  }

  uint64_t random_val = s_mt();

  auto packet = bluetooth::hci::LeRandCompleteBuilder::Create(
      kNumCommandPackets, ErrorCode::SUCCESS, random_val);
+1 −1
Original line number Diff line number Diff line
@@ -78,7 +78,7 @@ DeviceProperties::DeviceProperties(const std::string& file_name)
    return;
  }
  LOG_INFO("Reading controller properties from %s.", file_name.c_str());
  if (!base::ReadFileToString(base::FilePath(file_name), &properties_raw)) {
  if (!base::ReadFileToString(base::FilePath::FromUTF8Unsafe(file_name), &properties_raw)) {
    LOG_ERROR("Error reading controller properties from file.");
    return;
  }
+1 −1
Original line number Diff line number Diff line
@@ -103,7 +103,7 @@ void TestCommandHandler::FromFile(const std::string& file_name) {
  }

  std::string commands_raw;
  if (!base::ReadFileToString(base::FilePath(file_name), &commands_raw)) {
  if (!base::ReadFileToString(base::FilePath::FromUTF8Unsafe(file_name), &commands_raw)) {
    LOG_ERROR("Error reading commands from file.");
    return;
  }