rippled
Fulfillment.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_FULFILLMENT_H
21 #define RIPPLE_CONDITIONS_FULFILLMENT_H
22 
23 #include <ripple/basics/Buffer.h>
24 #include <ripple/basics/Slice.h>
25 #include <ripple/conditions/Condition.h>
26 #include <ripple/conditions/impl/utils.h>
27 
28 namespace ripple {
29 namespace cryptoconditions {
30 
32 {
33 public:
41  static constexpr std::size_t maxSerializedFulfillment = 256;
42 
55 
56 public:
57  virtual ~Fulfillment() = default;
58 
66  virtual Buffer
67  fingerprint() const = 0;
68 
70  virtual Type
71  type() const = 0;
72 
74  virtual bool
75  validate(Slice data) const = 0;
76 
83  virtual std::uint32_t
84  cost() const = 0;
85 
92  virtual Condition
93  condition() const = 0;
94 };
95 
96 inline bool
97 operator==(Fulfillment const& lhs, Fulfillment const& rhs)
98 {
99  // FIXME: for compound conditions, need to also check subtypes
100  return lhs.type() == rhs.type() && lhs.cost() == rhs.cost() &&
101  lhs.fingerprint() == rhs.fingerprint();
102 }
103 
104 inline bool
105 operator!=(Fulfillment const& lhs, Fulfillment const& rhs)
106 {
107  return !(lhs == rhs);
108 }
109 
111 bool
112 match(Fulfillment const& f, Condition const& c);
113 
124 bool
125 validate(Fulfillment const& f, Condition const& c, Slice m);
126 
140 bool
141 validate(Fulfillment const& f, Condition const& c);
142 
143 } // namespace cryptoconditions
144 } // namespace ripple
145 
146 #endif
ripple::cryptoconditions::Fulfillment::deserialize
static std::unique_ptr< Fulfillment > deserialize(Slice s, std::error_code &ec)
Load a fulfillment from its binary form.
Definition: Fulfillment.cpp:57
ripple::cryptoconditions::Fulfillment::maxSerializedFulfillment
static constexpr std::size_t maxSerializedFulfillment
The largest binary fulfillment we support.
Definition: Fulfillment.h:41
ripple::Slice
An immutable linear range of bytes.
Definition: Slice.h:44
ripple::cryptoconditions::Fulfillment::type
virtual Type type() const =0
Returns the type of this condition.
ripple::cryptoconditions::Fulfillment::validate
virtual bool validate(Slice data) const =0
Validates a fulfillment.
ripple::Buffer
Like std::vector<char> but better.
Definition: Buffer.h:35
ripple::cryptoconditions::Fulfillment::cost
virtual std::uint32_t cost() const =0
Calculates the cost associated with this fulfillment.
ripple::cryptoconditions::Condition
Definition: Condition.h:44
std::error_code
STL class.
std::uint32_t
ripple::cryptoconditions::validate
bool validate(Fulfillment const &f, Condition const &c, Slice m)
Verify if the given message satisfies the fulfillment.
Definition: Fulfillment.cpp:45
ripple::cryptoconditions::Fulfillment::condition
virtual Condition condition() const =0
Returns the condition associated with the given fulfillment.
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::Fulfillment::fingerprint
virtual Buffer fingerprint() const =0
Returns the fulfillment's fingerprint:
ripple::cryptoconditions::operator==
bool operator==(Condition const &lhs, Condition const &rhs)
Definition: Condition.h:104
ripple::cryptoconditions::match
bool match(Fulfillment const &f, Condition const &c)
Determine whether the given fulfillment and condition match.
Definition: Fulfillment.cpp:32
std::size_t
ripple::cryptoconditions::Fulfillment
Definition: Fulfillment.h:31
ripple::cryptoconditions::Fulfillment::~Fulfillment
virtual ~Fulfillment()=default
std::unique_ptr
STL class.
ripple::cryptoconditions::operator!=
bool operator!=(Condition const &lhs, Condition const &rhs)
Definition: Condition.h:111