From 6409c4bbaa9ecfe9bf526821a62ef2d8c0c211f1 Mon Sep 17 00:00:00 2001 From: Sergey Gomenyuk Date: Thu, 21 Nov 2024 22:33:49 +0300 Subject: [PATCH] move code to build with clang 15 --- .github/workflows/release.yml | 2 +- src/configProcessor.h | 131 +++++++++++++++++----------------- 2 files changed, 66 insertions(+), 67 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7de9a16..924e486 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,7 +23,7 @@ jobs: cmakeGen: '"Unix Makefiles"' cc: clang cxx: clang++ - tools: NONINTERACTIVE=1 brew install libomp llvm + tools: NONINTERACTIVE=1 brew install libomp steps: - uses: actions/checkout@v3 diff --git a/src/configProcessor.h b/src/configProcessor.h index a848d9b..9b646fd 100644 --- a/src/configProcessor.h +++ b/src/configProcessor.h @@ -87,27 +87,86 @@ class ConfigProcessor final template [[nodiscard]] std::shared_ptr aquireKey( const std::string_view keyName); + [[nodiscard]] std::shared_ptr> aquireCC( const std::string_view ccName); template - void generateKeyPairAndSerialize( - const std::string_view keyName, - nlohmann::json& keyContent); + void generateKeyPairAndSerialize(const std::string_view keyName, nlohmann::json& keyContent) + { + std::shared_ptr> cc = + aquireCC(keyContent["cryptocontext"].get()); + cc->Enable(lbcrypto::PKE); + lbcrypto::KeyPair keyPair = cc->KeyGen(); + const std::string& linkedKeyName + = keyContent["linked_key_for_generation"].get_ref(); + if (!linkedKeyName.empty()) + { + if (!(m_configJson[linkedKeyName]["linked_key_for_generation"].get() == keyName && + m_configJson[linkedKeyName]["source"].get().empty())) + { + throw std::runtime_error("Incorrect linking between keys"); + } + if constexpr (std::is_same_v>) + { + auto itKey = getKeyMap>().emplace( + linkedKeyName, std::move(getKeyFromKeyPair>(keyPair))).first; + serialize>(linkedKeyName, itKey->second); + } + else + { + auto itKey = getKeyMap>().emplace( + linkedKeyName, std::move(getKeyFromKeyPair>(keyPair))).first; + serialize>(linkedKeyName, itKey->second); + } + updateSource(linkedKeyName, m_configJson[linkedKeyName]); + } + else + { + if constexpr (std::is_same_v>) + { + serialize>(std::string(keyName) + "." + + m_configJson[linkedKeyName]["type"].get(), + getKeyFromKeyPair>(keyPair)); + } + else + { + serialize>(std::string(keyName) + "." + + m_configJson[linkedKeyName]["type"].get(), + getKeyFromKeyPair>(keyPair)); + } + } + auto itKey = getKeyMap().emplace(keyName, std::move(getKeyFromKeyPair(keyPair))).first; + const std::string keyNameStr(itKey->first); + serialize(keyNameStr, itKey->second); + updateSource(keyNameStr, keyContent); + } [[nodiscard]] std::shared_ptr> generateCC( const std::string_view ccName, const nlohmann::json& ccContent); + template [[nodiscard]] static lbcrypto::CCParams getCCParams( const nlohmann::json& ccContent); template - [[nodiscard]] inline auto& getKeyMap() noexcept; + [[nodiscard]] inline auto& getKeyMap() noexcept + { + if constexpr (std::is_same_v, lbcrypto::PrivateKeyImpl>) + return m_privateKeyMap; + else + return m_publicKeyMap; + } template - [[nodiscard]] inline auto& getKeyFromKeyPair( - lbcrypto::KeyPair& keyPair) noexcept; + [[nodiscard]] inline auto& getKeyFromKeyPair(lbcrypto::KeyPair& keyPair) noexcept + { + if constexpr (std::is_same_v, lbcrypto::PrivateKeyImpl>) + return keyPair.secretKey; + else + return keyPair.publicKey; + } inline void updateSource( const std::string& filename, @@ -382,57 +441,6 @@ template return itCC->second; } -template -void ConfigProcessor::generateKeyPairAndSerialize(const std::string_view keyName, nlohmann::json& keyContent) -{ - std::shared_ptr> cc = - aquireCC(keyContent["cryptocontext"].get()); - cc->Enable(lbcrypto::PKE); - lbcrypto::KeyPair keyPair = cc->KeyGen(); - const std::string& linkedKeyName - = keyContent["linked_key_for_generation"].get_ref(); - if (!linkedKeyName.empty()) - { - if (!(m_configJson[linkedKeyName]["linked_key_for_generation"].get() == keyName && - m_configJson[linkedKeyName]["source"].get().empty())) - { - throw std::runtime_error("Incorrect linking between keys"); - } - if constexpr (std::is_same_v>) - { - auto itKey = getKeyMap>().emplace( - linkedKeyName, std::move(getKeyFromKeyPair>(keyPair))).first; - serialize>(linkedKeyName, itKey->second); - } - else - { - auto itKey = getKeyMap>().emplace( - linkedKeyName, std::move(getKeyFromKeyPair>(keyPair))).first; - serialize>(linkedKeyName, itKey->second); - } - updateSource(linkedKeyName, m_configJson[linkedKeyName]); - } - else - { - if constexpr (std::is_same_v>) - { - serialize>(std::string(keyName) + "." + - m_configJson[linkedKeyName]["type"].get(), - getKeyFromKeyPair>(keyPair)); - } - else - { - serialize>(std::string(keyName) + "." + - m_configJson[linkedKeyName]["type"].get(), - getKeyFromKeyPair>(keyPair)); - } - } - auto itKey = getKeyMap().emplace(keyName, std::move(getKeyFromKeyPair(keyPair))).first; - const std::string keyNameStr(itKey->first); - serialize(keyNameStr, itKey->second); - updateSource(keyNameStr, keyContent); -} - [[nodiscard]] std::shared_ptr> ConfigProcessor::generateCC( const std::string_view ccName, const nlohmann::json& ccContent) { @@ -531,15 +539,6 @@ template return m_publicKeyMap; } -template -[[nodiscard]] inline auto& ConfigProcessor::getKeyFromKeyPair(lbcrypto::KeyPair& keyPair) noexcept -{ - if constexpr (std::is_same_v, lbcrypto::PrivateKeyImpl>) - return keyPair.secretKey; - else - return keyPair.publicKey; -} - inline void ConfigProcessor::updateSource(const std::string& filename, nlohmann::json& argContent) { static const std::string path = "local://" + m_outputCryptoObjectsDirectory;