rippled
Loading...
Searching...
No Matches
Condition.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2016 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_CONDITIONS_CONDITION_H
21#define RIPPLE_CONDITIONS_CONDITION_H
22
23#include <xrpld/conditions/detail/utils.h>
24#include <xrpl/basics/Buffer.h>
25#include <xrpl/basics/Slice.h>
26#include <array>
27#include <cstdint>
28#include <set>
29#include <string>
30#include <system_error>
31#include <vector>
32
33namespace ripple {
34namespace cryptoconditions {
35
36enum class Type : std::uint8_t {
38 prefixSha256 = 1,
40 rsaSha256 = 3,
42};
43
45{
46public:
54 static constexpr std::size_t maxSerializedCondition = 128;
55
68
69public:
71
78
81
84
86 : type(t), fingerprint(fp), cost(c)
87 {
88 }
89
91 : type(t), fingerprint(std::move(fp)), cost(c)
92 {
93 }
94
95 ~Condition() = default;
96
97 Condition(Condition const&) = default;
98 Condition(Condition&&) = default;
99
100 Condition() = delete;
101};
102
103inline bool
104operator==(Condition const& lhs, Condition const& rhs)
105{
106 return lhs.type == rhs.type && lhs.cost == rhs.cost &&
107 lhs.subtypes == rhs.subtypes && lhs.fingerprint == rhs.fingerprint;
108}
109
110inline bool
111operator!=(Condition const& lhs, Condition const& rhs)
112{
113 return !(lhs == rhs);
114}
115
116} // namespace cryptoconditions
117
118} // namespace ripple
119
120#endif
Like std::vector<char> but better.
Definition: Buffer.h:36
An immutable linear range of bytes.
Definition: Slice.h:45
Buffer fingerprint
An identifier for this condition.
Definition: Condition.h:77
Condition(Type t, std::uint32_t c, Buffer &&fp)
Definition: Condition.h:90
std::set< Type > subtypes
For compound conditions, set of conditions includes.
Definition: Condition.h:83
Condition(Type t, std::uint32_t c, Slice fp)
Definition: Condition.h:85
Condition(Condition &&)=default
static std::unique_ptr< Condition > deserialize(Slice s, std::error_code &ec)
Load a condition from its binary form.
Definition: Condition.cpp:152
static constexpr std::size_t maxSerializedCondition
The largest binary condition we support.
Definition: Condition.h:54
Condition(Condition const &)=default
std::uint32_t cost
The cost associated with this condition.
Definition: Condition.h:80
bool operator==(Condition const &lhs, Condition const &rhs)
Definition: Condition.h:104
bool operator!=(Condition const &lhs, Condition const &rhs)
Definition: Condition.h:111
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
STL namespace.