aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar buttercat1791 <mjjurkoic@gmail.com>2024-06-16 12:21:34 -0500
committerLibravatar buttercat1791 <mjjurkoic@gmail.com>2024-06-16 12:21:34 -0500
commitb69876b1786f5e99448266a3b74ca4404d7118fd (patch)
treece5f693265834aedfba5559237e9bd2ef61d379c
parent39b50919f4a9aaa2ece139c40e7927bb7b033834 (diff)
Convert hex string back to binary before assigning
-rw-r--r--src/signer/noscrypt_signer.cpp39
1 files changed, 30 insertions, 9 deletions
diff --git a/src/signer/noscrypt_signer.cpp b/src/signer/noscrypt_signer.cpp
index bcc7c7e..68cdf6a 100644
--- a/src/signer/noscrypt_signer.cpp
+++ b/src/signer/noscrypt_signer.cpp
@@ -184,10 +184,17 @@ inline string NoscryptSigner::_getLocalPrivateKey() const
inline void NoscryptSigner::_setLocalPrivateKey(const string value)
{
- auto seckeyBuf = reinterpret_cast<uint8_t*>(const_cast<char*>(value.data()));
auto seckey = make_unique<NCSecretKey>();
- memcpy(seckey->key, seckeyBuf, sizeof(NCSecretKey));
-
+
+ for (auto i = 0; i < sizeof(NCSecretKey); i++)
+ {
+ stringstream ss;
+ ss << hex << value.substr(i * 2, 2);
+ uint8_t byte;
+ ss >> byte;
+ seckey->key[i] = byte;
+ }
+
this->_localPrivateKey = move(seckey);
};
@@ -204,10 +211,17 @@ inline string NoscryptSigner::_getLocalPublicKey() const
inline void NoscryptSigner::_setLocalPublicKey(const string value)
{
- auto pubkeyBuf = reinterpret_cast<uint8_t*>(const_cast<char*>(value.data()));
auto pubkey = make_unique<NCPublicKey>();
- memcpy(pubkey->key, pubkeyBuf, sizeof(NCPublicKey));
-
+
+ for (auto i = 0; i < sizeof(NCPublicKey); i++)
+ {
+ stringstream ss;
+ ss << hex << value.substr(i * 2, 2);
+ uint8_t byte;
+ ss >> byte;
+ pubkey->key[i] = byte;
+ }
+
this->_localPublicKey = move(pubkey);
};
@@ -224,10 +238,17 @@ inline string NoscryptSigner::_getRemotePublicKey() const
inline void NoscryptSigner::_setRemotePublicKey(const string value)
{
- auto pubkeyBuf = reinterpret_cast<uint8_t*>(const_cast<char*>(value.data()));
auto pubkey = make_unique<NCPublicKey>();
- memcpy(pubkey->key, pubkeyBuf, sizeof(NCPublicKey));
-
+
+ for (auto i = 0; i < sizeof(NCPublicKey); i++)
+ {
+ stringstream ss;
+ ss << hex << value.substr(i * 2, 2);
+ uint8_t byte;
+ ss >> byte;
+ pubkey->key[i] = byte;
+ }
+
this->_remotePublicKey = move(pubkey);
};