Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
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 
34 class TargetHashMismatch : public Exception {
35  public:
36  explicit TargetHashMismatch(const std::string& targetname)
37  : Exception(targetname, "The target's calculated hash did not match the hash in the metadata.") {}
38  ~TargetHashMismatch() noexcept override = default;
39 };
40 
41 class OversizedTarget : public Exception {
42  public:
43  explicit OversizedTarget(const std::string& reponame)
44  : Exception(reponame, "The target's size was greater than the size in the metadata.") {}
45  ~OversizedTarget() noexcept override = default;
46 };
47 
48 class IllegalThreshold : public Exception {
49  public:
50  IllegalThreshold(const std::string& reponame, const std::string& what_arg) : Exception(reponame, what_arg) {}
51  ~IllegalThreshold() noexcept override = default;
52 };
53 
54 class MissingRepo : public Exception {
55  public:
56  explicit MissingRepo(const std::string& reponame) : Exception(reponame, "The " + reponame + " repo is missing.") {}
57  ~MissingRepo() noexcept override = default;
58 };
59 
60 class UnmetThreshold : public Exception {
61  public:
62  UnmetThreshold(const std::string& reponame, const std::string& role)
63  : Exception(reponame, "The " + role + " metadata had an unmet threshold.") {}
64  ~UnmetThreshold() noexcept override = default;
65 };
66 
67 class ExpiredMetadata : public Exception {
68  public:
69  ExpiredMetadata(const std::string& reponame, const std::string& role)
70  : Exception(reponame, "The " + role + " metadata was expired.") {}
71  ~ExpiredMetadata() noexcept override = default;
72 };
73 
74 class InvalidMetadata : public Exception {
75  public:
76  InvalidMetadata(const std::string& reponame, const std::string& role, const std::string& reason)
77  : Exception(reponame, "The " + role + " metadata failed to parse: " + reason) {}
78  ~InvalidMetadata() noexcept override = default;
79 };
80 
81 class TargetMismatch : public Exception {
82  public:
83  explicit TargetMismatch(const std::string& targetname)
84  : Exception(targetname, "The target metadata in the Image and Director repos do not match.") {}
85  ~TargetMismatch() noexcept override = default;
86 };
87 
89  public:
90  NonUniqueSignatures(const std::string& reponame, const std::string& role)
91  : Exception(reponame, "The role " + role + " had non-unique signatures.") {}
92  ~NonUniqueSignatures() noexcept override = default;
93 };
94 
95 class BadKeyId : public Exception {
96  public:
97  BadKeyId(const std::string& reponame) : Exception(reponame, "A key has an incorrect associated key ID") {}
98  ~BadKeyId() noexcept override = default;
99 };
100 
101 class BadEcuId : public Exception {
102  public:
103  BadEcuId(const std::string& reponame)
104  : Exception(reponame, "The target had an ECU ID that did not match the client's configured ECU ID.") {}
105  ~BadEcuId() noexcept override = default;
106 };
107 
108 class BadHardwareId : public Exception {
109  public:
110  BadHardwareId(const std::string& reponame)
111  : Exception(reponame, "The target had a hardware ID that did not match the client's configured hardware ID.") {}
112  ~BadHardwareId() noexcept override = default;
113 };
114 
115 class RootRotationError : public Exception {
116  public:
117  RootRotationError(const std::string& reponame)
118  : Exception(reponame, "Version in Root metadata does not match its expected value.") {}
119  ~RootRotationError() noexcept override = default;
120 };
121 
122 class VersionMismatch : public Exception {
123  public:
124  VersionMismatch(const std::string& reponame, const std::string& role)
125  : Exception(reponame, "The version of role " + role + " does not match the entry in Snapshot metadata.") {}
126  ~VersionMismatch() noexcept override = default;
127 };
128 
130  public:
131  explicit DelegationHashMismatch(const std::string& delegation_name)
132  : Exception("image", "The calculated hash of delegated role " + delegation_name +
133  " did not match the hash in the metadata.") {}
134  ~DelegationHashMismatch() noexcept override = default;
135 };
136 
137 class DelegationMissing : public Exception {
138  public:
139  explicit DelegationMissing(const std::string& delegation_name)
140  : Exception("image", "The delegated role " + delegation_name + " is missing.") {}
141  ~DelegationMissing() noexcept override = default;
142 };
143 
144 class InvalidTarget : public Exception {
145  public:
146  InvalidTarget(const std::string& reponame)
147  : Exception(reponame, "The target had a non-OSTree package that can not be installed on an OSTree system.") {}
148  ~InvalidTarget() noexcept override = default;
149 };
150 
151 } // namespace Uptane
152 
153 #endif
Uptane::UnmetThreshold
Definition: exceptions.h:60
Uptane::BadHardwareId
Definition: exceptions.h:108
Uptane::InvalidTarget
Definition: exceptions.h:144
Uptane::InvalidMetadata
Definition: exceptions.h:74
Uptane::DelegationMissing
Definition: exceptions.h:137
Uptane::BadEcuId
Definition: exceptions.h:101
Uptane::NonUniqueSignatures
Definition: exceptions.h:88
Uptane::MissingRepo
Definition: exceptions.h:54
Uptane::ExpiredMetadata
Definition: exceptions.h:67
Uptane::TargetMismatch
Definition: exceptions.h:81
Uptane::OversizedTarget
Definition: exceptions.h:41
Uptane::DelegationHashMismatch
Definition: exceptions.h:129
Uptane::MetadataFetchFailure
Definition: exceptions.h:21
Uptane::Exception
Definition: exceptions.h:10
Uptane::IllegalThreshold
Definition: exceptions.h:48
Uptane::TargetHashMismatch
Definition: exceptions.h:34
Uptane::BadKeyId
Definition: exceptions.h:95
Uptane
Base data types that are used in The Update Framework (TUF), part of Uptane.
Definition: ipuptanesecondary.cc:11
Uptane::RootRotationError
Definition: exceptions.h:115
Uptane::SecurityException
Definition: exceptions.h:28
Uptane::VersionMismatch
Definition: exceptions.h:122