From 784e4ebf5fd3d1c2a678334a8aa33a85c6c20cd2 Mon Sep 17 00:00:00 2001 From: Chris Mc Date: Tue, 23 Jan 2024 21:50:10 -0800 Subject: [PATCH] touchups making copyable --- include/jwt-cpp/jwt.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/include/jwt-cpp/jwt.h b/include/jwt-cpp/jwt.h index 880e6a328..6ab758018 100644 --- a/include/jwt-cpp/jwt.h +++ b/include/jwt-cpp/jwt.h @@ -1143,18 +1143,18 @@ namespace jwt { * \param name Name of the algorithm */ hmacsha(std::string key, const EVP_MD* (*md)(), std::string name) - : secret(helper::raw2bn(key)), md(md), alg_name(std::move(name)) {} - hmacsha(const hmacsha& other) : - secret(BN_dup(other.secret)), md(other.md), alg_name(other.alg_name) { - } - hmacsha(hmacsha&& other) : - secret(BN_copy(other.secret)), md(std::move(other.md)), alg_name(std::move(other.alg_name)) { + : secret(helper::raw2bn(key).release()), md(md), alg_name(std::move(name)) {} + hmacsha(const hmacsha& other) + : secret(BN_dup(other.secret)), md(other.md), alg_name(other.alg_name) {} + hmacsha(hmacsha&& other) + : secret(nullptr), md(std::move(other.md)), alg_name(std::move(other.alg_name)) { + if(BN_copy(other.secret, secret) == nullptr) throw std::runtime_error("failed to copy BN"); } ~hmacsha(){ - BN_free(secret) + BN_free(secret); } - hmacsha& operator=(const hmacsha& other) = default; - hmacsha& operator=(hmacsha&& other) = default; + hmacsha& operator=(const hmacsha& other) = delete; + hmacsha& operator=(hmacsha&& other) = delete; /** * Sign jwt data @@ -1212,7 +1212,7 @@ namespace jwt { private: /// HMAC secret - const BIGNUM* secret; + BIGNUM* secret; /// HMAC hash generator const EVP_MD* (*md)(); /// algorithm's name