purify
C++ Purify implementation with native circuit and BPP support
Loading...
Searching...
No Matches
error.hpp File Reference

Library-level error taxonomy used to classify Purify failures.

#include <compare>
#include <cstdint>
#include <string_view>
#include <utility>
#include "purify/expected.hpp"

Go to the source code of this file.

Data Structures

struct  purify::Error
 Compact error object returned by checked APIs. More...

Namespaces

namespace  purify

Macros

#define PURIFY_DETAIL_CONCAT_IMPL(x, y)
#define PURIFY_DETAIL_CONCAT(x, y)
#define PURIFY_RETURN_IF_ERROR(expr, context)
 Evaluates an expected-like expression and returns the wrapped error on failure.
#define PURIFY_ASSIGN_OR_RETURN(lhs, expr, context)
 Evaluates an expected-like expression, binds the value to lhs, and propagates errors.
#define PURIFY_DETAIL_RETURN_IF_ERROR_IMPL(status_name, expr, context)
#define PURIFY_DETAIL_ASSIGN_OR_RETURN_IMPL(result_name, lhs, expr, context)

Typedefs

template<typename T>
using purify::Result = Expected<T, Error>
 Expected-returning convenience alias for Purify value-producing APIs.
using purify::Status = Expected<void, Error>
 Expected-returning convenience alias for Purify status-only APIs.

Enumerations

enum class  purify::ErrorCategory : std::uint8_t { purify::Natural , purify::Usage , purify::Internal }
 High-level classification for all recoverable Purify errors. More...
enum class  purify::ErrorCode : std::uint16_t {
  purify::InvalidHex , purify::InvalidHexLength , purify::InvalidFixedSize , purify::Overflow ,
  purify::Underflow , purify::NarrowingOverflow , purify::DivisionByZero , purify::BitIndexOutOfRange ,
  purify::RangeViolation , purify::EmptyInput , purify::SizeMismatch , purify::MissingValue ,
  purify::InvalidSymbol , purify::UnsupportedSymbol , purify::UninitializedState , purify::IndexOutOfRange ,
  purify::InvalidDimensions , purify::NonBooleanValue , purify::EquationMismatch , purify::BindingMismatch ,
  purify::IoOpenFailed , purify::IoWriteFailed , purify::EntropyUnavailable , purify::BackendRejectedInput ,
  purify::HashToCurveExhausted , purify::UnexpectedSize , purify::GeneratorOrderCheckFailed , purify::InternalMismatch ,
  purify::TranscriptCheckFailed
}
 Machine-readable error codes shared across the library. More...

Functions

constexpr ErrorCategory purify::error_category (ErrorCode code) noexcept
 Returns the high-level category for a concrete error code.
constexpr std::string_view purify::to_string (ErrorCategory category) noexcept
 Returns a stable programmatic name for an error category.
constexpr std::string_view purify::to_string (ErrorCode code) noexcept
 Returns a stable programmatic name for an error code.
constexpr std::string_view purify::error_message (ErrorCode code) noexcept
 Returns the human-facing description for an error code.
constexpr Unexpected< Error > purify::unexpected_error (ErrorCode code, const char *context=nullptr)
 Constructs an unexpected Error value from a machine-readable code.
constexpr Unexpected< Error > purify::unexpected_error (Error error, const char *context=nullptr)
 Re-wraps an existing Error value for propagation through another Result.

Macro Definition Documentation

◆ PURIFY_ASSIGN_OR_RETURN

#define PURIFY_ASSIGN_OR_RETURN ( lhs,
expr,
context )
Value:
PURIFY_DETAIL_ASSIGN_OR_RETURN_IMPL(PURIFY_DETAIL_CONCAT(_purify_result_, __COUNTER__), lhs, expr, context)
#define PURIFY_DETAIL_ASSIGN_OR_RETURN_IMPL(result_name, lhs, expr, context)
Definition error.hpp:346
#define PURIFY_DETAIL_CONCAT(x, y)
Definition error.hpp:321

Example: PURIFY_ASSIGN_OR_RETURN(auto secret, SecretKey::from_hex(hex), "caller:from_hex"); context is forwarded to unexpected_error().

Definition at line 338 of file error.hpp.

Referenced by purify::accountable::aggregate_responses(), purify::puresign_plusplus::MessageProofCache::build(), purify::puresign_plusplus::TopicProofCache::build(), purify::puresign::api_impl::build_message_proof_cache(), purify::puresign::api_impl::build_topic_proof_cache(), purify::bppp::commit_experimental_circuit_witness(), purify::bppp::commit_norm_arg_with_cache(), purify::bppp::commit_output_witness(), purify::derive_key(), purify::puresign::api_impl::derive_public_key(), purify::puresign_plusplus::api_impl::derive_public_key(), purify::capi_detail::derive_public_key_from_secret(), purify::accountable::ScalarSignature::deserialize(), purify::puresign::NonceProof::deserialize(), purify::puresign::ProvenSignature::deserialize(), purify::puresign_plusplus::NonceProof::deserialize(), purify::puresign_plusplus::ProvenSignature::deserialize(), purify::evaluate_verifier_circuit(), purify::evaluate_verifier_circuit(), purify::SecretKey::from_hex(), purify::puresign::KeyPair::from_secret(), purify::puresign::KeyPair::from_secret(), purify::puresign_plusplus::KeyPair::from_secret(), purify::puresign_plusplus::KeyPair::from_secret(), purify::generate_key(), purify::generate_key(), purify::NativeBulletproofCircuitTemplate::integrity_digest(), purify::puresign::api_impl::prepare_message_nonce(), purify::puresign_plusplus::api_impl::prepare_message_nonce(), purify::puresign::api_impl::prepare_message_nonce_with_proof(), purify::puresign::api_impl::prepare_message_nonce_with_proof(), purify::puresign_plusplus::api_impl::prepare_message_nonce_with_proof(), purify::puresign_plusplus::api_impl::prepare_message_nonce_with_proof(), purify::puresign::api_impl::prepare_topic_nonce(), purify::puresign_plusplus::api_impl::prepare_topic_nonce(), purify::puresign::api_impl::prepare_topic_nonce_with_proof(), purify::puresign::api_impl::prepare_topic_nonce_with_proof(), purify::puresign_plusplus::api_impl::prepare_topic_nonce_with_proof(), purify::puresign_plusplus::api_impl::prepare_topic_nonce_with_proof(), purify::prove_assignment(), purify::prove_assignment_data(), purify::bppp::prove_experimental_circuit_norm_arg(), purify::bppp::prove_experimental_circuit_norm_arg_to_commitment(), purify::bppp::prove_experimental_circuit_zk_norm_arg_impl(), purify::bppp::prove_norm_arg_to_commitment_with_cache(), purify::accountable::reconstruct_nonce(), purify::accountable::recover_same_slot_key(), purify::puresign::NonceProof::serialize(), purify::puresign::ProvenSignature::serialize(), purify::puresign_plusplus::NonceProof::serialize(), purify::puresign_plusplus::ProvenSignature::serialize(), purify::puresign::api_impl::sign_message(), purify::puresign::KeyPair::sign_message(), purify::puresign::PreparedNonceWithProof::sign_message(), purify::puresign_plusplus::api_impl::sign_message(), purify::puresign_plusplus::KeyPair::sign_message(), purify::puresign_plusplus::PreparedNonceWithProof::sign_message(), purify::puresign::api_impl::sign_message_with_prepared(), purify::puresign::KeyPair::sign_message_with_prepared(), purify::puresign_plusplus::api_impl::sign_message_with_prepared(), purify::puresign_plusplus::KeyPair::sign_message_with_prepared(), purify::puresign::api_impl::sign_message_with_proof(), purify::puresign::api_impl::sign_message_with_proof(), purify::puresign::KeyPair::sign_message_with_proof(), purify::puresign::KeyPair::sign_message_with_proof(), purify::puresign_plusplus::api_impl::sign_message_with_proof(), purify::puresign_plusplus::api_impl::sign_message_with_proof(), purify::puresign_plusplus::KeyPair::sign_message_with_proof(), purify::puresign_plusplus::KeyPair::sign_message_with_proof(), purify::puresign::PreparedNonceWithProof::sign_topic_message(), purify::puresign_plusplus::PreparedNonceWithProof::sign_topic_message(), purify::puresign::api_impl::sign_with_prepared_topic(), purify::puresign::KeyPair::sign_with_prepared_topic(), purify::puresign_plusplus::api_impl::sign_with_prepared_topic(), purify::puresign_plusplus::KeyPair::sign_with_prepared_topic(), purify::puresign::api_impl::sign_with_topic(), purify::puresign::KeyPair::sign_with_topic(), purify::puresign_plusplus::api_impl::sign_with_topic(), purify::puresign_plusplus::KeyPair::sign_with_topic(), purify::puresign::api_impl::sign_with_topic_proof(), purify::puresign::api_impl::sign_with_topic_proof(), purify::puresign::KeyPair::sign_with_topic_proof(), purify::puresign::KeyPair::sign_with_topic_proof(), purify::puresign_plusplus::api_impl::sign_with_topic_proof(), purify::puresign_plusplus::api_impl::sign_with_topic_proof(), purify::puresign_plusplus::KeyPair::sign_with_topic_proof(), purify::puresign_plusplus::KeyPair::sign_with_topic_proof(), purify::detail::validate_message_proof_cache(), purify::detail::validate_topic_proof_cache(), purify::verifier(), purify::verifier_circuit(), purify::verifier_circuit_template(), purify::verify_experimental_circuit(), purify::verify_experimental_circuit(), purify::bppp::verify_experimental_circuit_norm_arg(), purify::bppp::verify_experimental_circuit_zk_norm_arg_impl(), purify::puresign::api_impl::verify_message_nonce_proof(), purify::puresign::api_impl::verify_message_nonce_proof(), purify::puresign_plusplus::api_impl::verify_message_nonce_proof(), purify::puresign_plusplus::api_impl::verify_message_nonce_proof(), purify::puresign::api_impl::verify_message_signature_with_proof(), purify::puresign::api_impl::verify_message_signature_with_proof(), purify::puresign_plusplus::api_impl::verify_message_signature_with_proof(), purify::puresign_plusplus::api_impl::verify_message_signature_with_proof(), purify::accountable::verify_partial_response(), purify::puresign::api_impl::verify_topic_nonce_proof(), purify::puresign::api_impl::verify_topic_nonce_proof(), purify::puresign_plusplus::api_impl::verify_topic_nonce_proof(), purify::puresign_plusplus::api_impl::verify_topic_nonce_proof(), purify::puresign::api_impl::verify_topic_signature_with_proof(), purify::puresign::api_impl::verify_topic_signature_with_proof(), purify::puresign_plusplus::api_impl::verify_topic_signature_with_proof(), and purify::puresign_plusplus::api_impl::verify_topic_signature_with_proof().

