Aktualizr
C++ SOTA Client
uptane_repo.cc
1 
2 #include "uptane_repo.h"
3 
4 UptaneRepo::UptaneRepo(const boost::filesystem::path &path, const std::string &expires,
5  const std::string &correlation_id)
6  : director_repo_(path, expires, correlation_id), image_repo_(path, expires, correlation_id) {}
7 
8 void UptaneRepo::generateRepo(KeyType key_type) {
9  director_repo_.generateRepo(key_type);
10  image_repo_.generateRepo(key_type);
11 }
12 
13 void UptaneRepo::addTarget(const std::string &target_name, const std::string &hardware_id,
14  const std::string &ecu_serial, const std::string &url, const std::string &expires) {
15  auto target = image_repo_.getTarget(target_name);
16  if (target.empty()) {
17  throw std::runtime_error("No such " + target_name + " target in the image repository");
18  }
19  director_repo_.addTarget(target_name, target, hardware_id, ecu_serial, url, expires);
20 }
21 
22 void UptaneRepo::addDelegation(const Uptane::Role &name, const Uptane::Role &parent_role, const std::string &path,
23  bool terminating, KeyType key_type) {
24  image_repo_.addDelegation(name, parent_role, path, terminating, key_type);
25 }
26 
27 void UptaneRepo::revokeDelegation(const Uptane::Role &name) {
28  director_repo_.revokeTargets(image_repo_.getDelegationTargets(name));
29  image_repo_.revokeDelegation(name);
30 }
31 
32 void UptaneRepo::addImage(const boost::filesystem::path &image_path, const boost::filesystem::path &targetname,
33  const std::string &hardware_id, const std::string &url, const Delegation &delegation) {
34  image_repo_.addBinaryImage(image_path, targetname, hardware_id, url, delegation);
35 }
36 void UptaneRepo::addCustomImage(const std::string &name, const Hash &hash, uint64_t length,
37  const std::string &hardware_id, const std::string &url, const Delegation &delegation,
38  const Json::Value &custom) {
39  image_repo_.addCustomImage(name, hash, length, hardware_id, url, delegation, custom);
40 }
41 
42 void UptaneRepo::signTargets() { director_repo_.signTargets(); }
43 
44 void UptaneRepo::emptyTargets() { director_repo_.emptyTargets(); }
45 void UptaneRepo::oldTargets() { director_repo_.oldTargets(); }
46 
47 void UptaneRepo::generateCampaigns() { director_repo_.generateCampaigns(); }
48 
49 void UptaneRepo::refresh(Uptane::RepositoryType repo_type, const Uptane::Role &role) {
50  if (repo_type == Uptane::RepositoryType(Uptane::RepositoryType::Director())) {
51  director_repo_.refresh(role);
52  } else if (repo_type == Uptane::RepositoryType(Uptane::RepositoryType::Image())) {
53  image_repo_.refresh(role);
54  }
55 }
Hash
The Hash class The hash of a file or Uptane metadata.
Definition: types.h:159
Uptane::RepositoryType
Definition: tuf.h:21
Uptane::Role
TUF Roles.
Definition: tuf.h:61
Delegation
Definition: repo.h:19