Changeset View
Changeset View
Standalone View
Standalone View
native/cpp/CommonCpp/CryptoTools/Session.cpp
#include "Session.h" | #include "Session.h" | ||||
#include "PlatformSpecificTools.h" | #include "PlatformSpecificTools.h" | ||||
#include <stdexcept> | #include <stdexcept> | ||||
namespace comm { | namespace comm { | ||||
namespace crypto { | namespace crypto { | ||||
std::unique_ptr<Session> Session::createSessionAsInitializer( | std::unique_ptr<Session> Session::createSessionAsInitializer( | ||||
OlmAccount *account, | OlmAccount *account, | ||||
std::uint8_t *ownerIdentityKeys, | std::uint8_t *ownerIdentityKeys, | ||||
const OlmBuffer &idKeys, | const OlmBuffer &idKeys, | ||||
const OlmBuffer &preKeys, | |||||
const OlmBuffer &oneTimeKeys, | const OlmBuffer &oneTimeKeys, | ||||
size_t keyIndex) { | size_t keyIndex) { | ||||
std::unique_ptr<Session> session(new Session(account, ownerIdentityKeys)); | std::unique_ptr<Session> session(new Session(account, ownerIdentityKeys)); | ||||
session->olmSessionBuffer.resize(::olm_session_size()); | session->olmSessionBuffer.resize(::olm_session_size()); | ||||
session->olmSession = ::olm_session(session->olmSessionBuffer.data()); | session->olmSession = ::olm_session(session->olmSessionBuffer.data()); | ||||
OlmBuffer randomBuffer; | OlmBuffer randomBuffer; | ||||
PlatformSpecificTools::generateSecureRandomBytes( | PlatformSpecificTools::generateSecureRandomBytes( | ||||
randomBuffer, | randomBuffer, | ||||
::olm_create_outbound_session_random_length(session->olmSession)); | ::olm_create_outbound_session_random_length(session->olmSession)); | ||||
if (-1 == | if (-1 == | ||||
::olm_create_outbound_session( | ::olm_create_outbound_session( | ||||
session->olmSession, | session->olmSession, | ||||
session->ownerUserAccount, | session->ownerUserAccount, | ||||
idKeys.data() + ID_KEYS_PREFIX_OFFSET, | idKeys.data() + ID_KEYS_PREFIX_OFFSET, | ||||
KEYSIZE, | KEYSIZE, | ||||
preKeys.data() + PRE_KEY_PREFIX_OFFSET, | |||||
KEYSIZE, | |||||
oneTimeKeys.data() + ONE_TIME_KEYS_PREFIX_OFFSET + | oneTimeKeys.data() + ONE_TIME_KEYS_PREFIX_OFFSET + | ||||
(KEYSIZE + ONE_TIME_KEYS_MIDDLE_OFFSET) * keyIndex, | (KEYSIZE + ONE_TIME_KEYS_MIDDLE_OFFSET) * keyIndex, | ||||
KEYSIZE, | KEYSIZE, | ||||
randomBuffer.data(), | randomBuffer.data(), | ||||
randomBuffer.size())) { | randomBuffer.size())) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"error createOutbound => ::olm_create_outbound_session"); | "error createOutbound => ::olm_create_outbound_session"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 71 Lines • Show Last 20 Lines |