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