Skip to main content

confium_daemon/methods/
mod.rs

1//! JSON-RPC method handlers.
2//!
3//! Each submodule covers one interface group (plugin, hash, cipher, …).
4//! Handlers are plain async functions that take the daemon-owned
5//! [`Confium`] and the parsed params, returning a JSON result value or
6//! an [`RpcError`].
7//!
8//! Methods that mirror C-FFI calls that are not yet wired in
9//! `confium-core` use the [`pending_method!`] macro below. As the core
10//! lands each interface, the matching handler becomes a thin adapter —
11//! no dispatch change is needed.
12
13pub mod aead;
14pub mod attributes;
15pub mod audit;
16pub mod cipher;
17pub mod composite;
18pub mod hash;
19pub mod kdf;
20pub mod kem;
21pub mod keyfmt;
22pub mod keystore;
23pub mod meta;
24pub mod plugin;
25pub mod registry;
26pub mod rng;
27pub mod signature;
28pub mod tc;
29
30/// Generate an async stub handler that returns an `Engine` error with
31/// the given `(method_name, reason)` pair.
32///
33/// Why a macro: 29 daemon handlers across 7 modules all returned
34/// the same boilerplate ("X requires Y (pending)"). The macro keeps
35/// the message format consistent and the call site one line. Each
36/// pending handler is its own `pub async fn` so the dispatch table
37/// (which takes function pointers) sees them as first-class items.
38///
39/// When a handler moves from pending to real, delete the macro
40/// invocation and write the real `pub async fn` in its place.
41#[macro_export]
42macro_rules! pending_method {
43    ($name:ident, $method:literal, $reason:literal) => {
44        pub async fn $name(
45            _cfm: $crate::server::SharedConfium,
46            _params: serde_json::Value,
47        ) -> std::result::Result<serde_json::Value, $crate::error::RpcError> {
48            Err($crate::error::RpcError::Engine {
49                message: format!("{} {}", $method, $reason),
50            })
51        }
52    };
53}