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 <array>
5 #include <cstdint>
6 #include <iostream>
7 #include <string>
8 #include <utility>
9 
10 class OSTreeHash {
11  public:
12  /**
13  * Parse an OSTree hash from a string. This will normally be a root commit.
14  * @throws OSTreeCommitParseError on invalid input
15  */
16  static OSTreeHash Parse(const std::string& hash);
17 
18  explicit OSTreeHash(const uint8_t hash[32]); // NOLINT(modernize-avoid-c-arrays)
19  explicit OSTreeHash(const std::array<uint8_t, 32>& hash);
20 
21  std::string string() const;
22 
23  bool operator<(const OSTreeHash& other) const;
24  friend std::ostream& operator<<(std::ostream& os, const OSTreeHash& obj);
25 
26  private:
27  std::array<uint8_t, 32> hash_{};
28 };
29 
30 class OSTreeCommitParseError : std::exception {
31  public:
32  explicit OSTreeCommitParseError(std::string bad_hash) : bad_hash_(std::move(bad_hash)) {}
33 
34  const char* what() const noexcept override { return "Could not parse OSTree commit"; }
35 
36  std::string bad_hash() const { return bad_hash_; }
37 
38  private:
39  std::string bad_hash_;
40 };
41 
42 #endif // SOTA_CLIENT_TOOLS_OSTREE_HASH_H_
OSTreeHash
Definition: ostree_hash.h:10
OSTreeCommitParseError
Definition: ostree_hash.h:30
OSTreeHash::Parse
static OSTreeHash Parse(const std::string &hash)
Parse an OSTree hash from a string.
Definition: ostree_hash.cc:7