CCF
Loading...
Searching...
No Matches
claims_digest.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
6
7namespace ccf
8{
10 {
11 public:
13
14 private:
15 bool is_set = false;
16 Digest digest;
17
18 public:
19 ClaimsDigest() = default;
20
21 inline void set(Digest&& digest_)
22 {
23 is_set = true;
24 digest = std::move(digest_);
25 }
26
27 inline void set(Digest::Representation&& r)
28 {
29 is_set = true;
30 digest.set(std::move(r));
31 }
32
33 inline bool empty() const
34 {
35 return !is_set;
36 }
37
38 const Digest& value() const
39 {
40 return digest;
41 }
42
43 bool operator==(const ClaimsDigest& other) const
44 {
45 return (is_set == other.is_set) && (digest == other.digest);
46 }
47 };
48
49 inline void to_json(nlohmann::json& j, const ClaimsDigest& hash)
50 {
51 j = hash.value();
52 }
53
54 inline void from_json(const nlohmann::json& j, ClaimsDigest& hash)
55 {
56 hash.set(j.get<ClaimsDigest::Digest>());
57 }
58
59 inline std::string schema_name(const ClaimsDigest*)
60 {
61 return ds::json::schema_name<ClaimsDigest::Digest>();
62 }
63
64 inline void fill_json_schema(nlohmann::json& schema, const ClaimsDigest*)
65 {
66 ds::json::fill_schema<ClaimsDigest::Digest>(schema);
67 }
68
69 static ClaimsDigest empty_claims()
70 {
71 ClaimsDigest cd;
73 return cd;
74 }
75}
Definition claims_digest.h:10
ClaimsDigest()=default
void set(Digest &&digest_)
Definition claims_digest.h:21
const Digest & value() const
Definition claims_digest.h:38
bool empty() const
Definition claims_digest.h:33
bool operator==(const ClaimsDigest &other) const
Definition claims_digest.h:43
void set(Digest::Representation &&r)
Definition claims_digest.h:27
Definition sha256_hash.h:16
void set(Representation &&r)
Definition sha256_hash.h:24
std::array< uint8_t, SIZE > Representation
Definition sha256_hash.h:19
Definition app_interface.h:14
void fill_json_schema(nlohmann::json &schema, const ClaimsDigest *)
Definition claims_digest.h:64
std::string schema_name(const ClaimsDigest *)
Definition claims_digest.h:59
void from_json(const nlohmann::json &j, ClaimsDigest &hash)
Definition claims_digest.h:54
void to_json(nlohmann::json &j, const ClaimsDigest &hash)
Definition claims_digest.h:49