rippled
STValidation.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 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 #include <ripple/basics/Log.h>
21 #include <ripple/basics/contract.h>
22 #include <ripple/json/to_string.h>
23 #include <ripple/protocol/HashPrefix.h>
24 #include <ripple/protocol/STValidation.h>
25 
26 namespace ripple {
27 
28 STBase*
29 STValidation::copy(std::size_t n, void* buf) const
30 {
31  return emplace(n, buf, *this);
32 }
33 
34 STBase*
36 {
37  return emplace(n, buf, std::move(*this));
38 }
39 
40 SOTemplate const&
42 {
43  // We can't have this be a magic static at namespace scope because
44  // it relies on the SField's below being initialized, and we can't
45  // guarantee the initialization order.
46  // clang-format off
47  static SOTemplate const format{
61  // featureHardenedValidations
65  // featureXRPFees
69  };
70  // clang-format on
71 
72  return format;
73 };
74 
75 uint256
77 {
79 }
80 
81 uint256
83 {
84  return getFieldH256(sfLedgerHash);
85 }
86 
87 uint256
89 {
91 }
92 
95 {
97 }
98 
101 {
102  return seenTime_;
103 }
104 
105 bool
106 STValidation::isValid() const noexcept
107 {
108  if (!valid_)
109  {
111 
113  getSignerPublic(),
114  getSigningHash(),
117  }
118 
119  return valid_.value();
120 }
121 
122 bool
123 STValidation::isFull() const noexcept
124 {
125  return (getFlags() & vfFullValidation) != 0;
126 }
127 
128 Blob
130 {
131  return getFieldVL(sfSignature);
132 }
133 
134 Blob
136 {
137  Serializer s;
138  add(s);
139  return s.peekData();
140 }
141 
142 } // namespace ripple
ripple::sfBaseFeeDrops
const SF_AMOUNT sfBaseFeeDrops
ripple::makeSlice
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
Definition: Slice.h:241
ripple::sfReserveBase
const SF_UINT32 sfReserveBase
ripple::STValidation::getConsensusHash
uint256 getConsensusHash() const
Definition: STValidation.cpp:88
ripple::sfLedgerSequence
const SF_UINT32 sfLedgerSequence
std::vector< unsigned char >
ripple::sfSigningPubKey
const SF_VL sfSigningPubKey
ripple::STValidation::getLedgerHash
uint256 getLedgerHash() const
Definition: STValidation.cpp:82
std::chrono::duration
ripple::soeREQUIRED
@ soeREQUIRED
Definition: SOTemplate.h:35
ripple::STValidation::copy
STBase * copy(std::size_t n, void *buf) const override
Definition: STValidation.cpp:29
ripple::sfCloseTime
const SF_UINT32 sfCloseTime
ripple::STObject::getFieldVL
Blob getFieldVL(SField const &field) const
Definition: STObject.cpp:595
ripple::STValidation::validationFormat
static SOTemplate const & validationFormat()
Definition: STValidation.cpp:41
ripple::STValidation::getSignature
Blob getSignature() const
Definition: STValidation.cpp:129
ripple::vfFullyCanonicalSig
constexpr std::uint32_t vfFullyCanonicalSig
Definition: STValidation.h:42
ripple::publicKeyType
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
Definition: PublicKey.cpp:207
ripple::sfValidatedHash
const SF_UINT256 sfValidatedHash
ripple::base_uint< 256 >
ripple::SOTemplate
Defines the fields and their attributes within a STObject.
Definition: SOTemplate.h:82
ripple::STValidation::getSignerPublic
PublicKey const & getSignerPublic() const noexcept
Definition: STValidation.h:233
ripple::sfServerVersion
const SF_UINT64 sfServerVersion
ripple::sfLoadFee
const SF_UINT32 sfLoadFee
ripple::STBase::emplace
static STBase * emplace(std::size_t n, void *buf, T &&val)
Definition: STBase.h:165
ripple::STValidation::valid_
std::optional< bool > valid_
Definition: STValidation.h:50
ripple::sfReserveIncrement
const SF_UINT32 sfReserveIncrement
ripple::soeOPTIONAL
@ soeOPTIONAL
Definition: SOTemplate.h:36
ripple::STValidation::getSerialized
Blob getSerialized() const
Definition: STValidation.cpp:135
ripple::STValidation::move
STBase * move(std::size_t n, void *buf) override
Definition: STValidation.cpp:35
ripple::sfLedgerHash
const SF_UINT256 sfLedgerHash
ripple::sfCookie
const SF_UINT64 sfCookie
ripple::STValidation::isFull
bool isFull() const noexcept
Definition: STValidation.cpp:123
std::chrono::time_point
ripple::STObject::getFlags
std::uint32_t getFlags() const
Definition: STObject.cpp:481
ripple::HashPrefix::validation
@ validation
validation for signing
ripple::STValidation::getSignTime
NetClock::time_point getSignTime() const
Definition: STValidation.cpp:94
ripple::sfReserveIncrementDrops
const SF_AMOUNT sfReserveIncrementDrops
ripple::sfReserveBaseDrops
const SF_AMOUNT sfReserveBaseDrops
ripple::STValidation::seenTime_
NetClock::time_point seenTime_
Definition: STValidation.h:59
ripple::STValidation::isValid
bool isValid() const noexcept
Definition: STValidation.cpp:106
ripple::KeyType::secp256k1
@ secp256k1
ripple::Serializer
Definition: Serializer.h:39
std::optional::value
T value(T... args)
ripple::sfBaseFee
const SF_UINT64 sfBaseFee
ripple::STObject::add
void add(Serializer &s) const override
Definition: STObject.cpp:85
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::STObject::getSigningHash
uint256 getSigningHash(HashPrefix prefix) const
Definition: STObject.cpp:348
ripple::STBase
A type which can be exported to a well known binary format.
Definition: STBase.h:66
ripple::sfFlags
const SF_UINT32 sfFlags
ripple::verifyDigest
bool verifyDigest(PublicKey const &publicKey, uint256 const &digest, Slice const &sig, bool mustBeFullyCanonical) noexcept
Verify a secp256k1 signature on the digest of a message.
Definition: PublicKey.cpp:222
ripple::Serializer::peekData
Blob const & peekData() const
Definition: Serializer.h:168
ripple::sfConsensusHash
const SF_UINT256 sfConsensusHash
ripple::sfSignature
const SF_VL sfSignature
ripple::STValidation::getSeenTime
NetClock::time_point getSeenTime() const noexcept
Definition: STValidation.cpp:100
ripple::STValidation::getSigningHash
uint256 getSigningHash() const
Definition: STValidation.cpp:76
std::size_t
ripple::vfFullValidation
constexpr std::uint32_t vfFullValidation
Definition: STValidation.h:39
ripple::STObject::getFieldU32
std::uint32_t getFieldU32(SField const &field) const
Definition: STObject.cpp:559
ripple::sfSigningTime
const SF_UINT32 sfSigningTime
ripple::soeDEFAULT
@ soeDEFAULT
Definition: SOTemplate.h:37
ripple::sfAmendments
const SF_VECTOR256 sfAmendments
ripple::STObject::getFieldH256
uint256 getFieldH256(SField const &field) const
Definition: STObject.cpp:583