MCPcopy Create free account
hub / github.com/apache/arrow / Parse

Method Parse

cpp/src/parquet/encryption/key_material.cc:61–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59 encoded_wrapped_dek_(encoded_wrapped_dek) {}
60
61KeyMaterial KeyMaterial::Parse(const std::string& key_material_string) {
62 JsonObjectParser json_parser;
63 ::arrow::Status status = json_parser.Parse(key_material_string);
64 if (!status.ok()) {
65 throw ParquetException("Failed to parse key material " + key_material_string);
66 }
67
68 // External key material - extract "key material type", and make sure it is supported
69 std::string key_material_type;
70 PARQUET_ASSIGN_OR_THROW(key_material_type,
71 json_parser.GetString(kKeyMaterialTypeField));
72 if (kKeyMaterialType1 != key_material_type) {
73 throw ParquetException("Wrong key material type: " + key_material_type + " vs " +
74 kKeyMaterialType1);
75 }
76
77 // 2. Check if "key material" belongs to file footer key
78 bool is_footer_key;
79 PARQUET_ASSIGN_OR_THROW(is_footer_key, json_parser.GetBool(kIsFooterKeyField));
80 std::string kms_instance_id;
81 std::string kms_instance_url;
82 if (is_footer_key) {
83 // 3. For footer key, extract KMS Instance ID
84 PARQUET_ASSIGN_OR_THROW(kms_instance_id, json_parser.GetString(kKmsInstanceIdField));
85 // 4. For footer key, extract KMS Instance URL
86 PARQUET_ASSIGN_OR_THROW(kms_instance_url,
87 json_parser.GetString(kKmsInstanceUrlField));
88 }
89 // 5. Extract master key ID
90 std::string master_key_id;
91 PARQUET_ASSIGN_OR_THROW(master_key_id, json_parser.GetString(kMasterKeyIdField));
92 // 6. Extract wrapped DEK
93 std::string encoded_wrapped_dek;
94 PARQUET_ASSIGN_OR_THROW(encoded_wrapped_dek,
95 json_parser.GetString(kWrappedDataEncryptionKeyField));
96 std::string kek_id;
97 std::string encoded_wrapped_kek;
98 // 7. Check if "key material" was generated in double wrapping mode
99 bool is_double_wrapped;
100 PARQUET_ASSIGN_OR_THROW(is_double_wrapped, json_parser.GetBool(kDoubleWrappingField));
101 if (is_double_wrapped) {
102 // 8. In double wrapping mode, extract KEK ID
103 PARQUET_ASSIGN_OR_THROW(kek_id, json_parser.GetString(kKeyEncryptionKeyIdField));
104 // 9. In double wrapping mode, extract wrapped KEK
105 PARQUET_ASSIGN_OR_THROW(encoded_wrapped_kek,
106 json_parser.GetString(kWrappedKeyEncryptionKeyField));
107 }
108
109 return KeyMaterial(is_footer_key, kms_instance_id, kms_instance_url, master_key_id,
110 is_double_wrapped, kek_id, encoded_wrapped_kek, encoded_wrapped_dek);
111}
112
113std::string KeyMaterial::SerializeToJson(
114 bool is_footer_key, const std::string& kms_instance_id,

Callers

nothing calls this directly

Calls 4

ParquetExceptionFunction · 0.85
okMethod · 0.45
GetStringMethod · 0.45
GetBoolMethod · 0.45

Tested by

no test coverage detected