rippled
Loading...
Searching...
No Matches
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 <xrpl/basics/Blob.h>
21#include <xrpl/basics/Slice.h>
22#include <xrpl/basics/base_uint.h>
23#include <xrpl/basics/chrono.h>
24#include <xrpl/beast/utility/instrumentation.h>
25#include <xrpl/protocol/HashPrefix.h>
26#include <xrpl/protocol/KeyType.h>
27#include <xrpl/protocol/PublicKey.h>
28#include <xrpl/protocol/SField.h>
29#include <xrpl/protocol/SOTemplate.h>
30#include <xrpl/protocol/STBase.h>
31#include <xrpl/protocol/STObject.h>
32#include <xrpl/protocol/STValidation.h>
33#include <xrpl/protocol/Serializer.h>
34
35#include <cstddef>
36#include <utility>
37
38namespace ripple {
39
40STBase*
42{
43 return emplace(n, buf, *this);
44}
45
46STBase*
48{
49 return emplace(n, buf, std::move(*this));
50}
51
52SOTemplate const&
54{
55 // We can't have this be a magic static at namespace scope because
56 // it relies on the SField's below being initialized, and we can't
57 // guarantee the initialization order.
58 // clang-format off
59 static SOTemplate const format{
60 {sfFlags, soeREQUIRED},
61 {sfLedgerHash, soeREQUIRED},
62 {sfLedgerSequence, soeREQUIRED},
63 {sfCloseTime, soeOPTIONAL},
64 {sfLoadFee, soeOPTIONAL},
65 {sfAmendments, soeOPTIONAL},
66 {sfBaseFee, soeOPTIONAL},
67 {sfReserveBase, soeOPTIONAL},
68 {sfReserveIncrement, soeOPTIONAL},
69 {sfSigningTime, soeREQUIRED},
70 {sfSigningPubKey, soeREQUIRED},
71 {sfSignature, soeREQUIRED},
72 {sfConsensusHash, soeOPTIONAL},
73 // featureHardenedValidations
74 {sfCookie, soeDEFAULT},
75 {sfValidatedHash, soeOPTIONAL},
76 {sfServerVersion, soeOPTIONAL},
77 // featureXRPFees
78 {sfBaseFeeDrops, soeOPTIONAL},
79 {sfReserveBaseDrops, soeOPTIONAL},
80 {sfReserveIncrementDrops, soeOPTIONAL},
81 };
82 // clang-format on
83
84 return format;
85};
86
89{
91}
92
95{
96 return getFieldH256(sfLedgerHash);
97}
98
101{
102 return getFieldH256(sfConsensusHash);
103}
104
107{
109}
110
113{
114 return seenTime_;
115}
116
117bool
118STValidation::isValid() const noexcept
119{
120 if (!valid_)
121 {
122 XRPL_ASSERT(
124 "ripple::STValidation::isValid : valid key type");
125
129 makeSlice(getFieldVL(sfSignature)),
131 }
132
133 return valid_.value();
134}
135
136bool
137STValidation::isFull() const noexcept
138{
139 return (getFlags() & vfFullValidation) != 0;
140}
141
142Blob
144{
145 return getFieldVL(sfSignature);
146}
147
148Blob
150{
151 Serializer s;
152 add(s);
153 return s.peekData();
154}
155
156} // namespace ripple
Defines the fields and their attributes within a STObject.
Definition: SOTemplate.h:114
A type which can be exported to a well known binary format.
Definition: STBase.h:126
static STBase * emplace(std::size_t n, void *buf, T &&val)
Definition: STBase.h:224
Blob getFieldVL(SField const &field) const
Definition: STObject.cpp:657
std::uint32_t getFieldU32(SField const &field) const
Definition: STObject.cpp:615
void add(Serializer &s) const override
Definition: STObject.cpp:141
uint256 getSigningHash(HashPrefix prefix) const
Definition: STObject.cpp:404
std::uint32_t getFlags() const
Definition: STObject.cpp:537
uint256 getFieldH256(SField const &field) const
Definition: STObject.cpp:645
PublicKey const & getSignerPublic() const noexcept
Definition: STValidation.h:256
uint256 getConsensusHash() const
std::optional< bool > valid_
Definition: STValidation.h:52
Blob getSerialized() const
NetClock::time_point getSeenTime() const noexcept
static SOTemplate const & validationFormat()
bool isFull() const noexcept
NetClock::time_point seenTime_
Definition: STValidation.h:61
STBase * copy(std::size_t n, void *buf) const override
uint256 getLedgerHash() const
bool isValid() const noexcept
uint256 getSigningHash() const
Blob getSignature() const
STBase * move(std::size_t n, void *buf) override
NetClock::time_point getSignTime() const
Blob const & peekData() const
Definition: Serializer.h:203
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
bool verifyDigest(PublicKey const &publicKey, uint256 const &digest, Slice const &sig, bool mustBeFullyCanonical=true) noexcept
Verify a secp256k1 signature on the digest of a message.
Definition: PublicKey.cpp:237
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
Definition: PublicKey.cpp:222
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:244
constexpr std::uint32_t vfFullyCanonicalSig
Definition: STValidation.h:44
constexpr std::uint32_t vfFullValidation
Definition: STValidation.h:41
@ validation
validation for signing
@ soeOPTIONAL
Definition: SOTemplate.h:37
@ soeREQUIRED
Definition: SOTemplate.h:36
@ soeDEFAULT
Definition: SOTemplate.h:38
T value(T... args)