Skip to content

Commit 2728924

Browse files
touchups making copyable
1 parent 730630d commit 2728924

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

include/jwt-cpp/jwt.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,18 +1139,18 @@ namespace jwt {
11391139
* \param name Name of the algorithm
11401140
*/
11411141
hmacsha(std::string key, const EVP_MD* (*md)(), std::string name)
1142-
: secret(helper::raw2bn(key)), md(md), alg_name(std::move(name)) {}
1143-
hmacsha(const hmacsha& other) :
1144-
secret(BN_dup(other.secret)), md(other.md), alg_name(other.alg_name) {
1145-
}
1146-
hmacsha(hmacsha&& other) :
1147-
secret(BN_copy(other.secret)), md(std::move(other.md)), alg_name(std::move(other.alg_name)) {
1142+
: secret(helper::raw2bn(key).release()), md(md), alg_name(std::move(name)) {}
1143+
hmacsha(const hmacsha& other)
1144+
: secret(BN_dup(other.secret)), md(other.md), alg_name(other.alg_name) {}
1145+
hmacsha(hmacsha&& other)
1146+
: secret(nullptr), md(std::move(other.md)), alg_name(std::move(other.alg_name)) {
1147+
if(BN_copy(other.secret, secret) == nullptr) throw std::runtime_error("failed to copy BN");
11481148
}
11491149
~hmacsha(){
1150-
BN_free(secret)
1150+
BN_free(secret);
11511151
}
1152-
hmacsha& operator=(const hmacsha& other) = default;
1153-
hmacsha& operator=(hmacsha&& other) = default;
1152+
hmacsha& operator=(const hmacsha& other) = delete;
1153+
hmacsha& operator=(hmacsha&& other) = delete;
11541154

11551155
/**
11561156
* Sign jwt data
@@ -1208,7 +1208,7 @@ namespace jwt {
12081208

12091209
private:
12101210
/// HMAC secret
1211-
const BIGNUM* secret;
1211+
BIGNUM* secret;
12121212
/// HMAC hash generator
12131213
const EVP_MD* (*md)();
12141214
/// algorithm's name

0 commit comments

Comments
 (0)