@@ -1140,6 +1140,18 @@ namespace jwt {
11401140 */
11411141 hmacsha (std::string key, const EVP_MD* (*md)(), std::string name)
11421142 : 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)) {
1148+ }
1149+ ~hmacsha (){
1150+ BN_free (secret)
1151+ }
1152+ hmacsha& operator =(const hmacsha& other) = default ;
1153+ hmacsha& operator =(hmacsha&& other) = default ;
1154+
11431155 /* *
11441156 * Sign jwt data
11451157 *
@@ -1152,9 +1164,8 @@ namespace jwt {
11521164 std::string res (static_cast <size_t >(EVP_MAX_MD_SIZE), ' \0 ' );
11531165 auto len = static_cast <unsigned int >(res.size ());
11541166
1155- const BIGNUM* secret_bn = secret.get ();
1156- std::vector<unsigned char > buffer (BN_num_bytes (secret_bn), ' \0 ' );
1157- const auto buffer_size = BN_bn2bin (secret_bn, buffer.data ());
1167+ std::vector<unsigned char > buffer (BN_num_bytes (secret), ' \0 ' );
1168+ const auto buffer_size = BN_bn2bin (secret, buffer.data ());
11581169 buffer.resize (buffer_size);
11591170
11601171 if (HMAC (md (), buffer.data (), buffer_size,
@@ -1197,7 +1208,7 @@ namespace jwt {
11971208
11981209 private:
11991210 // / HMAC secret
1200- const std::unique_ptr< BIGNUM, decltype (&BN_free)> secret;
1211+ const BIGNUM* secret;
12011212 // / HMAC hash generator
12021213 const EVP_MD* (*md)();
12031214 // / algorithm's name
0 commit comments