//------------------------------------------------------------------------------ /* This file is part of rippled: https://github.com/ripple/rippled Copyright (c) 2025 Ripple Labs Inc. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ //============================================================================== #include #include #include namespace ripple { Permission::Permission() { delegatableTx_ = { #pragma push_macro("TRANSACTION") #undef TRANSACTION #define TRANSACTION(tag, value, name, delegatable, fields) {value, delegatable}, #include #undef TRANSACTION #pragma pop_macro("TRANSACTION") }; granularPermissionMap_ = { #pragma push_macro("PERMISSION") #undef PERMISSION #define PERMISSION(type, txType, value) {#type, type}, #include #undef PERMISSION #pragma pop_macro("PERMISSION") }; granularNameMap_ = { #pragma push_macro("PERMISSION") #undef PERMISSION #define PERMISSION(type, txType, value) {type, #type}, #include #undef PERMISSION #pragma pop_macro("PERMISSION") }; granularTxTypeMap_ = { #pragma push_macro("PERMISSION") #undef PERMISSION #define PERMISSION(type, txType, value) {type, txType}, #include #undef PERMISSION #pragma pop_macro("PERMISSION") }; for ([[maybe_unused]] auto const& permission : granularPermissionMap_) XRPL_ASSERT( permission.second > UINT16_MAX, "ripple::Permission::granularPermissionMap_ : granular permission " "value must not exceed the maximum uint16_t value."); } Permission const& Permission::getInstance() { static Permission const instance; return instance; } std::optional Permission::getGranularValue(std::string const& name) const { auto const it = granularPermissionMap_.find(name); if (it != granularPermissionMap_.end()) return static_cast(it->second); return std::nullopt; } std::optional Permission::getGranularName(GranularPermissionType const& value) const { auto const it = granularNameMap_.find(value); if (it != granularNameMap_.end()) return it->second; return std::nullopt; } std::optional Permission::getGranularTxType(GranularPermissionType const& gpType) const { auto const it = granularTxTypeMap_.find(gpType); if (it != granularTxTypeMap_.end()) return it->second; return std::nullopt; } bool Permission::isDelegatable(std::uint32_t const& permissionValue) const { auto const granularPermission = getGranularName(static_cast(permissionValue)); if (granularPermission) // granular permissions are always allowed to be delegated return true; auto const it = delegatableTx_.find(permissionValue - 1); if (it != delegatableTx_.end() && it->second == Delegation::notDelegatable) return false; return true; } uint32_t Permission::txToPermissionType(TxType const& type) const { return static_cast(type) + 1; } TxType Permission::permissionToTxType(uint32_t const& value) const { return static_cast(value - 1); } } // namespace ripple