Page MenuHomePhorge

D7381.1767439609.diff
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

D7381.1767439609.diff

diff --git a/native/cpp/CommonCpp/CryptoTools/CryptoModule.h b/native/cpp/CommonCpp/CryptoTools/CryptoModule.h
--- a/native/cpp/CommonCpp/CryptoTools/CryptoModule.h
+++ b/native/cpp/CommonCpp/CryptoTools/CryptoModule.h
@@ -39,6 +39,7 @@
std::string getIdentityKeys();
std::string getOneTimeKeys(size_t oneTimeKeysAmount = 50);
+ std::string generatePreKey();
void initializeInboundForReceivingSession(
const std::string &targetUserId,
diff --git a/native/cpp/CommonCpp/CryptoTools/CryptoModule.cpp b/native/cpp/CommonCpp/CryptoTools/CryptoModule.cpp
--- a/native/cpp/CommonCpp/CryptoTools/CryptoModule.cpp
+++ b/native/cpp/CommonCpp/CryptoTools/CryptoModule.cpp
@@ -115,6 +115,35 @@
this->keys.oneTimeKeys.begin(), this->keys.oneTimeKeys.end()};
}
+std::string CryptoModule::generatePreKey() {
+ size_t preKeySize =
+ ::olm_account_generate_prekey_random_length(this->account);
+
+ OlmBuffer random;
+ PlatformSpecificTools::generateSecureRandomBytes(random, preKeySize);
+
+ if (-1 ==
+ ::olm_account_generate_prekey(
+ this->account, random.data(), random.size())) {
+ throw std::runtime_error{
+ "error generatePreKey => " +
+ std::string{::olm_account_last_error(this->account)}};
+ }
+
+ ::olm_account_mark_prekey_as_published(this->account);
+
+ OlmBuffer preKey;
+ preKey.resize(::olm_account_prekey_length(this->account));
+
+ if (-1 == ::olm_account_prekey(this->account, preKey.data(), preKey.size())) {
+ throw std::runtime_error{
+ "error generatePreKey => " +
+ std::string{::olm_account_last_error(this->account)}};
+ }
+
+ return std::string{preKey.begin(), preKey.end()};
+}
+
void CryptoModule::initializeInboundForReceivingSession(
const std::string &targetUserId,
const OlmBuffer &encryptedMessage,

File Metadata

Mime Type
text/plain
Expires
Sat, Jan 3, 11:26 AM (14 h, 2 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5888258
Default Alt Text
D7381.1767439609.diff (1 KB)

Event Timeline