Skip to content

Commit

Permalink
Merge GH #3656 For swapping use ADL instead of specializing std::swap
Browse files Browse the repository at this point in the history
  • Loading branch information
randombit committed Aug 17, 2023
2 parents cf04552 + 3107bd8 commit 7c03c1b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 27 deletions.
11 changes: 2 additions & 9 deletions src/lib/math/bigint/bigint.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<word>& reg) {
m_data.swap(reg);
// sign left unchanged
Expand Down Expand Up @@ -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>(Botan::BigInt& x, Botan::BigInt& y) {
x.swap(y);
}

} // namespace std

#endif
11 changes: 2 additions & 9 deletions src/lib/pubkey/ec_group/curve_gfp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -204,13 +206,4 @@ inline bool operator!=(const CurveGFp& lhs, const CurveGFp& rhs) {

} // namespace Botan

namespace std {

template <>
inline void swap<Botan::CurveGFp>(Botan::CurveGFp& curve1, Botan::CurveGFp& curve2) noexcept {
curve1.swap(curve2);
}

} // namespace std

#endif
11 changes: 2 additions & 9 deletions src/lib/pubkey/ec_group/ec_point.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -401,13 +403,4 @@ typedef EC_Point PointGFp;

} // namespace Botan

namespace std {

template <>
inline void swap<Botan::EC_Point>(Botan::EC_Point& x, Botan::EC_Point& y) {
x.swap(y);
}

} // namespace std

#endif

0 comments on commit 7c03c1b

Please sign in to comment.