Skip to content

Commit

Permalink
Fixed formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mikael-s-persson committed Feb 3, 2025
1 parent 6c1ebbd commit ab50757
Showing 1 changed file with 38 additions and 46 deletions.
84 changes: 38 additions & 46 deletions include/cpr/secure_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,54 @@ namespace cpr::util {
// sections.
template <typename T>
struct SecureAllocator : private std::allocator<T> {
template <typename U>
friend struct SecureAllocator;
SecureAllocator() = default;
template <typename U>
// NOLINTNEXTLINE(google-explicit-constructor,hicpp-explicit-conversions)
SecureAllocator(const SecureAllocator<U>& rhs) noexcept
: std::allocator<T>(static_cast<const std::allocator<U>&>(rhs)) {}
template <typename U>
// NOLINTNEXTLINE(google-explicit-constructor,hicpp-explicit-conversions)
SecureAllocator(SecureAllocator<U>&& rhs) noexcept
: std::allocator<T>(static_cast<std::allocator<U>&&>(rhs)) {}
template <typename U>
SecureAllocator& operator=(const SecureAllocator<U>& rhs) noexcept {
static_cast<std::allocator<T>&>(*this) =
static_cast<const std::allocator<U>&>(rhs);
return *this;
}
template <typename U>
SecureAllocator& operator=(SecureAllocator<U>&& rhs) noexcept {
static_cast<std::allocator<T>&>(*this) =
static_cast<std::allocator<U>&&>(rhs);
return *this;
}
template <typename U>
friend struct SecureAllocator;
SecureAllocator() = default;
template <typename U>
// NOLINTNEXTLINE(google-explicit-constructor,hicpp-explicit-conversions)
SecureAllocator(const SecureAllocator<U>& rhs) noexcept : std::allocator<T>(static_cast<const std::allocator<U>&>(rhs)) {}
template <typename U>
// NOLINTNEXTLINE(google-explicit-constructor,hicpp-explicit-conversions)
SecureAllocator(SecureAllocator<U>&& rhs) noexcept : std::allocator<T>(static_cast<std::allocator<U>&&>(rhs)) {}
template <typename U>
SecureAllocator& operator=(const SecureAllocator<U>& rhs) noexcept {
static_cast<std::allocator<T>&>(*this) = static_cast<const std::allocator<U>&>(rhs);
return *this;
}
template <typename U>
SecureAllocator& operator=(SecureAllocator<U>&& rhs) noexcept {
static_cast<std::allocator<T>&>(*this) = static_cast<std::allocator<U>&&>(rhs);
return *this;
}

using value_type = T;
using value_type = T;

// NOLINTNEXTLINE(readability-identifier-naming)
T* allocate(std::size_t n) {
return static_cast<std::allocator<T>&>(*this).allocate(n);
}
// NOLINTNEXTLINE(readability-identifier-naming)
T* allocate(std::size_t n) {
return static_cast<std::allocator<T>&>(*this).allocate(n);
}

// NOLINTNEXTLINE(readability-identifier-naming)
void deallocate(T* p, std::size_t n) {
std::fill_n(p, n, T{});
static_cast<std::allocator<T>&>(*this).deallocate(p, n);
}
// NOLINTNEXTLINE(readability-identifier-naming)
void deallocate(T* p, std::size_t n) {
std::fill_n(p, n, T{});
static_cast<std::allocator<T>&>(*this).deallocate(p, n);
}

template <typename U>
[[nodiscard]] bool IsEqual(const SecureAllocator<U>& rhs) const noexcept {
return static_cast<const std::allocator<T>&>(*this) ==
static_cast<const std::allocator<U>&>(rhs);
}
template <typename U>
[[nodiscard]] bool IsEqual(const SecureAllocator<U>& rhs) const noexcept {
return static_cast<const std::allocator<T>&>(*this) == static_cast<const std::allocator<U>&>(rhs);
}
};
template <typename T, typename U>
bool operator==(const SecureAllocator<T>& lhs,
const SecureAllocator<U>& rhs) noexcept {
return lhs.IsEqual(rhs);
bool operator==(const SecureAllocator<T>& lhs, const SecureAllocator<U>& rhs) noexcept {
return lhs.IsEqual(rhs);
}
template <typename T, typename U>
bool operator!=(const SecureAllocator<T>& lhs,
const SecureAllocator<U>& rhs) noexcept {
return !lhs.IsEqual(rhs);
bool operator!=(const SecureAllocator<T>& lhs, const SecureAllocator<U>& rhs) noexcept {
return !lhs.IsEqual(rhs);
}

using SecureString =
std::basic_string<char, std::char_traits<char>, SecureAllocator<char>>;
using SecureString = std::basic_string<char, std::char_traits<char>, SecureAllocator<char>>;

} // namespace cpr::util

Expand Down

0 comments on commit ab50757

Please sign in to comment.