fgerlits commented on a change in pull request #1090:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r664074774



##########
File path: extensions/rocksdb-repos/database/RocksDbUtils.h
##########
@@ -38,19 +38,14 @@ class Writable {
  public:
   explicit Writable(T& target) : target_(target) {}
 
-  template<typename F>
-  void set(F T::* member, typename utils::type_identity<F>::type value) {
-    if (!(target_.*member == value)) {
+  template<typename F, typename Comparator = std::equal_to<F>>
+  void set(F T::* member, typename utils::type_identity<F>::type value, const 
Comparator& comparator = Comparator{}) {
+    if (!comparator(target_.*member, value)) {
       target_.*member = value;
       is_modified_ = true;
     }
   }
 
-  template<typename Transformer, typename F>
-  void transform(F T::* member) {
-    set(member, Transformer::transform(target_.*member));
-  }

Review comment:
       can `StringAppender::transform()` be removed, too?

##########
File path: extensions/rocksdb-repos/database/RocksDbInstance.cpp
##########
@@ -99,6 +112,7 @@ utils::optional<OpenRocksDb> RocksDbInstance::open(const 
std::string& column, co
       return utils::nullopt;
     }
     gsl_Expects(db_instance);
+    db_options_patch_ = db_options_patch;

Review comment:
       this seems to be the only place where we use 
`RocksDbInstance::db_options_patch_`; can it be removed?

##########
File path: libminifi/test/rocksdb-tests/EncryptionTests.cpp
##########
@@ -0,0 +1,108 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../TestBase.h"
+#include "utils/TestUtils.h"
+#include "FlowFileRepository.h"
+#include "utils/IntegrationTestUtils.h"
+
+using utils::Path;
+using core::repository::FlowFileRepository;
+
+class FFRepoFixture : public TestController {
+ public:
+  FFRepoFixture() {
+    LogTestController::getInstance().setDebug<minifi::FlowFileRecord>();
+    LogTestController::getInstance().setDebug<minifi::Connection>();
+    LogTestController::getInstance().setTrace<FlowFileRepository>();
+    home_ = createTempDirectory("/var/tmp/testRepo.XXXXXX");
+    repo_dir_ = home_ / "flowfile_repo";
+    checkpoint_dir_ = home_ / "checkpoint_dir";
+    config_ = std::make_shared<minifi::Configure>();
+    config_->setHome(home_.str());
+    container_ = std::make_shared<minifi::Connection>(nullptr, nullptr, 
"container");
+    content_repo_ = 
std::make_shared<core::repository::VolatileContentRepository>();
+    content_repo_->initialize(config_);
+  }
+
+  static void putFlowFile(const std::shared_ptr<minifi::FlowFileRecord>& 
flowfile, const std::shared_ptr<core::repository::FlowFileRepository>& repo) {
+    minifi::io::BufferStream buffer;
+    flowfile->Serialize(buffer);
+    REQUIRE(repo->Put(flowfile->getUUIDStr(), buffer.getBuffer(), 
buffer.size()));
+  }
+
+  template<typename Fn>
+  void runWithNewRepository(Fn&& fn) {
+    auto repository = std::make_shared<FlowFileRepository>("ff", 
checkpoint_dir_.str(), repo_dir_.str());
+    repository->initialize(config_);
+    std::map<std::string, std::shared_ptr<core::Connectable>> container_map;
+    container_map[container_->getUUIDStr()] = container_;
+    repository->setContainers(container_map);
+    repository->loadComponent(content_repo_);
+    repository->start();
+    std::forward<Fn>(fn)(repository);
+    repository->stop();
+  }
+
+ protected:
+  std::shared_ptr<minifi::Connection> container_;
+  Path home_;
+  Path repo_dir_;
+  Path checkpoint_dir_;
+  std::shared_ptr<minifi::Configure> config_;
+  std::shared_ptr<core::repository::VolatileContentRepository> content_repo_;
+};
+
+TEST_CASE_METHOD(FFRepoFixture, "FlowFileRepository creates checkpoint and 
loads flowfiles") {
+  SECTION("Without encryption") {
+    // pass
+  }
+  SECTION("With encryption") {
+    utils::file::FileUtils::create_dir((home_ / "conf").str());
+    std::ofstream{(home_ / "conf" / "bootstrap.conf").str()}
+      << static_cast<const char*>(FlowFileRepository::ENCRYPTION_KEY_NAME) << 
"="

Review comment:
       why is this cast needed?  `FlowFileRepository::ENCRYPTION_KEY_NAME` is 
already a `const char*`

##########
File path: libminifi/src/utils/crypto/ciphers/Aes256Ecb.cpp
##########
@@ -0,0 +1,122 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/crypto/ciphers/Aes256Ecb.h"
+#include "openssl/conf.h"
+#include "openssl/evp.h"
+#include "openssl/err.h"
+#include "openssl/rand.h"
+#include "core/logging/LoggerConfiguration.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+namespace crypto {
+
+using EVP_CIPHER_CTX_ptr = std::unique_ptr<EVP_CIPHER_CTX, 
decltype(&EVP_CIPHER_CTX_free)>;
+
+std::shared_ptr<core::logging::Logger> 
Aes256EcbCipher::logger_{core::logging::LoggerFactory<Aes256EcbCipher>::getLogger()};
+
+Aes256EcbCipher::Aes256EcbCipher(Bytes encryption_key) : 
encryption_key_(std::move(encryption_key)) {
+  if (encryption_key_.size() != KEY_SIZE) {
+    handleError("Invalid key length %zu bytes, expected %zu bytes", 
encryption_key_.size(), static_cast<size_t>(KEY_SIZE));
+  }
+}
+
+Bytes Aes256EcbCipher::generateKey() {

Review comment:
       we already have `utils::crypto::randomBytes()` in EncryptionUtils which 
does the same thing (but instead of libressl it uses libsodium, which is better 
according to @alopresto)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to