rippled
tokens.h
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 #ifndef RIPPLE_PROTOCOL_TOKENS_H_INCLUDED
21 #define RIPPLE_PROTOCOL_TOKENS_H_INCLUDED
22 
23 #include <ripple/basics/Expected.h>
24 #include <ripple/basics/contract.h>
25 #include <ripple/protocol/impl/token_errors.h>
26 
27 #include <cstdint>
28 #include <optional>
29 #include <span>
30 #include <string>
31 #include <string_view>
32 
33 namespace ripple {
34 
35 template <class T>
37 
38 enum class TokenType : std::uint8_t {
39  None = 1, // unused
40  NodePublic = 28,
41  NodePrivate = 32,
42  AccountID = 0,
43  AccountPublic = 35,
44  AccountSecret = 34,
45  FamilyGenerator = 41, // unused
46  FamilySeed = 33
47 };
48 
49 template <class T>
50 [[nodiscard]] std::optional<T>
51 parseBase58(std::string const& s);
52 
53 template <class T>
54 [[nodiscard]] std::optional<T>
55 parseBase58(TokenType type, std::string const& s);
56 
68 [[nodiscard]] std::string
69 encodeBase58Token(TokenType type, void const* token, std::size_t size);
70 
71 [[nodiscard]] std::string
73 
74 namespace b58_ref {
75 // The reference version does not use gcc extensions (int128 in particular)
76 [[nodiscard]] std::string
77 encodeBase58Token(TokenType type, void const* token, std::size_t size);
78 
79 [[nodiscard]] std::string
81 
82 namespace detail {
83 // Expose detail functions for unit tests only
86  void const* message,
87  std::size_t size,
88  void* temp,
89  std::size_t temp_size);
90 
92 decodeBase58(std::string const& s);
93 } // namespace detail
94 } // namespace b58_ref
95 
96 #ifndef _MSC_VER
97 namespace b58_fast {
98 // Use the fast version (10-15x faster) is using gcc extensions (int128 in
99 // particular)
100 [[nodiscard]] B58Result<std::span<std::uint8_t>>
102  TokenType token_type,
105 
106 [[nodiscard]] B58Result<std::span<std::uint8_t>>
108  TokenType type,
110  std::span<std::uint8_t> outBuf);
111 
112 // This interface matches the old interface, but requires additional allocation
113 [[nodiscard]] std::string
114 encodeBase58Token(TokenType type, void const* token, std::size_t size);
115 
116 // This interface matches the old interface, but requires additional allocation
117 [[nodiscard]] std::string
118 decodeBase58Token(std::string const& s, TokenType type);
119 
120 namespace detail {
121 // Expose detail functions for unit tests only
122 B58Result<std::span<std::uint8_t>>
123 b256_to_b58_be(
126 
127 B58Result<std::span<std::uint8_t>>
128 b58_to_b256_be(std::string_view input, std::span<std::uint8_t> out);
129 } // namespace detail
130 
131 } // namespace b58_fast
132 #endif // _MSC_VER
133 } // namespace ripple
134 
135 #endif
span
std::string
STL class.
std::string_view
STL class.
ripple::TokenType::FamilyGenerator
@ FamilyGenerator
ripple::decodeBase58Token
std::string decodeBase58Token(std::string const &s, TokenType type)
Definition: tokens.cpp:205
ripple::b58_ref::decodeBase58Token
std::string decodeBase58Token(std::string const &s, TokenType type)
Definition: tokens.cpp:343
ripple::b58_ref::encodeBase58Token
std::string encodeBase58Token(TokenType type, void const *token, std::size_t size)
Definition: tokens.cpp:319
ripple::TokenType::None
@ None
ripple::base_uint
Integers of any length that is a multiple of 32-bits.
Definition: base_uint.h:82
ripple::Expected
Definition: Expected.h:132
ripple::TokenType::FamilySeed
@ FamilySeed
ripple::TokenType
TokenType
Definition: tokens.h:38
cstdint
std::uint8_t
ripple::b58_ref::detail::decodeBase58
std::string decodeBase58(std::string const &s)
Definition: tokens.cpp:270
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::b58_ref::detail::encodeBase58
std::string encodeBase58(void const *message, std::size_t size, void *temp, std::size_t temp_size)
Definition: tokens.cpp:219
ripple::encodeBase58Token
std::string encodeBase58Token(TokenType type, void const *token, std::size_t size)
Encode data in Base58Check format using XRPL alphabet.
Definition: tokens.cpp:195
ripple::TokenType::AccountSecret
@ AccountSecret
ripple::TokenType::AccountPublic
@ AccountPublic
ripple::TokenType::NodePublic
@ NodePublic
optional
std::size_t
ripple::parseBase58
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
Definition: AccountID.cpp:114
string_view
ripple::TokenType::NodePrivate
@ NodePrivate
string