Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cpp/src/arrow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,6 @@ if(ARROW_JSON)
json/from_string.cc
json/json_writer_internal.cc
json/object_parser.cc
json/object_writer.cc
json/parser.cc
json/reader.cc)
foreach(ARROW_JSON_TARGET ${ARROW_JSON_TARGETS})
Expand Down
10 changes: 10 additions & 0 deletions cpp/src/arrow/json/json_writer_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,14 @@ void JsonWriter::MaybeComma() {
}
}

void JsonWriter::StringField(std::string_view key, std::string_view value) {
Key(key);
String(value);
}

void JsonWriter::BoolField(std::string_view key, bool value) {
Key(key);
Bool(value);
}

} // namespace arrow::json
3 changes: 3 additions & 0 deletions cpp/src/arrow/json/json_writer_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class ARROW_EXPORT JsonWriter {

void Null();

void StringField(std::string_view key, std::string_view value);
void BoolField(std::string_view key, bool value);

std::string_view GetString() const;

void Clear();
Expand Down
3 changes: 1 addition & 2 deletions cpp/src/arrow/json/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ exc = executable(
'chunker_test.cc',
'converter_test.cc',
'from_string_test.cc',
'json_writer_internal_test.cc',
'parser_test.cc',
'reader_test.cc',
'json_writer_internal_test.cc',
],
dependencies: [arrow_test_dep, rapidjson_dep],
)
Expand All @@ -45,7 +45,6 @@ install_headers(
'converter.h',
'from_string.h',
'object_parser.h',
'object_writer.h',
'options.h',
'parser.h',
'rapidjson_defs.h',
Expand Down
81 changes: 0 additions & 81 deletions cpp/src/arrow/json/object_writer.cc

This file was deleted.

49 changes: 0 additions & 49 deletions cpp/src/arrow/json/object_writer.h

This file was deleted.

1 change: 0 additions & 1 deletion cpp/src/arrow/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,6 @@ if needs_json
'json/from_string.cc',
'json/json_writer_internal.cc',
'json/object_parser.cc',
'json/object_writer.cc',
'json/options.cc',
'json/parser.cc',
'json/reader.cc',
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/parquet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,9 @@ endif()

list(APPEND PARQUET_SHARED_LINK_LIBS arrow_shared)

# Add RapidJSON libraries
list(APPEND PARQUET_SHARED_PRIVATE_LINK_LIBS RapidJSON)
list(APPEND PARQUET_STATIC_LINK_LIBS RapidJSON)
# Add RapidJSON & simdjson libraries
list(APPEND PARQUET_SHARED_PRIVATE_LINK_LIBS RapidJSON simdjson::simdjson)
list(APPEND PARQUET_STATIC_LINK_LIBS RapidJSON simdjson::simdjson)

# These are libraries that we will link privately with parquet_shared (as they
# do not need to be linked transitively by other linkers)
Expand Down
10 changes: 6 additions & 4 deletions cpp/src/parquet/encryption/file_system_key_material_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#include "arrow/buffer.h"
#include "arrow/filesystem/filesystem.h"
#include "arrow/filesystem/path_util.h"
#include "arrow/json/json_writer_internal.h"
#include "arrow/json/object_parser.h"
#include "arrow/json/object_writer.h"
#include "arrow/result.h"

#include "parquet/encryption/file_system_key_material_store.h"
Expand Down Expand Up @@ -81,11 +81,13 @@ void FileSystemKeyMaterialStore::LoadKeyMaterialMap() {
}

std::string FileSystemKeyMaterialStore::BuildKeyMaterialMapJson() {
::arrow::json::internal::ObjectWriter writer;
::arrow::json::JsonWriter writer;
writer.StartObject();
for (const auto& it : key_material_map_) {
writer.SetString(it.first, it.second);
writer.StringField(it.first, it.second);
}
return writer.Serialize();
writer.EndObject();
return std::string(writer.GetString());
}

void FileSystemKeyMaterialStore::SaveMaterial() {
Expand Down
40 changes: 26 additions & 14 deletions cpp/src/parquet/encryption/key_material.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
// specific language governing permissions and limitations
// under the License.

#include "arrow/json/json_writer_internal.h"
#include "arrow/json/object_parser.h"
#include "arrow/json/object_writer.h"

#include "parquet/encryption/key_material.h"
#include "parquet/encryption/key_metadata.h"
#include "parquet/exception.h"

using ::arrow::json::JsonWriter;
using ::arrow::json::internal::ObjectParser;
using ::arrow::json::internal::ObjectWriter;

namespace parquet::encryption {

Expand Down Expand Up @@ -122,36 +122,48 @@ std::string KeyMaterial::SerializeToJson(
bool is_double_wrapped, const std::string& kek_id,
const std::string& encoded_wrapped_kek, const std::string& encoded_wrapped_dek,
bool is_internal_storage) {
ObjectWriter json_writer;
json_writer.SetString(kKeyMaterialTypeField, kKeyMaterialType1);
JsonWriter json_writer;

json_writer.StartObject();

json_writer.StringField(kKeyMaterialTypeField, kKeyMaterialType1);

if (is_internal_storage) {
// 1. for internal storage, key material and key metadata are the same.
// adding the "internalStorage" field that belongs to KeyMetadata.
json_writer.SetBool(KeyMetadata::kKeyMaterialInternalStorageField, true);
json_writer.BoolField(KeyMetadata::kKeyMaterialInternalStorageField, true);
}

// 2. Write isFooterKey
json_writer.SetBool(kIsFooterKeyField, is_footer_key);
json_writer.BoolField(kIsFooterKeyField, is_footer_key);

if (is_footer_key) {
// 3. For footer key, write KMS Instance ID
json_writer.SetString(kKmsInstanceIdField, kms_instance_id);
json_writer.StringField(kKmsInstanceIdField, kms_instance_id);

// 4. For footer key, write KMS Instance URL
json_writer.SetString(kKmsInstanceUrlField, kms_instance_url);
json_writer.StringField(kKmsInstanceUrlField, kms_instance_url);
}

// 5. Write master key ID
json_writer.SetString(kMasterKeyIdField, master_key_id);
json_writer.StringField(kMasterKeyIdField, master_key_id);

// 6. Write wrapped DEK
json_writer.SetString(kWrappedDataEncryptionKeyField, encoded_wrapped_dek);
json_writer.StringField(kWrappedDataEncryptionKeyField, encoded_wrapped_dek);

// 7. Write isDoubleWrapped
json_writer.SetBool(kDoubleWrappingField, is_double_wrapped);
json_writer.BoolField(kDoubleWrappingField, is_double_wrapped);

if (is_double_wrapped) {
// 8. In double wrapping mode, write KEK ID
json_writer.SetString(kKeyEncryptionKeyIdField, kek_id);
json_writer.StringField(kKeyEncryptionKeyIdField, kek_id);

// 9. In double wrapping mode, write wrapped KEK
json_writer.SetString(kWrappedKeyEncryptionKeyField, encoded_wrapped_kek);
json_writer.StringField(kWrappedKeyEncryptionKeyField, encoded_wrapped_kek);
}

return json_writer.Serialize();
json_writer.EndObject();
return std::string(json_writer.GetString());
}

} // namespace parquet::encryption
19 changes: 11 additions & 8 deletions cpp/src/parquet/encryption/key_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
// specific language governing permissions and limitations
// under the License.

#include "arrow/json/json_writer_internal.h"
#include "arrow/json/object_parser.h"
#include "arrow/json/object_writer.h"

#include "parquet/encryption/key_metadata.h"
#include "parquet/exception.h"

using ::arrow::json::JsonWriter;
using ::arrow::json::internal::ObjectParser;
using ::arrow::json::internal::ObjectWriter;

namespace parquet::encryption {

Expand Down Expand Up @@ -73,15 +73,18 @@ KeyMetadata KeyMetadata::Parse(const std::string& key_metadata) {
// directly
std::string KeyMetadata::CreateSerializedForExternalMaterial(
const std::string& key_reference) {
ObjectWriter json_writer;
JsonWriter json_writer;

json_writer.SetString(KeyMaterial::kKeyMaterialTypeField,
KeyMaterial::kKeyMaterialType1);
json_writer.SetBool(kKeyMaterialInternalStorageField, false);
json_writer.StartObject();

json_writer.SetString(kKeyReferenceField, key_reference);
json_writer.StringField(KeyMaterial::kKeyMaterialTypeField,
KeyMaterial::kKeyMaterialType1);
json_writer.BoolField(kKeyMaterialInternalStorageField, false);
json_writer.StringField(kKeyReferenceField, key_reference);

return json_writer.Serialize();
json_writer.EndObject();

return std::string(json_writer.GetString());
}

} // namespace parquet::encryption
16 changes: 10 additions & 6 deletions cpp/src/parquet/encryption/local_wrap_kms_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
// specific language governing permissions and limitations
// under the License.

#include "arrow/json/json_writer_internal.h"
#include "arrow/json/object_parser.h"
#include "arrow/json/object_writer.h"
#include "arrow/util/secure_string.h"

#include "parquet/encryption/key_toolkit_internal.h"
#include "parquet/encryption/local_wrap_kms_client.h"
#include "parquet/exception.h"

using ::arrow::json::JsonWriter;
using ::arrow::json::internal::ObjectParser;
using ::arrow::json::internal::ObjectWriter;
using ::arrow::util::SecureString;

namespace parquet::encryption {
Expand All @@ -41,12 +41,16 @@ LocalWrapKmsClient::LocalKeyWrap::LocalKeyWrap(std::string master_key_version,

std::string LocalWrapKmsClient::LocalKeyWrap::CreateSerialized(
const std::string& encrypted_encoded_key) {
ObjectWriter json_writer;
JsonWriter json_writer;

json_writer.SetString(kLocalWrapKeyVersionField, kLocalWrapNoKeyVersion);
json_writer.SetString(kLocalWrapEncryptedKeyField, encrypted_encoded_key);
json_writer.StartObject();

return json_writer.Serialize();
json_writer.StringField(kLocalWrapKeyVersionField, kLocalWrapNoKeyVersion);
json_writer.StringField(kLocalWrapEncryptedKeyField, encrypted_encoded_key);

json_writer.EndObject();

return std::string(json_writer.GetString());
}

LocalWrapKmsClient::LocalKeyWrap LocalWrapKmsClient::LocalKeyWrap::Parse(
Expand Down
Loading