| 102 | } |
| 103 | |
| 104 | ColumnPathToEncryptionPropertiesMap CryptoFactory::GetColumnEncryptionProperties( |
| 105 | int dek_length, const std::string& column_keys, FileKeyWrapper* key_wrapper) { |
| 106 | ColumnPathToEncryptionPropertiesMap encrypted_columns; |
| 107 | |
| 108 | std::vector<::std::string_view> key_to_columns = |
| 109 | ::arrow::internal::SplitString(column_keys, ';'); |
| 110 | for (size_t i = 0; i < key_to_columns.size(); ++i) { |
| 111 | std::string cur_key_to_columns = |
| 112 | ::arrow::internal::TrimString(std::string(key_to_columns[i])); |
| 113 | if (cur_key_to_columns.empty()) { |
| 114 | continue; |
| 115 | } |
| 116 | |
| 117 | std::vector<::std::string_view> parts = |
| 118 | ::arrow::internal::SplitString(cur_key_to_columns, ':'); |
| 119 | if (parts.size() != 2) { |
| 120 | std::ostringstream message; |
| 121 | message << "Incorrect key to columns mapping in column keys property" |
| 122 | << ": [" << cur_key_to_columns << "]"; |
| 123 | throw ParquetException(message.str()); |
| 124 | } |
| 125 | |
| 126 | std::string column_key_id = ::arrow::internal::TrimString(std::string(parts[0])); |
| 127 | if (column_key_id.empty()) { |
| 128 | throw ParquetException("Empty key name in column keys property."); |
| 129 | } |
| 130 | |
| 131 | std::string column_names_str = ::arrow::internal::TrimString(std::string(parts[1])); |
| 132 | std::vector<::std::string_view> column_names = |
| 133 | ::arrow::internal::SplitString(column_names_str, ','); |
| 134 | if (0 == column_names.size()) { |
| 135 | throw ParquetException("No columns to encrypt defined for key: " + column_key_id); |
| 136 | } |
| 137 | |
| 138 | for (size_t j = 0; j < column_names.size(); ++j) { |
| 139 | std::string column_name = |
| 140 | ::arrow::internal::TrimString(std::string(column_names[j])); |
| 141 | if (column_name.empty()) { |
| 142 | std::ostringstream message; |
| 143 | message << "Empty column name in column keys property for key: " << column_key_id; |
| 144 | throw ParquetException(message.str()); |
| 145 | } |
| 146 | |
| 147 | if (encrypted_columns.find(column_name) != encrypted_columns.end()) { |
| 148 | throw ParquetException("Multiple keys defined for the same column: " + |
| 149 | column_name); |
| 150 | } |
| 151 | |
| 152 | SecureString column_key(dek_length, '\0'); |
| 153 | RandBytes(column_key.as_span().data(), column_key.size()); |
| 154 | |
| 155 | std::string column_key_key_metadata = |
| 156 | key_wrapper->GetEncryptionKeyMetadata(column_key, column_key_id, false); |
| 157 | |
| 158 | std::shared_ptr<ColumnEncryptionProperties> cmd = |
| 159 | ColumnEncryptionProperties::Builder() |
| 160 | .key(column_key) |
| 161 | ->key_metadata(column_key_key_metadata) |
nothing calls this directly
no test coverage detected