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{
64  };
65  // clang-format on
66 
67  return format;
68 };
69 
70 uint256
72 {
74 }
75 
76 uint256
78 {
79  return getFieldH256(sfLedgerHash);
80 }
81 
82 uint256
84 {
86 }
87 
90 {
92 }
93 
95 STValidation::getSeenTime() const noexcept
96 {
97  return seenTime_;
98 }
99 
100 bool
101 STValidation::isValid() const noexcept
102 {
103  if (!valid_)
104  {
106 
108  getSignerPublic(),
109  getSigningHash(),
112  }
113 
114  return valid_.value();
115 }
116 
117 bool
118 STValidation::isFull() const noexcept
119 {
120  return (getFlags() & vfFullValidation) != 0;
121 }
122 
123 Blob
125 {
126  return getFieldVL(sfSignature);
127 }
128 
129 Blob
131 {
132  Serializer s;
133  add(s);
134  return s.peekData();
135 }
136 
137 } // namespace ripple
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:83
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:77
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:124
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
Integers of any length that is a multiple of 32-bits.
Definition: base_uint.h:81
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:130
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:118
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:89
ripple::STValidation::seenTime_
NetClock::time_point seenTime_
Definition: STValidation.h:59
ripple::STValidation::isValid
bool isValid() const noexcept
Definition: STValidation.cpp:101
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:95
ripple::STValidation::getSigningHash
uint256 getSigningHash() const
Definition: STValidation.cpp:71
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