Files
brave-core/net/http/partitioned_host_state_map.cc
cdesouza-chromium 821274796b [IWYU] Fixing logging inclusions pt.11 (#29531)
This change is one of many fixing inclusion for the following files:

    - `base/notimplemented.h`
    - `base/notreached.h`
    - `base/check.h`
    - `base/dcheck_is_on.h`
    - `base/check_deref.h`
    - `base/check_op.h`
    - `base/logging/log_severity.h`
    - `base/logging.h`

This change is a mechanical change done with the following script:
https://github.com/brave/brave-browser/issues/46707#issuecomment-2960116515

Resolves https://github.com/brave/brave-browser/issues/46707
2025-06-12 13:48:07 +01:00

67 lines
2.1 KiB
C++

/* Copyright (c) 2022 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */
#include "brave/net/http/partitioned_host_state_map.h"
#include <algorithm>
#include <optional>
#include <utility>
#include "base/check.h"
#include "base/compiler_specific.h"
#include "base/containers/span.h"
#include "crypto/sha2.h"
#include "net/base/network_isolation_key.h"
namespace {
bool IsEmptyPartitionHash(
const net::PartitionedHostStateMapBase::HashedHost& hashed_host) {
return std::ranges::all_of(hashed_host.begin(), hashed_host.end(),
[](uint8_t i) { return i == 0; });
}
} // namespace
namespace net {
PartitionedHostStateMapBase::PartitionedHostStateMapBase() = default;
PartitionedHostStateMapBase::~PartitionedHostStateMapBase() = default;
base::AutoReset<std::optional<PartitionedHostStateMapBase::HashedHost>>
PartitionedHostStateMapBase::SetScopedPartitionHash(
std::optional<HashedHost> partition_hash) {
return base::AutoReset<std::optional<HashedHost>>(&partition_hash_,
std::move(partition_hash));
}
bool PartitionedHostStateMapBase::HasPartitionHash() const {
return partition_hash_.has_value();
}
bool PartitionedHostStateMapBase::IsPartitionHashValid() const {
return partition_hash_ && !IsEmptyPartitionHash(*partition_hash_);
}
PartitionedHostStateMapBase::HashedHost
PartitionedHostStateMapBase::GetKeyWithPartitionHash(
const HashedHost& k) const {
CHECK(IsPartitionHashValid());
if (k == *partition_hash_) {
return k;
}
HashedHost result;
static_assert(result.size() == crypto::kSHA256Length,
"Unexpected HashedHost size");
base::span(result).first<crypto::kSHA256Length / 2>().copy_from(
base::span(k).first<crypto::kSHA256Length / 2>());
base::span(result).last<crypto::kSHA256Length / 2>().copy_from(
base::span(*partition_hash_).first<crypto::kSHA256Length / 2>());
return result;
}
} // namespace net