Skip to content

Commit

Permalink
Update sv2 header w alphabetical Error enum
Browse files Browse the repository at this point in the history
  • Loading branch information
rrybarczyk committed Oct 9, 2024
1 parent 0ed2ad1 commit c938009
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions protocols/v2/sv2-ffi/sv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,24 +430,32 @@ void free_submit_solution(CSubmitSolution s);
#include <ostream>
#include <new>

/// C-compatible enumeration of possible errors in the `codec_sv2` module.
///
/// This enum mirrors the [`Error`] enum but is designed to be used in C code through FFI. It
/// represents the same set of errors as [`Error`], making them accessible to C programs.
struct CError {
enum class Tag {
/// Errors from the `binary_sv2` crate
/// AEAD (`snow`) error in the Noise protocol.
AeadError,
/// Binary Sv2 data format error.
BinarySv2Error,
/// Errors from the `framing_sv2` crate
/// Framing Sv2 error.
FramingError,
/// Framing Sv2 error.
FramingSv2Error,
/// Errors if there are missing bytes in the Noise protocol
/// Invalid step for initiator in the Noise protocol.
InvalidStepForInitiator,
/// Invalid step for responder in the Noise protocol.
InvalidStepForResponder,
/// Missing bytes in the Noise protocol.
MissingBytes,
/// Errors from the `noise_sv2` crate
/// Sv2 Noise protocol error.
NoiseSv2Error,
/// `snow` errors
AeadError,
/// Error if Noise protocol state is not as expected
UnexpectedNoiseState,
InvalidStepForResponder,
InvalidStepForInitiator,
/// Noise protocol is not in the expected handshake state.
NotInHandShakeState,
FramingError,
/// Unexpected state in the Noise protocol.
UnexpectedNoiseState,
};

struct MissingBytes_Body {
Expand All @@ -462,7 +470,11 @@ struct CError {

extern "C" {

/// Here only to force cbindgen to create header for CError
/// Force `cbindgen` to create a header for [`CError`].
///
/// It ensures that [`CError`] is included in the generated C header file. This function is not meant
/// to be called and will panic if called. Its only purpose is to make [`CError`] visible to
/// `cbindgen`.
CError export_cerror();

} // extern "C"
Expand Down

0 comments on commit c938009

Please sign in to comment.