Aktualizr
C++ SOTA Client
signature.h
1 #ifndef OPCUABRIDGE_SIGNATURE_H_
2 #define OPCUABRIDGE_SIGNATURE_H_
3 
4 #include "hash.h"
5 
6 #include "common.h"
7 
8 namespace opcuabridge {
9 class Signature {
10  public:
11  Signature() = default;
12  virtual ~Signature() = default;
13 
14  const std::string& getKeyid() const { return keyid_; }
15  void setKeyid(const std::string& keyid) { keyid_ = keyid; }
16  const SignatureMethod& getMethod() const { return method_; }
17  void setMethod(const SignatureMethod& method) { method_ = method; }
18  const Hash& getHash() const { return hash_; }
19  void setHash(const Hash& hash) { hash_ = hash; }
20  const std::string& getValue() const { return value_; }
21  void setValue(const std::string& value) { value_ = value; }
22 
23  Json::Value wrapMessage() const {
24  Json::Value v;
25  v["keyid"] = getKeyid();
26  v["method"] = static_cast<Json::Value::Int>(getMethod());
27  v["hash"] = getHash().wrapMessage();
28  v["sig"] = getValue();
29  return v;
30  }
31  void unwrapMessage(Json::Value v) {
32  setKeyid(v["keyid"].asString());
33  setMethod(static_cast<SignatureMethod>(v["method"].asInt()));
34  Hash h;
35  h.unwrapMessage(v["hash"]);
36  setHash(h);
37  setValue(v["sig"].asString());
38  }
39 
40  protected:
41  std::string keyid_;
42  SignatureMethod method_{};
43  Hash hash_;
44  std::string value_;
45 
46  private:
47 #ifdef OPCUABRIDGE_ENABLE_SERIALIZATION
48  SERIALIZE_FUNCTION_FRIEND_DECLARATION
49 
50  DEFINE_SERIALIZE_METHOD() {
51  SERIALIZE_FIELD(ar, "keyid_", keyid_);
52  SERIALIZE_FIELD(ar, "method_", method_);
53  SERIALIZE_FIELD(ar, "hash_", hash_);
54  SERIALIZE_FIELD(ar, "value_", value_);
55  }
56 #endif // OPCUABRIDGE_ENABLE_SERIALIZATION
57 };
58 } // namespace opcuabridge
59 
60 #endif // OPCUABRIDGE_SIGNATURE_H_