From 3107bd89884ca220b52b316aebf0f6c5bee6c480 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Fri, 4 Aug 2023 17:35:02 -0400 Subject: [PATCH] For swap use ADL instead of specializing std::swap Not using ADL is a remnant of pre-C++11 --- src/lib/math/bigint/bigint.h | 11 ++--------- src/lib/pubkey/ec_group/curve_gfp.h | 11 ++--------- src/lib/pubkey/ec_group/ec_point.h | 11 ++--------- 3 files changed, 6 insertions(+), 27 deletions(-) diff --git a/src/lib/math/bigint/bigint.h b/src/lib/math/bigint/bigint.h index 9be3d794253..5a6820d1840 100644 --- a/src/lib/math/bigint/bigint.h +++ b/src/lib/math/bigint/bigint.h @@ -171,6 +171,8 @@ class BOTAN_PUBLIC_API(2, 0) BigInt final { std::swap(m_signedness, other.m_signedness); } + friend void swap(BigInt& x, BigInt& y) { x.swap(y); } + void swap_reg(secure_vector& reg) { m_data.swap(reg); // sign left unchanged @@ -1034,13 +1036,4 @@ BOTAN_PUBLIC_API(2, 0) std::istream& operator>>(std::istream&, BigInt&); } // namespace Botan -namespace std { - -template <> -inline void swap(Botan::BigInt& x, Botan::BigInt& y) { - x.swap(y); -} - -} // namespace std - #endif diff --git a/src/lib/pubkey/ec_group/curve_gfp.h b/src/lib/pubkey/ec_group/curve_gfp.h index d42a14351d4..cf8f79c6aa1 100644 --- a/src/lib/pubkey/ec_group/curve_gfp.h +++ b/src/lib/pubkey/ec_group/curve_gfp.h @@ -179,6 +179,8 @@ class BOTAN_UNSTABLE_API CurveGFp final { void swap(CurveGFp& other) { std::swap(m_repr, other.m_repr); } + friend void swap(CurveGFp& x, CurveGFp& y) { x.swap(y); } + /** * Equality operator * @param other a curve @@ -204,13 +206,4 @@ inline bool operator!=(const CurveGFp& lhs, const CurveGFp& rhs) { } // namespace Botan -namespace std { - -template <> -inline void swap(Botan::CurveGFp& curve1, Botan::CurveGFp& curve2) noexcept { - curve1.swap(curve2); -} - -} // namespace std - #endif diff --git a/src/lib/pubkey/ec_group/ec_point.h b/src/lib/pubkey/ec_group/ec_point.h index 864d93c1e5e..bdbc21ba494 100644 --- a/src/lib/pubkey/ec_group/ec_point.h +++ b/src/lib/pubkey/ec_group/ec_point.h @@ -189,6 +189,8 @@ class BOTAN_PUBLIC_API(2, 0) EC_Point final { */ void swap(EC_Point& other); + friend void swap(EC_Point& x, EC_Point& y) { x.swap(y); } + /** * Randomize the point representation * The actual value (get_affine_x, get_affine_y) does not change @@ -401,13 +403,4 @@ typedef EC_Point PointGFp; } // namespace Botan -namespace std { - -template <> -inline void swap(Botan::EC_Point& x, Botan::EC_Point& y) { - x.swap(y); -} - -} // namespace std - #endif