Aktualizr
C++ SOTA Client
exceptions.h
1 #ifndef UPTANE_EXCEPTIONS_H_
2 #define UPTANE_EXCEPTIONS_H_
3 
4 #include <stdexcept>
5 #include <string>
6 #include <utility>
7 
8 namespace Uptane {
9 
10 class Exception : public std::logic_error {
11  public:
12  Exception(std::string reponame, const std::string& what_arg)
13  : std::logic_error(what_arg.c_str()), reponame_(std::move(reponame)) {}
14  ~Exception() noexcept override = default;
15  virtual std::string getName() const { return reponame_; };
16 
17  protected:
18  std::string reponame_;
19 };
20 
22  public:
23  MetadataFetchFailure(const std::string& reponame, const std::string& role)
24  : Exception(reponame, std::string("Failed to fetch role ") + role + " in " + reponame + " repository.") {}
25  ~MetadataFetchFailure() noexcept override = default;
26 };
27 
28 class SecurityException : public Exception {
29  public:
30  SecurityException(const std::string& reponame, const std::string& what_arg) : Exception(reponame, what_arg) {}
31  ~SecurityException() noexcept override = default;
32 };
33 
35  public:
36  explicit TargetContentMismatch(const std::string& targetname)
37  : Exception(targetname, "Director Target filename matches currently installed version, but content differs.") {}
38  ~TargetContentMismatch() noexcept override = default;
39 };
40 
41 class TargetHashMismatch : public Exception {
42  public:
43  explicit TargetHashMismatch(const std::string& targetname)
44  : Exception(targetname, "The target's calculated hash did not match the hash in the metadata.") {}
45  ~TargetHashMismatch() noexcept override = default;
46 };
47 
48 class OversizedTarget : public Exception {
49  public:
50  explicit OversizedTarget(const std::string& reponame)
51  : Exception(reponame, "The target's size was greater than the size in the metadata.") {}
52  ~OversizedTarget() noexcept override = default;
53 };
54 
55 class IllegalThreshold : public Exception {
56  public:
57  IllegalThreshold(const std::string& reponame, const std::string& what_arg) : Exception(reponame, what_arg) {}
58  ~IllegalThreshold() noexcept override = default;
59 };
60 
61 class MissingRepo : public Exception {
62  public:
63  explicit MissingRepo(const std::string& reponame) : Exception(reponame, "The " + reponame + " repo is missing.") {}
64  ~MissingRepo() noexcept override = default;
65 };
66 
67 class UnmetThreshold : public Exception {
68  public:
69  UnmetThreshold(const std::string& reponame, const std::string& role)
70  : Exception(reponame, "The " + role + " metadata had an unmet threshold.") {}
71  ~UnmetThreshold() noexcept override = default;
72 };
73 
74 class ExpiredMetadata : public Exception {
75  public:
76  ExpiredMetadata(const std::string& reponame, const std::string& role)
77  : Exception(reponame, "The " + role + " metadata was expired.") {}
78  ~ExpiredMetadata() noexcept override = default;
79 };
80 
81 class InvalidMetadata : public Exception {
82  public:
83  InvalidMetadata(const std::string& reponame, const std::string& role, const std::string& reason)
84  : Exception(reponame, "The " + role + " metadata failed to parse: " + reason) {}
85  ~InvalidMetadata() noexcept override = default;
86 };
87 
88 class TargetMismatch : public Exception {
89  public:
90  explicit TargetMismatch(const std::string& targetname)
91  : Exception(targetname, "The target metadata in the Image and Director repos do not match.") {}
92  ~TargetMismatch() noexcept override = default;
93 };
94 
96  public:
97  NonUniqueSignatures(const std::string& reponame, const std::string& role)
98  : Exception(reponame, "The role " + role + " had non-unique signatures.") {}
99  ~NonUniqueSignatures() noexcept override = default;
100 };
101 
102 class BadKeyId : public Exception {
103  public:
104  BadKeyId(const std::string& reponame) : Exception(reponame, "A key has an incorrect associated key ID") {}
105  ~BadKeyId() noexcept override = default;
106 };
107 
108 class BadEcuId : public Exception {
109  public:
110  BadEcuId(const std::string& reponame)
111  : Exception(reponame, "The target had an ECU ID that did not match the client's configured ECU ID.") {}
112  ~BadEcuId() noexcept override = default;
113 };
114 
115 class BadHardwareId : public Exception {
116  public:
117  BadHardwareId(const std::string& reponame)
118  : Exception(reponame, "The target had a hardware ID that did not match the client's configured hardware ID.") {}
119  ~BadHardwareId() noexcept override = default;
120 };
121 
122 class RootRotationError : public Exception {
123  public:
124  RootRotationError(const std::string& reponame)
125  : Exception(reponame, "Version in Root metadata does not match its expected value.") {}
126  ~RootRotationError() noexcept override = default;
127 };
128 
129 class VersionMismatch : public Exception {
130  public:
131  VersionMismatch(const std::string& reponame, const std::string& role)
132  : Exception(reponame, "The version of role " + role + " does not match the entry in Snapshot metadata.") {}
133  ~VersionMismatch() noexcept override = default;
134 };
135 
137  public:
138  explicit DelegationHashMismatch(const std::string& delegation_name)
139  : Exception("image", "The calculated hash of delegated role " + delegation_name +
140  " did not match the hash in the metadata.") {}
141  ~DelegationHashMismatch() noexcept override = default;
142 };
143 
144 class DelegationMissing : public Exception {
145  public:
146  explicit DelegationMissing(const std::string& delegation_name)
147  : Exception("image", "The delegated role " + delegation_name + " is missing.") {}
148  ~DelegationMissing() noexcept override = default;
149 };
150 
151 class InvalidTarget : public Exception {
152  public:
153  InvalidTarget(const std::string& reponame)
154  : Exception(reponame, "The target had a non-OSTree package that can not be installed on an OSTree system.") {}
155  ~InvalidTarget() noexcept override = default;
156 };
157 
158 } // namespace Uptane
159 
160 #endif
Uptane::UnmetThreshold
Definition: exceptions.h:67
Uptane::BadHardwareId
Definition: exceptions.h:115
Uptane::InvalidTarget
Definition: exceptions.h:151
Uptane::InvalidMetadata
Definition: exceptions.h:81
Uptane::DelegationMissing
Definition: exceptions.h:144
Uptane::BadEcuId
Definition: exceptions.h:108
Uptane::NonUniqueSignatures
Definition: exceptions.h:95
Uptane::MissingRepo
Definition: exceptions.h:61
Uptane::ExpiredMetadata
Definition: exceptions.h:74
Uptane::TargetMismatch
Definition: exceptions.h:88
Uptane::OversizedTarget
Definition: exceptions.h:48
Uptane::DelegationHashMismatch
Definition: exceptions.h:136
Uptane::MetadataFetchFailure
Definition: exceptions.h:21
Uptane::Exception
Definition: exceptions.h:10
Uptane::IllegalThreshold
Definition: exceptions.h:55
Uptane::TargetHashMismatch
Definition: exceptions.h:41
Uptane::BadKeyId
Definition: exceptions.h:102
Uptane
Base data types that are used in The Update Framework (TUF), part of Uptane.
Definition: packagemanagerinterface.h:18
Uptane::RootRotationError
Definition: exceptions.h:122
Uptane::TargetContentMismatch
Definition: exceptions.h:34
Uptane::SecurityException
Definition: exceptions.h:28
Uptane::VersionMismatch
Definition: exceptions.h:129