Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
ostree_hash.h
1 #ifndef SOTA_CLIENT_TOOLS_OSTREE_HASH_H_
2 #define SOTA_CLIENT_TOOLS_OSTREE_HASH_H_
3 
4 #include <cstdint>
5 #include <iostream>
6 #include <string>
7 #include <utility>
8 
9 class OSTreeHash {
10  public:
11  /**
12  * Parse an OSTree hash from a string. This will normally be a root commit.
13  * @throws OSTreeCommitParseError on invalid input
14  */
15  static OSTreeHash Parse(const std::string& hash);
16 
17  explicit OSTreeHash(const uint8_t /*hash*/[32]);
18 
19  std::string string() const;
20 
21  bool operator<(const OSTreeHash& other) const;
22  friend std::ostream& operator<<(std::ostream& os, const OSTreeHash& obj);
23 
24  private:
25  uint8_t hash_[32]{};
26 };
27 
28 class OSTreeCommitParseError : std::exception {
29  public:
30  explicit OSTreeCommitParseError(std::string bad_hash) : bad_hash_(std::move(bad_hash)) {}
31 
32  const char* what() const noexcept override { return "Could not parse OSTree commit"; }
33 
34  std::string bad_hash() const { return bad_hash_; }
35 
36  private:
37  std::string bad_hash_;
38 };
39 
40 #endif // SOTA_CLIENT_TOOLS_OSTREE_HASH_H_
OSTreeHash
Definition: ostree_hash.h:9
OSTreeCommitParseError
Definition: ostree_hash.h:28
OSTreeHash::Parse
static OSTreeHash Parse(const std::string &hash)
Parse an OSTree hash from a string.
Definition: ostree_hash.cc:7