Skip to content

Commit

Permalink
Store a copy of the encryption key
Browse files Browse the repository at this point in the history
  • Loading branch information
tgoyne committed Sep 4, 2015
1 parent 0700428 commit a91839b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions shared_realm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,41 @@
////////////////////////////////////////////////////////////////////////////

#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;

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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion shared_realm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a91839b

Please sign in to comment.