MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / getCurrentKeyAndNonce

Method getCurrentKeyAndNonce

src/Compression/CompressionCodecEncrypted.cpp:432–456  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

430}
431
432void CompressionCodecEncrypted::Configuration::getCurrentKeyAndNonce(EncryptionMethod method, UInt64 & current_key_id, String &current_key, String & nonce) const
433{
434 /// It parameters were not set, throw exception
435 if (!params.get())
436 throw Exception(ErrorCodes::BAD_ARGUMENTS, "Empty params in CompressionCodecEncrypted configuration");
437
438 /// Save parameters in variable, because they can always change.
439 /// As this function not atomic, we should be certain that we get information from one particular version for correct work.
440 const auto current_params = params.get();
441 current_key_id = current_params->current_key_id[method];
442
443 /// As parameters can be created empty, we need to check that this key is available.
444 if (current_params->keys_storage[method].contains(current_key_id))
445 current_key = current_params->keys_storage[method].at(current_key_id);
446 else
447 throw Exception(ErrorCodes::BAD_ARGUMENTS, "There is no current_key {} in config. Please, put it in config and reload.", current_key_id);
448
449 /// If there is no nonce in config, we need to generate particular one,
450 /// because all encryptions should have nonce and random nonce generation will lead to cases
451 /// when nonce after config reload (nonce is not defined in config) will differ from previously generated one.
452 /// This will lead to data loss.
453 nonce = current_params->nonce[method];
454 if (nonce.empty())
455 nonce = empty_nonce;
456}
457
458String CompressionCodecEncrypted::Configuration::getKey(EncryptionMethod method, const UInt64 & key_id) const
459{

Callers 1

doCompressDataMethod · 0.80

Calls 5

ExceptionClass · 0.70
getMethod · 0.45
containsMethod · 0.45
atMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected