purify
C++ Purify implementation with native circuit and BPP support
Loading...
Searching...
No Matches
error_bridge.hpp
Go to the documentation of this file.
1// Copyright (c) 2026 Judica, Inc.
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or https://opensource.org/license/mit/.
4
5#pragma once
6
7#include <cassert>
8
9#include "purify.h"
10#include "purify/error.hpp"
11
13
14#define PURIFY_FOR_EACH_ERROR_CODE(X) \
15 X(InvalidHex, PURIFY_ERROR_INVALID_HEX) \
16 X(InvalidHexLength, PURIFY_ERROR_INVALID_HEX_LENGTH) \
17 X(InvalidFixedSize, PURIFY_ERROR_INVALID_FIXED_SIZE) \
18 X(Overflow, PURIFY_ERROR_OVERFLOW) \
19 X(Underflow, PURIFY_ERROR_UNDERFLOW) \
20 X(NarrowingOverflow, PURIFY_ERROR_NARROWING_OVERFLOW) \
21 X(DivisionByZero, PURIFY_ERROR_DIVISION_BY_ZERO) \
22 X(BitIndexOutOfRange, PURIFY_ERROR_BIT_INDEX_OUT_OF_RANGE) \
23 X(RangeViolation, PURIFY_ERROR_RANGE_VIOLATION) \
24 X(EmptyInput, PURIFY_ERROR_EMPTY_INPUT) \
25 X(SizeMismatch, PURIFY_ERROR_SIZE_MISMATCH) \
26 X(MissingValue, PURIFY_ERROR_MISSING_VALUE) \
27 X(InvalidSymbol, PURIFY_ERROR_INVALID_SYMBOL) \
28 X(UnsupportedSymbol, PURIFY_ERROR_UNSUPPORTED_SYMBOL) \
29 X(UninitializedState, PURIFY_ERROR_UNINITIALIZED_STATE) \
30 X(IndexOutOfRange, PURIFY_ERROR_INDEX_OUT_OF_RANGE) \
31 X(InvalidDimensions, PURIFY_ERROR_INVALID_DIMENSIONS) \
32 X(NonBooleanValue, PURIFY_ERROR_NON_BOOLEAN_VALUE) \
33 X(EquationMismatch, PURIFY_ERROR_EQUATION_MISMATCH) \
34 X(BindingMismatch, PURIFY_ERROR_BINDING_MISMATCH) \
35 X(IoOpenFailed, PURIFY_ERROR_IO_OPEN_FAILED) \
36 X(IoWriteFailed, PURIFY_ERROR_IO_WRITE_FAILED) \
37 X(EntropyUnavailable, PURIFY_ERROR_ENTROPY_UNAVAILABLE) \
38 X(BackendRejectedInput, PURIFY_ERROR_BACKEND_REJECTED_INPUT) \
39 X(HashToCurveExhausted, PURIFY_ERROR_HASH_TO_CURVE_EXHAUSTED) \
40 X(UnexpectedSize, PURIFY_ERROR_UNEXPECTED_SIZE) \
41 X(GeneratorOrderCheckFailed, PURIFY_ERROR_GENERATOR_ORDER_CHECK_FAILED) \
42 X(InternalMismatch, PURIFY_ERROR_INTERNAL_MISMATCH) \
43 X(TranscriptCheckFailed, PURIFY_ERROR_TRANSCRIPT_CHECK_FAILED)
44
46 switch (code) {
47#define PURIFY_FROM_CORE_CASE(cpp_code, c_code) \
48 case c_code: \
49 return ErrorCode::cpp_code;
51#undef PURIFY_FROM_CORE_CASE
52 case PURIFY_ERROR_OK:
53 break;
54 }
55
56 assert(false && "from_core_error_code() requires a non-success core status");
58}
59
61 switch (code) {
62#define PURIFY_TO_CORE_CASE(cpp_code, c_code) \
63 case ErrorCode::cpp_code: \
64 return c_code;
66#undef PURIFY_TO_CORE_CASE
67 }
68
69 assert(false && "to_core_error_code() requires a mapped ErrorCode");
71}
72
73#undef PURIFY_FOR_EACH_ERROR_CODE
74
75} // namespace purify::core_api_detail
Library-level error taxonomy used to classify Purify failures.
#define PURIFY_TO_CORE_CASE(cpp_code, c_code)
#define PURIFY_FOR_EACH_ERROR_CODE(X)
#define PURIFY_FROM_CORE_CASE(cpp_code, c_code)
constexpr ErrorCode from_core_error_code(purify_error_code code) noexcept
constexpr purify_error_code to_core_error_code(ErrorCode code) noexcept
ErrorCode
Machine-readable error codes shared across the library.
Definition error.hpp:42
Public C core for Purify key validation, key derivation, key generation, and evaluation.
purify_error_code
Machine-readable status code returned by the Purify C core.
Definition purify.h:28
@ PURIFY_ERROR_OK
Definition purify.h:29
@ PURIFY_ERROR_INTERNAL_MISMATCH
Definition purify.h:57