| 71 | } |
| 72 | |
| 73 | SecureString FileKeyUnwrapper::GetKey(const std::string& key_metadata_bytes) { |
| 74 | // key_metadata is expected to be in UTF8 encoding |
| 75 | ::arrow::util::InitializeUTF8(); |
| 76 | if (!::arrow::util::ValidateUTF8( |
| 77 | reinterpret_cast<const uint8_t*>(key_metadata_bytes.data()), |
| 78 | key_metadata_bytes.size())) { |
| 79 | throw ParquetException("key metadata should be in UTF8 encoding"); |
| 80 | } |
| 81 | KeyMetadata key_metadata = KeyMetadata::Parse(key_metadata_bytes); |
| 82 | |
| 83 | KeyMaterial key_material; |
| 84 | if (key_metadata.key_material_stored_internally()) { |
| 85 | key_material = key_metadata.key_material(); |
| 86 | } else { |
| 87 | if (key_material_store_ == nullptr) { |
| 88 | key_material_store_ = |
| 89 | FileSystemKeyMaterialStore::Make(file_path_, file_system_, false); |
| 90 | } |
| 91 | // External key material storage: key metadata contains a reference |
| 92 | // to a key in the material store |
| 93 | std::string key_id_in_file = key_metadata.key_reference(); |
| 94 | std::string key_material_string = key_material_store_->GetKeyMaterial(key_id_in_file); |
| 95 | if (key_material_string.empty()) { |
| 96 | throw ParquetException("Could not find key material with ID '" + key_id_in_file + |
| 97 | "' in external key material file"); |
| 98 | } |
| 99 | key_material = KeyMaterial::Parse(key_material_string); |
| 100 | } |
| 101 | |
| 102 | return GetDataEncryptionKey(key_material).data_key(); |
| 103 | } |
| 104 | |
| 105 | KeyWithMasterId FileKeyUnwrapper::GetDataEncryptionKey(const KeyMaterial& key_material) { |
| 106 | auto kms_client = GetKmsClientFromConfigOrKeyMaterial(key_material); |
nothing calls this directly
no test coverage detected