Skip to content

Commit

Permalink
Add const and reorganize repo_checker
Browse files Browse the repository at this point in the history
Add text in description for verify-package flag
  • Loading branch information
Hind-M committed Feb 21, 2024
1 parent 64e3414 commit 9c69502
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 51 deletions.
12 changes: 6 additions & 6 deletions libmamba/include/mamba/validation/repo_checker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ namespace mamba::validation

void generate_index_checker();

auto cache_path() -> const fs::u8path&;

auto root_version() -> std::size_t;
auto cache_path() const -> const fs::u8path&;
auto root_version() const -> std::size_t;

private:

Expand All @@ -77,9 +76,10 @@ namespace mamba::validation

std::size_t m_root_version;

auto initial_trusted_root() -> fs::u8path;
auto ref_root() -> fs::u8path;
auto cached_root() -> fs::u8path;
auto ref_root() const -> fs::u8path;
auto cached_root() const -> fs::u8path;

auto initial_trusted_root() const -> fs::u8path;

void persist_file(const fs::u8path& file_path);

Expand Down
5 changes: 4 additions & 1 deletion libmamba/src/api/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,10 @@ namespace mamba
.group("Extract, Link & Install")
.set_rc_configurable()
.set_env_var_names()
.description("Run verifications on packages signatures")
.description( //
"Run verifications on packages signatures.\n"
"This is still experimental and may not be stable yet.\n"
)
.long_description(unindent(R"(
Spend extra time validating package contents. It consists of running
cryptographic verifications on channels and packages metadata.)")));
Expand Down
92 changes: 48 additions & 44 deletions libmamba/src/validation/repo_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,6 @@ namespace mamba::validation

auto RepoChecker::operator=(RepoChecker&&) noexcept -> RepoChecker& = default;

auto RepoChecker::cache_path() -> const fs::u8path&
{
return m_cache_path;
}

void RepoChecker::generate_index_checker()
{
if (!p_index_checker)
{
// TUF spec 5.1 - Record fixed update start time
// Expiration computations will be done against
// this reference
// https://theupdateframework.github.io/specification/latest/#fix-time
const TimeRef time_reference;

auto root = get_root_role(time_reference);
p_index_checker = root->build_index_checker(
m_context,
time_reference,
m_base_url,
cache_path()
);

LOG_INFO << "Index checker successfully generated for '" << m_base_url << "'";
}
}

void RepoChecker::verify_index(const nlohmann::json& j) const
{
if (p_index_checker)
Expand Down Expand Up @@ -118,17 +91,48 @@ namespace mamba::validation
}
}

auto RepoChecker::root_version() -> std::size_t
void RepoChecker::generate_index_checker()
{
if (!p_index_checker)
{
// TUF spec 5.1 - Record fixed update start time
// Expiration computations will be done against
// this reference
// https://theupdateframework.github.io/specification/latest/#fix-time
const TimeRef time_reference;

auto root = get_root_role(time_reference);
p_index_checker = root->build_index_checker(
m_context,
time_reference,
m_base_url,
cache_path()
);

LOG_INFO << "Index checker successfully generated for '" << m_base_url << "'";
}
}

auto RepoChecker::cache_path() const -> const fs::u8path&
{
return m_cache_path;
}

auto RepoChecker::root_version() const -> std::size_t
{
return m_root_version;
}

auto RepoChecker::ref_root() -> fs::u8path
////////////////////////////
///// Private methods /////
//////////////////////////

auto RepoChecker::ref_root() const -> fs::u8path
{
return m_ref_path / "root.json";
}

auto RepoChecker::cached_root() -> fs::u8path
auto RepoChecker::cached_root() const -> fs::u8path
{
if (cache_path().empty())
{
Expand All @@ -140,19 +144,7 @@ namespace mamba::validation
}
}

void RepoChecker::persist_file(const fs::u8path& file_path)
{
if (fs::exists(cached_root()))
{
fs::remove(cached_root());
}
if (!cached_root().empty())
{
fs::copy(file_path, cached_root());
}
}

auto RepoChecker::initial_trusted_root() -> fs::u8path
auto RepoChecker::initial_trusted_root() const -> fs::u8path
{
if (fs::exists(cached_root()))
{
Expand All @@ -172,6 +164,18 @@ namespace mamba::validation
}
}

void RepoChecker::persist_file(const fs::u8path& file_path)
{
if (fs::exists(cached_root()))
{
fs::remove(cached_root());
}
if (!cached_root().empty())
{
fs::copy(file_path, cached_root());
}
}

auto RepoChecker::get_root_role(const TimeRef& time_reference) -> std::unique_ptr<RootRole>
{
// TUF spec 5.3 - Update the root role
Expand Down Expand Up @@ -268,5 +272,5 @@ namespace mamba::validation
}

return updated_root;
};
}
}

0 comments on commit 9c69502

Please sign in to comment.