Aktualizr
C++ SOTA Client
fetcher.h
1 #ifndef UPTANE_FETCHER_H_
2 #define UPTANE_FETCHER_H_
3 
4 #include "config/config.h"
5 #include "http/httpinterface.h"
6 #include "storage/invstorage.h"
7 #include "utilities/events.h"
8 
9 namespace Uptane {
10 
11 constexpr int64_t kMaxRootSize = 64 * 1024;
12 constexpr int64_t kMaxDirectorTargetsSize = 64 * 1024;
13 constexpr int64_t kMaxTimestampSize = 64 * 1024;
14 constexpr int64_t kMaxSnapshotSize = 64 * 1024;
15 constexpr int64_t kMaxImagesTargetsSize = 1024 * 1024;
16 
18  DownloadMetaStruct(Target target_in, std::shared_ptr<event::Channel> events_channel_in)
19  : hash_type{target_in.hashes()[0].type()},
20  events_channel{std::move(events_channel_in)},
21  target{std::move(target_in)} {}
22  uint64_t downloaded_length{};
23  StorageTargetWHandle* fhandle{};
24  const Hash::Type hash_type;
25  MultiPartHasher& hasher() {
26  switch (hash_type) {
27  case Hash::Type::kSha256:
28  return sha256_hasher;
29  case Hash::Type::kSha512:
30  return sha512_hasher;
31  default:
32  throw std::runtime_error("Unknown hash algorithm");
33  }
34  }
35  std::shared_ptr<event::Channel> events_channel;
36  Target target;
37 
38  private:
39  MultiPartSHA256Hasher sha256_hasher;
40  MultiPartSHA512Hasher sha512_hasher;
41 };
42 
43 class Fetcher {
44  public:
45  Fetcher(const Config& config_in, std::shared_ptr<INvStorage> storage_in, std::shared_ptr<HttpInterface> http_in,
46  std::shared_ptr<event::Channel> events_channel_in = nullptr)
47  : http(std::move(http_in)),
48  storage(std::move(storage_in)),
49  config(config_in),
50  events_channel(std::move(events_channel_in)) {}
51  bool fetchVerifyTarget(const Target& target);
52  bool fetchRole(std::string* result, int64_t maxsize, RepositoryType repo, Uptane::Role role, Version version);
53  bool fetchLatestRole(std::string* result, int64_t maxsize, RepositoryType repo, Uptane::Role role) {
54  return fetchRole(result, maxsize, repo, role, Version());
55  }
56 
57  private:
58  std::shared_ptr<HttpInterface> http;
59  std::shared_ptr<INvStorage> storage;
60  const Config& config;
61  std::shared_ptr<event::Channel> events_channel;
62 };
63 
64 } // namespace Uptane
65 
66 #endif
Metadata version numbers.
Definition: tuf.h:57
Configuration object for an aktualizr instance running on a primary ECU.
Definition: config.h:100
TUF Roles.
Definition: tuf.h:25
RepositoryType
This must match the repo_type table in sqlstorage.
Definition: tuf.h:18
Base data types that are used in The Update Framework (TUF), part of UPTANE.