MCPcopy Create free account
hub / github.com/AGWA/git-crypt / decrypt_repo_key

Function decrypt_repo_key

commands.cpp:613–649  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

611}
612
613static bool decrypt_repo_key (Key_file& key_file, const char* key_name, uint32_t key_version, const std::vector<std::string>& secret_keys, const std::string& keys_path)
614{
615 std::exception_ptr gpg_error;
616
617 for (std::vector<std::string>::const_iterator seckey(secret_keys.begin()); seckey != secret_keys.end(); ++seckey) {
618 std::ostringstream path_builder;
619 path_builder << keys_path << '/' << (key_name ? key_name : "default") << '/' << key_version << '/' << *seckey << ".gpg";
620 std::string path(path_builder.str());
621 if (access(path.c_str(), F_OK) == 0) {
622 std::stringstream decrypted_contents;
623 try {
624 gpg_decrypt_from_file(path, decrypted_contents);
625 } catch (const Gpg_error&) {
626 gpg_error = std::current_exception();
627 continue;
628 }
629 Key_file this_version_key_file;
630 this_version_key_file.load(decrypted_contents);
631 const Key_file::Entry* this_version_entry = this_version_key_file.get(key_version);
632 if (!this_version_entry) {
633 throw Error("GPG-encrypted keyfile is malformed because it does not contain expected key version");
634 }
635 if (!same_key_name(key_name, this_version_key_file.get_key_name())) {
636 throw Error("GPG-encrypted keyfile is malformed because it does not contain expected key name");
637 }
638 key_file.set_key_name(key_name);
639 key_file.add(*this_version_entry);
640 return true;
641 }
642 }
643
644 if (gpg_error) {
645 std::rethrow_exception(gpg_error);
646 }
647
648 return false;
649}
650
651static bool decrypt_repo_keys (std::vector<Key_file>& key_files, uint32_t key_version, const std::vector<std::string>& secret_keys, const std::string& keys_path)
652{

Callers 1

decrypt_repo_keysFunction · 0.85

Calls 8

gpg_decrypt_from_fileFunction · 0.85
ErrorClass · 0.85
same_key_nameFunction · 0.85
loadMethod · 0.80
get_key_nameMethod · 0.80
set_key_nameMethod · 0.80
getMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected