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
25#include <xrpl/basics/Buffer.h>
26#include <xrpl/basics/Slice.h>
27
28#include <cstdint>
29#include <set>
30
31namespace ripple {
32namespace cryptoconditions {
33
34enum class Type : std::uint8_t {
36 prefixSha256 = 1,
38 rsaSha256 = 3,
40};
41
43{
44public:
52 static constexpr std::size_t maxSerializedCondition = 128;
53
66
67public:
69
76
79
82
84 : type(t), fingerprint(fp), cost(c)
85 {
86 }
87
89 : type(t), fingerprint(std::move(fp)), cost(c)
90 {
91 }
92
93 ~Condition() = default;
94
95 Condition(Condition const&) = default;
96 Condition(Condition&&) = default;
97
98 Condition() = delete;
99};
100
101inline bool
102operator==(Condition const& lhs, Condition const& rhs)
103{
104 return lhs.type == rhs.type && lhs.cost == rhs.cost &&
105 lhs.subtypes == rhs.subtypes && lhs.fingerprint == rhs.fingerprint;
106}
107
108inline bool
109operator!=(Condition const& lhs, Condition const& rhs)
110{
111 return !(lhs == rhs);
112}
113
114} // namespace cryptoconditions
115
116} // namespace ripple
117
118#endif
Like std::vector<char> but better.
Definition Buffer.h:36
An immutable linear range of bytes.
Definition Slice.h:46
Buffer fingerprint
An identifier for this condition.
Definition Condition.h:75
Condition(Type t, std::uint32_t c, Buffer &&fp)
Definition Condition.h:88
std::set< Type > subtypes
For compound conditions, set of conditions includes.
Definition Condition.h:81
Condition(Type t, std::uint32_t c, Slice fp)
Definition Condition.h:83
Condition(Condition &&)=default
static std::unique_ptr< Condition > deserialize(Slice s, std::error_code &ec)
Load a condition from its binary form.
static constexpr std::size_t maxSerializedCondition
The largest binary condition we support.
Definition Condition.h:52
Condition(Condition const &)=default
std::uint32_t cost
The cost associated with this condition.
Definition Condition.h:78
bool operator==(Condition const &lhs, Condition const &rhs)
Definition Condition.h:102
bool operator!=(Condition const &lhs, Condition const &rhs)
Definition Condition.h:109
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
STL namespace.