Store a copy of the encryption key
This commit is contained in:
parent
591ec90e67
commit
5c1e20a7b1
|
@ -17,9 +17,11 @@
|
|||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "shared_realm.hpp"
|
||||
|
||||
#include <realm/commit_log.hpp>
|
||||
#include <realm/group_shared.hpp>
|
||||
#include <realm/lang_bind_helper.hpp>
|
||||
#include <realm/commit_log.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
using namespace realm;
|
||||
|
@ -27,25 +29,29 @@ using namespace realm;
|
|||
RealmCache Realm::s_global_cache;
|
||||
std::mutex Realm::s_init_mutex;
|
||||
|
||||
Realm::Config::Config(const Config& c) : path(c.path), read_only(c.read_only), in_memory(c.in_memory), schema_version(c.schema_version), encryption_key(c.encryption_key), migration_function(c.migration_function)
|
||||
Realm::Config::Config(const Config& c) : path(c.path), read_only(c.read_only), in_memory(c.in_memory), schema_version(c.schema_version), migration_function(c.migration_function)
|
||||
{
|
||||
if (c.schema) {
|
||||
schema = std::make_unique<Schema>(*c.schema);
|
||||
}
|
||||
if (c.encryption_key) {
|
||||
encryption_key = std::make_unique<char[]>(64);
|
||||
memcpy(encryption_key.get(), c.encryption_key.get(), 64);
|
||||
}
|
||||
}
|
||||
|
||||
Realm::Realm(Config &config) : m_config(config), m_thread_id(std::this_thread::get_id()), m_auto_refresh(true), m_in_transaction(false)
|
||||
{
|
||||
try {
|
||||
if (config.read_only) {
|
||||
m_read_only_group = std::make_unique<Group>(config.path, config.encryption_key.data(), Group::mode_ReadOnly);
|
||||
m_read_only_group = std::make_unique<Group>(config.path, config.encryption_key.get(), Group::mode_ReadOnly);
|
||||
m_group = m_read_only_group.get();
|
||||
}
|
||||
else {
|
||||
m_history = realm::make_client_history(config.path, config.encryption_key.data());
|
||||
m_history = realm::make_client_history(config.path, config.encryption_key.get());
|
||||
SharedGroup::DurabilityLevel durability = config.in_memory ? SharedGroup::durability_MemOnly :
|
||||
SharedGroup::durability_Full;
|
||||
m_shared_group = std::make_unique<SharedGroup>(*m_history, durability, config.encryption_key.data());
|
||||
m_shared_group = std::make_unique<SharedGroup>(*m_history, durability, config.encryption_key.get());
|
||||
m_group = nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace realm {
|
|||
std::string path;
|
||||
bool read_only;
|
||||
bool in_memory;
|
||||
StringData encryption_key;
|
||||
std::unique_ptr<char[]> encryption_key;
|
||||
|
||||
std::unique_ptr<Schema> schema;
|
||||
uint64_t schema_version;
|
||||
|
|
Loading…
Reference in New Issue