chromium/components/feedback/redaction_tool/ip_address.cc

// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

// This is a copy of net/base/ip_address.cc circa 2023. It should be used only
// by components/feedback/redaction_tool/. We need a copy because the
// components/feedback/redaction_tool source code is shared into ChromeOS and
// needs to have no dependencies outside of base/.

#include "components/feedback/redaction_tool/ip_address.h"

#include <algorithm>
#include <climits>
#include <string_view>

#include "base/check_op.h"
#include "base/notreached.h"
#include "base/ranges/algorithm.h"
#include "base/strings/strcat.h"
#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
#include "base/trace_event/memory_usage_estimator.h"
#include "base/values.h"
#include "components/feedback/redaction_tool/url_canon_ip.h"
#include "components/feedback/redaction_tool/url_canon_stdstring.h"
#include "third_party/abseil-cpp/absl/container/inlined_vector.h"

namespace redaction_internal {
namespace {

// The prefix for IPv6 mapped IPv4 addresses.
// https://tools.ietf.org/html/rfc4291#section-2.5.5.2
constexpr uint8_t kIPv4MappedPrefix[] =;

// Note that this function assumes:
// * |ip_address| is at least |prefix_length_in_bits| (bits) long;
// * |ip_prefix| is at least |prefix_length_in_bits| (bits) long.
bool IPAddressPrefixCheck(const IPAddressBytes& ip_address,
                          const uint8_t* ip_prefix,
                          size_t prefix_length_in_bits) {}

bool ParseIPLiteralToBytes(std::string_view ip_literal, IPAddressBytes* bytes) {}

}  // namespace

IPAddressBytes::IPAddressBytes() :{}

IPAddressBytes::IPAddressBytes(const uint8_t* data, size_t data_len) {}

IPAddressBytes::~IPAddressBytes() = default;
IPAddressBytes::IPAddressBytes(IPAddressBytes const& other) = default;

void IPAddressBytes::Assign(const uint8_t* data, size_t data_len) {}

bool IPAddressBytes::operator<(const IPAddressBytes& other) const {}

bool IPAddressBytes::operator==(const IPAddressBytes& other) const {}

bool IPAddressBytes::operator!=(const IPAddressBytes& other) const {}

// static

IPAddress::IPAddress() = default;

IPAddress::IPAddress(const IPAddress& other) = default;

IPAddress::IPAddress(const IPAddressBytes& address) :{}

IPAddress::IPAddress(const uint8_t* address, size_t address_len)
    :{}

IPAddress::IPAddress(uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3) {}

IPAddress::IPAddress(uint8_t b0,
                     uint8_t b1,
                     uint8_t b2,
                     uint8_t b3,
                     uint8_t b4,
                     uint8_t b5,
                     uint8_t b6,
                     uint8_t b7,
                     uint8_t b8,
                     uint8_t b9,
                     uint8_t b10,
                     uint8_t b11,
                     uint8_t b12,
                     uint8_t b13,
                     uint8_t b14,
                     uint8_t b15) {}

IPAddress::~IPAddress() = default;

bool IPAddress::IsIPv4() const {}

bool IPAddress::IsIPv6() const {}

bool IPAddress::IsValid() const {}

bool IPAddress::IsIPv4MappedIPv6() const {}

bool IPAddress::AssignFromIPLiteral(std::string_view ip_literal) {}

// static
IPAddress IPAddress::AllZeros(size_t num_zero_bytes) {}

// static
IPAddress IPAddress::IPv4AllZeros() {}

// static
IPAddress IPAddress::IPv6AllZeros() {}

bool IPAddress::operator==(const IPAddress& that) const {}

bool IPAddress::operator!=(const IPAddress& that) const {}

bool IPAddress::operator<(const IPAddress& that) const {}

std::string IPAddress::ToString() const {}

IPAddress ConvertIPv4ToIPv4MappedIPv6(const IPAddress& address) {}

IPAddress ConvertIPv4MappedIPv6ToIPv4(const IPAddress& address) {}

bool IPAddressMatchesPrefix(const IPAddress& ip_address,
                            const IPAddress& ip_prefix,
                            size_t prefix_length_in_bits) {}

}  // namespace redaction_internal