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 #include <boost/optional.hpp>
28 
29 namespace ripple {
30 namespace cryptoconditions {
31 
33 {
34 public:
42  static constexpr std::size_t maxSerializedFulfillment = 256;
43 
56 
57 public:
58  virtual ~Fulfillment() = default;
59 
67  virtual Buffer
68  fingerprint() const = 0;
69 
71  virtual Type
72  type() const = 0;
73 
75  virtual bool
76  validate(Slice data) const = 0;
77 
84  virtual std::uint32_t
85  cost() const = 0;
86 
93  virtual Condition
94  condition() const = 0;
95 };
96 
97 inline bool
98 operator==(Fulfillment const& lhs, Fulfillment const& rhs)
99 {
100  // FIXME: for compound conditions, need to also check subtypes
101  return lhs.type() == rhs.type() && lhs.cost() == rhs.cost() &&
102  lhs.fingerprint() == rhs.fingerprint();
103 }
104 
105 inline bool
106 operator!=(Fulfillment const& lhs, Fulfillment const& rhs)
107 {
108  return !(lhs == rhs);
109 }
110 
112 bool
113 match(Fulfillment const& f, Condition const& c);
114 
125 bool
126 validate(Fulfillment const& f, Condition const& c, Slice m);
127 
141 bool
142 validate(Fulfillment const& f, Condition const& c);
143 
144 } // namespace cryptoconditions
145 } // namespace ripple
146 
147 #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:59
ripple::cryptoconditions::Fulfillment::maxSerializedFulfillment
static constexpr std::size_t maxSerializedFulfillment
The largest binary fulfillment we support.
Definition: Fulfillment.h:42
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:47
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:34
std::size_t
ripple::cryptoconditions::Fulfillment
Definition: Fulfillment.h:32
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