adamdebreceni commented on a change in pull request #1090: URL: https://github.com/apache/nifi-minifi-cpp/pull/1090#discussion_r663970159
########## File path: libminifi/include/utils/crypto/ciphers/Aes256Ecb.h ########## @@ -0,0 +1,69 @@ +/** + * 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. + */ + +#pragma once + +#include <string> +#include <memory> +#include <utility> + +#include "utils/crypto/EncryptionUtils.h" +#include "Exception.h" +#include "core/logging/Logger.h" + +namespace org { +namespace apache { +namespace nifi { +namespace minifi { +namespace utils { +namespace crypto { + +class CipherError : public Exception { + public: + explicit CipherError(const std::string& error_msg) : Exception(ExceptionType::GENERAL_EXCEPTION, error_msg) {} +}; + +class Aes256EcbCipher { + static std::shared_ptr<core::logging::Logger> logger_; + public: + static constexpr size_t BLOCK_SIZE = 16; + static constexpr size_t KEY_SIZE = 32; + + explicit Aes256EcbCipher(Bytes encryption_key); + void encrypt(unsigned char* data) const; + void decrypt(unsigned char* data) const; + + static Bytes generateKey(); + + bool equals(const Aes256EcbCipher& other) const; + + private: + template<typename ...Args> + static void handleError(Args&& ...args) { + std::string error_msg = core::logging::format_string(-1, "%s", std::forward<Args>(args)...); + logger_->log_error("%s", error_msg); + throw CipherError(error_msg); + } Review comment: indeed this would have misbehaved, fixed in [09e2a1e0](https://github.com/apache/nifi-minifi-cpp/pull/1090/commits/09e2a1e0686a320b4e29264b5ff830b0cc74d471) -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
