rippled
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 <ripple/basics/Buffer.h>
24 #include <ripple/basics/Slice.h>
25 #include <ripple/conditions/impl/utils.h>
26 #include <array>
27 #include <cstdint>
28 #include <set>
29 #include <string>
30 #include <system_error>
31 #include <vector>
32 
33 namespace ripple {
34 namespace cryptoconditions {
35 
36 enum class Type : std::uint8_t {
37  preimageSha256 = 0,
38  prefixSha256 = 1,
39  thresholdSha256 = 2,
40  rsaSha256 = 3,
41  ed25519Sha256 = 4
42 };
43 
44 class Condition
45 {
46 public:
54  static constexpr std::size_t maxSerializedCondition = 128;
55 
68 
69 public:
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 
103 inline bool
104 operator==(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 
110 inline bool
111 operator!=(Condition const& lhs, Condition const& rhs)
112 {
113  return !(lhs == rhs);
114 }
115 
116 } // namespace cryptoconditions
117 
118 } // namespace ripple
119 
120 #endif
ripple::cryptoconditions::Type::preimageSha256
@ preimageSha256
system_error
ripple::Slice
An immutable linear range of bytes.
Definition: Slice.h:44
ripple::cryptoconditions::Condition::~Condition
~Condition()=default
vector
ripple::cryptoconditions::Condition::subtypes
std::set< Type > subtypes
For compound conditions, set of conditions includes.
Definition: Condition.h:83
ripple::Buffer
Like std::vector<char> but better.
Definition: Buffer.h:35
ripple::cryptoconditions::Condition
Definition: Condition.h:44
std::error_code
STL class.
ripple::cryptoconditions::Condition::cost
std::uint32_t cost
The cost associated with this condition.
Definition: Condition.h:80
ripple::cryptoconditions::Type::ed25519Sha256
@ ed25519Sha256
ripple::cryptoconditions::Condition::type
Type type
Definition: Condition.h:70
ripple::cryptoconditions::Type::thresholdSha256
@ thresholdSha256
ripple::cryptoconditions::Condition::Condition
Condition()=delete
ripple::cryptoconditions::Condition::maxSerializedCondition
static constexpr std::size_t maxSerializedCondition
The largest binary condition we support.
Definition: Condition.h:54
array
cstdint
std::uint8_t
ripple::cryptoconditions::Type
Type
Definition: Condition.h:36
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::cryptoconditions::Type::prefixSha256
@ prefixSha256
ripple::cryptoconditions::operator==
bool operator==(Condition const &lhs, Condition const &rhs)
Definition: Condition.h:104
std
STL namespace.
ripple::cryptoconditions::Type::rsaSha256
@ rsaSha256
std::size_t
ripple::cryptoconditions::Condition::fingerprint
Buffer fingerprint
An identifier for this condition.
Definition: Condition.h:77
ripple::cryptoconditions::Condition::Condition
Condition(Type t, std::uint32_t c, Buffer &&fp)
Definition: Condition.h:90
ripple::cryptoconditions::Condition::Condition
Condition(Type t, std::uint32_t c, Slice fp)
Definition: Condition.h:85
std::unique_ptr
STL class.
set
ripple::cryptoconditions::Condition::deserialize
static std::unique_ptr< Condition > deserialize(Slice s, std::error_code &ec)
Load a condition from its binary form.
Definition: Condition.cpp:152
ripple::cryptoconditions::operator!=
bool operator!=(Condition const &lhs, Condition const &rhs)
Definition: Condition.h:111
string