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 void set(Digest&& digest_)
22 {
23 is_set = true;
24 digest = std::move(digest_);
25 }
26
28 {
29 is_set = true;
30 digest.set(r);
31 }
32
33 [[nodiscard]] bool empty() const
34 {
35 return !is_set;
36 }
37
38 [[nodiscard]] 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(
60 [[maybe_unused]] const ClaimsDigest* claims_digest_type)
61 {
62 return ds::json::schema_name<ClaimsDigest::Digest>();
63 }
64
65 inline void fill_json_schema(
66 nlohmann::json& schema,
67 [[maybe_unused]] const ClaimsDigest* claims_digest_type)
68 {
69 ds::json::fill_schema<ClaimsDigest::Digest>(schema);
70 }
71
72 static ClaimsDigest empty_claims()
73 {
74 ClaimsDigest cd;
76 return cd;
77 }
78}
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
std::array< uint8_t, SIZE > Representation
Definition sha256_hash.h:19
void set(const Representation &r)
Definition sha256_hash.h:24
Definition app_interface.h:14
std::string schema_name(const ClaimsDigest *claims_digest_type)
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
void fill_json_schema(nlohmann::json &schema, const ClaimsDigest *claims_digest_type)
Definition claims_digest.h:65