EnricoMi commented on code in PR #46017: URL: https://github.com/apache/arrow/pull/46017#discussion_r2028970319
########## cpp/src/parquet/encryption/secure_string.cc: ########## @@ -0,0 +1,103 @@ +// 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 "parquet/encryption/secure_string.h" + +#include <openssl/crypto.h> +#include <openssl/opensslv.h> +#include <utility> +#if defined(_WIN32) +# include <windows.h> +#endif + +#include "arrow/util/span.h" +#include "parquet/encryption/encryption.h" + +namespace parquet::encryption { +SecureString::SecureString(SecureString&& secret) noexcept + : secret_(std::move(secret.secret_)) {} +SecureString::SecureString(std::string&& secret) noexcept : secret_(std::move(secret)) { + secure_clear(secret); +} + +SecureString& SecureString::operator=(SecureString&& secret) noexcept { + if (this == &secret) { + // self-assignment + return *this; + } + dispose(); + secret_ = std::move(secret.secret_); + return *this; +} +SecureString& SecureString::operator=(const SecureString& secret) noexcept { + if (this == &secret) { + // self-assignment + return *this; + } + dispose(); + secret_ = secret.secret_; + return *this; +} +SecureString& SecureString::operator=(std::string&& secret) noexcept { + dispose(); + secret_ = std::move(secret); + secure_clear(secret); + return *this; +} + +bool SecureString::operator==(const SecureString& other) const { + return secret_ == other.secret_; +} + +bool SecureString::operator!=(const SecureString& other) const { + return secret_ != other.secret_; +} + +bool SecureString::empty() const { return secret_.empty(); } +std::size_t SecureString::size() const { return secret_.size(); } +std::size_t SecureString::length() const { return secret_.length(); } +::arrow::util::span<const uint8_t> SecureString::as_span() const { + return str2span(secret_); Review Comment: Content is ```c++ if (str.empty()) { return {}; } return {reinterpret_cast<const uint8_t*>(str.data()), str.size()}; ``` I am not sure how much benefit the `if` clause provides, but I doubt it pays off for the extra conditional branch. `SecureString` could be expected not to be empty in general, so I removed the `if` clause from `as_span`. -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org