◆ PURIFY_DETAIL_ASSIGN_OR_RETURN_IMPL

#define PURIFY_DETAIL_ASSIGN_OR_RETURN_IMPL ( result_name,
lhs,
expr,
context )
Value:
auto result_name = (expr); \
if (!result_name.has_value()) \
return ::purify::unexpected_error(result_name.error(), context); \
lhs = std::move(*result_name)

Definition at line 346 of file error.hpp.

◆ PURIFY_DETAIL_CONCAT

#define PURIFY_DETAIL_CONCAT ( x,
y )
Value:
#define PURIFY_DETAIL_CONCAT_IMPL(x, y)
Definition error.hpp:320

Definition at line 321 of file error.hpp.

◆ PURIFY_DETAIL_CONCAT_IMPL

#define PURIFY_DETAIL_CONCAT_IMPL ( x,
y )
Value:
x##y

Definition at line 320 of file error.hpp.

◆ PURIFY_DETAIL_RETURN_IF_ERROR_IMPL

#define PURIFY_DETAIL_RETURN_IF_ERROR_IMPL ( status_name,
expr,
context )
Value:
auto status_name = (expr); \
if (!status_name.has_value()) \
return ::purify::unexpected_error(status_name.error(), context)

Definition at line 341 of file error.hpp.

◆ PURIFY_RETURN_IF_ERROR

#define PURIFY_RETURN_IF_ERROR ( expr,
context )
Value:
PURIFY_DETAIL_RETURN_IF_ERROR_IMPL(PURIFY_DETAIL_CONCAT(_purify_status_, __COUNTER__), expr, context)
#define PURIFY_DETAIL_RETURN_IF_ERROR_IMPL(status_name, expr, context)
Definition error.hpp:341

This is intended for Status-style propagation and may also be used with Result<T> when the value is intentionally discarded. context is forwarded to unexpected_error().

Definition at line 329 of file error.hpp.

Referenced by purify::accountable::SigningRoster::aggregate(), purify::accountable::aggregate_responses(), purify::bppp::commit_norm_arg_with_cache(), purify::bppp::create_generators(), purify::puresign::Nonce::deserialize(), purify::puresign::PublicKey::deserialize(), purify::puresign::Signature::deserialize(), purify::puresign_plusplus::Nonce::deserialize(), purify::puresign_plusplus::NonceProof::deserialize(), purify::puresign_plusplus::PublicKey::deserialize(), purify::puresign_plusplus::Signature::deserialize(), purify::SecretKey::from_packed(), purify::NativeBulletproofCircuitTemplate::integrity_digest(), purify::accountable::nonce_evaluation_input(), purify::bppp::pedersen_commit_char(), purify::puresign::api_impl::prepare_message_nonce_with_proof(), purify::puresign_plusplus::api_impl::prepare_message_nonce_with_proof(), purify::puresign::api_impl::prepare_topic_nonce_with_proof(), purify::puresign_plusplus::api_impl::prepare_topic_nonce_with_proof(), purify::prove_assignment_data(), purify::bppp::prove_experimental_circuit_zk_norm_arg_impl(), purify::bppp::prove_norm_arg_to_commitment_with_cache(), purify::random_below(), purify::puresign::PreparedNonce::sign_message(), purify::puresign_plusplus::PreparedNonce::sign_message(), purify::puresign::PreparedNonce::sign_topic_message(), purify::puresign_plusplus::PreparedNonce::sign_topic_message(), purify::accountable::signature_challenge(), purify::verifier(), purify::verifier_circuit_template(), purify::verify_experimental_circuit(), purify::verify_experimental_circuit(), purify::puresign::api_impl::verify_message_nonce_proof(), purify::puresign_plusplus::api_impl::verify_message_nonce_proof(), purify::puresign::api_impl::verify_signature(), purify::puresign_plusplus::api_impl::verify_signature(), purify::puresign::api_impl::verify_topic_nonce_proof(), and purify::puresign_plusplus::api_impl::verify_topic_nonce_proof().