From b69876b1786f5e99448266a3b74ca4404d7118fd Mon Sep 17 00:00:00 2001 From: buttercat1791 Date: Sun, 16 Jun 2024 12:21:34 -0500 Subject: Convert hex string back to binary before assigning --- src/signer/noscrypt_signer.cpp | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) (limited to 'src/signer') 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(const_cast(value.data())); auto seckey = make_unique(); - 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(const_cast(value.data())); auto pubkey = make_unique(); - 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(const_cast(value.data())); auto pubkey = make_unique(); - 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); }; -- cgit