From a91839bf7e89c559cf26d0440af8016577bcdbe5 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Fri, 4 Sep 2015 11:51:19 -0700 Subject: [PATCH] Store a copy of the encryption key --- shared_realm.cpp | 16 +++++++++++----- shared_realm.hpp | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/shared_realm.cpp b/shared_realm.cpp index a7269591eb..fc5eaa2ee1 100644 --- a/shared_realm.cpp +++ b/shared_realm.cpp @@ -17,9 +17,11 @@ //////////////////////////////////////////////////////////////////////////// #include "shared_realm.hpp" + +#include #include #include -#include + #include 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(*c.schema); } + if (c.encryption_key) { + encryption_key = std::make_unique(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(config.path, config.encryption_key.data(), Group::mode_ReadOnly); + m_read_only_group = std::make_unique(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(*m_history, durability, config.encryption_key.data()); + m_shared_group = std::make_unique(*m_history, durability, config.encryption_key.get()); m_group = nullptr; } } diff --git a/shared_realm.hpp b/shared_realm.hpp index af8b774a92..d3c1926338 100644 --- a/shared_realm.hpp +++ b/shared_realm.hpp @@ -45,7 +45,7 @@ namespace realm { std::string path; bool read_only; bool in_memory; - StringData encryption_key; + std::unique_ptr encryption_key; std::unique_ptr schema; uint64_t schema_version;